[4175] | 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 | (defpackage #:5am-criterion
|
---|
| 41 | (:use :cl :it.bese.fiveam :monom :polynomial :infix
|
---|
| 42 | :symbolic-polynomial :pair-queue :criterion))
|
---|
| 43 |
|
---|
| 44 | (in-package :5am-criterion)
|
---|
| 45 |
|
---|
| 46 | (def-suite criterion-suite
|
---|
| 47 | :description "Buchberger criterion suite")
|
---|
| 48 |
|
---|
| 49 | (in-suite criterion-suite)
|
---|
| 50 |
|
---|
| 51 | (def-fixture criterion-1-context ()
|
---|
| 52 | (let ((true-pair (make-instance 'critical-pair
|
---|
| 53 | :first (string->poly "x^2+2*y" '(x y z))
|
---|
| 54 | :second (string->poly "y*z + z^2" '(x y z))))
|
---|
| 55 | (false-pair (make-instance 'critical-pair
|
---|
| 56 | :first (string->poly "x^2*y+z" '(x y z))
|
---|
| 57 | :second (string->poly "y*z + z^2" '(x y z)))))
|
---|
| 58 | (&body)))
|
---|
| 59 |
|
---|
| 60 | (test criterion-1
|
---|
| 61 | "First Buchberger criterion"
|
---|
| 62 | (with-fixture criterion-1-context ()
|
---|
| 63 | (is-true (criterion-1 true-pair))
|
---|
| 64 | (is-false (criterion-1 false-pair))))
|
---|
| 65 |
|
---|
[4176] | 66 | (def-fixture criterion-2-failure-context ()
|
---|
| 67 | (let* ((p1 (string->poly "x^2+2*y" '(x y z)))
|
---|
| 68 | (p2 (string->poly "y*z + z^2" '(x y z)))
|
---|
| 69 | (pair (make-instance 'critical-pair
|
---|
| 70 | :first p1
|
---|
| 71 | :second p2))
|
---|
[4177] | 72 | (b-done (make-hash-table)) ;TODO: make meaningful B-DONE table
|
---|
[4176] | 73 | (partial-basis nil))
|
---|
| 74 | (&body)))
|
---|
| 75 |
|
---|
| 76 | (test criterion-2-failure
|
---|
| 77 | "Second Buchberger criterion failure"
|
---|
| 78 | (with-fixture criterion-2-failure-context ()
|
---|
| 79 | (is-false (criterion-2 pair b-done partial-basis))))
|
---|
| 80 |
|
---|
[4177] | 81 | (def-fixture criterion-2-success-context ()
|
---|
| 82 | (let* ((f (string->poly "x^2+2*y" '(x y z)))
|
---|
| 83 | (g (string->poly "y*z + z^2" '(x y z)))
|
---|
| 84 | (h (string->poly "x^2*y*z" '(x y z)))
|
---|
| 85 | (pair (make-instance 'critical-pair :first f :second g))
|
---|
[4179] | 86 | (b-done (make-hash-table :test #'equal))
|
---|
[4312] | 87 | (partial-basis (list f g h)))
|
---|
[4178] | 88 | ;; Initialize the lookup table of done pairs
|
---|
[4312] | 89 | (setf ;;(gethash (list h f) b-done) t
|
---|
| 90 | (gethash (list f h) b-done) t
|
---|
| 91 | ;;(gethash (list h g) b-done) t
|
---|
| 92 | (gethash (list g h) b-done) t
|
---|
| 93 | )
|
---|
[4177] | 94 | (&body)))
|
---|
[4176] | 95 |
|
---|
[4177] | 96 | (test criterion-2-success
|
---|
| 97 | "Second Buchberger criterion success"
|
---|
| 98 | (with-fixture criterion-2-success-context ()
|
---|
| 99 | (is-true (criterion-2 pair b-done partial-basis))))
|
---|
| 100 |
|
---|
| 101 |
|
---|
[4175] | 102 | (run! 'criterion-suite)
|
---|
| 103 | (format t "All tests done!~%")
|
---|
| 104 |
|
---|
| 105 |
|
---|