close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

source: branches/f4grobner/5am-criterion.lisp@ 4197

Last change on this file since 4197 was 4179, checked in by Marek Rychlik, 8 years ago

* empty log message *

File size: 4.0 KB
Line 
1;;; -*- Mode: Lisp -*-
2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3;;;
4;;; Copyright (C) 1999, 2002, 2009, 2015 Marek Rychlik <rychlik@u.arizona.edu>
5;;;
6;;; This program is free software; you can redistribute it and/or modify
7;;; it under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 2 of the License, or
9;;; (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19;;;
20;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21
22;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23;;
24;; Run tests using 5am unit testing framework
25;;
26;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27
28;; We assume that QuickLisp package manager is installed.
29;; See :
30;; https://www.quicklisp.org/beta/
31;;
32
33;; The following is unnecessary after running:
34;; * (ql:add-to-init-file)
35;; at lisp prompt:
36;;(load "~/quicklisp/setup")
37
38(ql:quickload :fiveam)
39
40;; Unless NGROBNER system loaded by ASDF,
41;; load the dependencies directly
42#-ngrobner
43(progn
44 (require :utils "copy")
45 (require :utils "utils")
46 (require :monom "monom")
47 (require :polynomial "polynomial")
48 (require :infix "infix")
49 (require :infix "infix-printer")
50 (require :symbolic-polynomial "symbolic-polynomial")
51 (require :heap "heap")
52 (require :priority-queue "priority-queue")
53 (require :pair-queue "pair-queue")
54 (require :grobner-debug "grobner-debug")
55 (require :criterion "criterion")
56)
57
58(defpackage #:5am-criterion
59 (:use :cl :it.bese.fiveam :monom :polynomial :infix
60 :symbolic-polynomial :pair-queue :criterion))
61
62(in-package :5am-criterion)
63
64(def-suite criterion-suite
65 :description "Buchberger criterion suite")
66
67(in-suite criterion-suite)
68
69(def-fixture criterion-1-context ()
70 (let ((true-pair (make-instance 'critical-pair
71 :first (string->poly "x^2+2*y" '(x y z))
72 :second (string->poly "y*z + z^2" '(x y z))))
73 (false-pair (make-instance 'critical-pair
74 :first (string->poly "x^2*y+z" '(x y z))
75 :second (string->poly "y*z + z^2" '(x y z)))))
76 (&body)))
77
78(test criterion-1
79 "First Buchberger criterion"
80 (with-fixture criterion-1-context ()
81 (is-true (criterion-1 true-pair))
82 (is-false (criterion-1 false-pair))))
83
84(def-fixture criterion-2-failure-context ()
85 (let* ((p1 (string->poly "x^2+2*y" '(x y z)))
86 (p2 (string->poly "y*z + z^2" '(x y z)))
87 (pair (make-instance 'critical-pair
88 :first p1
89 :second p2))
90 (b-done (make-hash-table)) ;TODO: make meaningful B-DONE table
91 (partial-basis nil))
92 (&body)))
93
94(test criterion-2-failure
95 "Second Buchberger criterion failure"
96 (with-fixture criterion-2-failure-context ()
97 (is-false (criterion-2 pair b-done partial-basis))))
98
99(def-fixture criterion-2-success-context ()
100 (let* ((f (string->poly "x^2+2*y" '(x y z)))
101 (g (string->poly "y*z + z^2" '(x y z)))
102 (h (string->poly "x^2*y*z" '(x y z)))
103 (pair (make-instance 'critical-pair :first f :second g))
104 (b-done (make-hash-table :test #'equal))
105 (partial-basis (list h)))
106 ;; Initialize the lookup table of done pairs
107 (setf (gethash (list h f) b-done) t
108 (gethash (list h g) b-done) t)
109 (&body)))
110
111(test criterion-2-success
112 "Second Buchberger criterion success"
113 (with-fixture criterion-2-success-context ()
114 (is-true (criterion-2 pair b-done partial-basis))))
115
116
117(run! 'criterion-suite)
118(format t "All tests done!~%")
119
120
Note: See TracBrowser for help on using the repository browser.