1 | ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*-
|
---|
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 | (load "ngrobner.asd")
|
---|
41 | (asdf:load-system :ngrobner)
|
---|
42 |
|
---|
43 | (defpackage #:ngrobner-tests
|
---|
44 | (:use :cl :it.bese.fiveam
|
---|
45 | :ngrobner :priority-queue :monomial
|
---|
46 | :utils :order :ring :term
|
---|
47 | )
|
---|
48 | )
|
---|
49 |
|
---|
50 | (in-package #:ngrobner-tests)
|
---|
51 |
|
---|
52 | (def-suite ngrobner-suite
|
---|
53 | :description "New Groebner Package Suite")
|
---|
54 |
|
---|
55 | (in-suite ngrobner-suite)
|
---|
56 |
|
---|
57 | #+nil
|
---|
58 | (test dummy-test
|
---|
59 | "Makelist"
|
---|
60 | (is (= (+ 2 2)) "2 plus 2 wasn't equal to 4 (using #'= to test equality)")
|
---|
61 | (is (= 0 (+ -1 1)))
|
---|
62 | (signals
|
---|
63 | (error "Trying to add 4 to FOO didn't signal an error")
|
---|
64 | (+ 'foo 4))
|
---|
65 | (is (= 0 (+ 1 1)) "this should have failed"))
|
---|
66 |
|
---|
67 | (test makelist-1
|
---|
68 | "makelist-1 test"
|
---|
69 | (is (equal (makelist-1 (* 2 i) i 0 10) '(0 2 4 6 8 10 12 14 16 18 20)))
|
---|
70 | (is (equal (makelist-1 (* 2 i) i 0 10 3) '(0 6 12 18))))
|
---|
71 |
|
---|
72 | (test makelist
|
---|
73 | "makelist"
|
---|
74 | (is (equal (makelist (+ (* i i) (* j j)) (i 1 4) (j 1 i)) '(2 5 8 10 13 18 17 20 25 32)))
|
---|
75 | (is (equal (makelist (list i j '---> (+ (* i i) (* j j))) (i 1 4) (j 1 i))
|
---|
76 | '((1 1 ---> 2) (2 1 ---> 5) (2 2 ---> 8) (3 1 ---> 10) (3 2 ---> 13)
|
---|
77 | (3 3 ---> 18) (4 1 ---> 17) (4 2 ---> 20) (4 3 ---> 25) (4 4 ---> 32)))))
|
---|
78 |
|
---|
79 | (test monom
|
---|
80 | "monom"
|
---|
81 | (is (equalp (make-monom 3) #(0 0 0)) "Trivial monomial is a vector of 0's")
|
---|
82 | (is (equalp (make-monom 3 :initial-contents '(1 2 3)) #(1 2 3)) "Monomial with powers 1,2,3"))
|
---|
83 |
|
---|
84 | (test order
|
---|
85 | "order"
|
---|
86 | (let ((p (make-monom 3 :initial-contents '(1 3 2)))
|
---|
87 | (q (make-monom 3 :initial-contents '(1 2 3))))
|
---|
88 | (is-true (lex> p q))
|
---|
89 | (is-true (grlex> p q))
|
---|
90 | (is-true (revlex> p q))
|
---|
91 | (is-true (grevlex> p q))
|
---|
92 | (is-false (invlex> p q)))
|
---|
93 | (let ((p (make-monom 3 :initial-contents '(1 2 3)))
|
---|
94 | (q (make-monom 3 :initial-contents '(4 5 6))))
|
---|
95 | (is-false (elimination-order-1 p q))
|
---|
96 | (is-false (funcall (elimination-order 2) p q))))
|
---|
97 |
|
---|
98 | (test term
|
---|
99 | "term"
|
---|
100 | (let* ((m1 (make-monom 3 :initial-contents '(1 2 3)))
|
---|
101 | (m2 (make-monom 3 :initial-contents '(3 5 2)))
|
---|
102 | (m3 (monom-mul m1 m2))
|
---|
103 | (t1 (make-term m1 7))
|
---|
104 | (t2 (make-term m2 9))
|
---|
105 | (t3 (make-term m3 (* 7 9))))
|
---|
106 | (is (equalp (term-mul *ring-of-integers* t1 t2) t3))))
|
---|
107 |
|
---|
108 | (test coerce-to-infix
|
---|
109 | "Conversion to infix form"
|
---|
110 | (is (equal
|
---|
111 | (coerce-to-infix :term (make-term-variable *ring-of-integers* 5 3) '(x y z w u v))
|
---|
112 | '(* 1 (EXPT X 0) (EXPT Y 0) (EXPT Z 0) (EXPT W 1) (EXPT U 0)))))
|
---|
113 |
|
---|
114 | (test priority-queue
|
---|
115 | "Priority queue"
|
---|
116 | (let ((q (priority-queue:make-priority-queue)))
|
---|
117 | (priority-queue::priority-queue-insert q 7)
|
---|
118 | (priority-queue::priority-queue-insert q 8)
|
---|
119 | (is (= (priority-queue::priority-queue-size q) 3) "Note that there is always a dummy element in the queue.")
|
---|
120 | (is (equalp (priority-queue::priority-queue-heap q) #(0 7 8)))
|
---|
121 | (is (= (priority-queue::priority-queue-remove q) 7))
|
---|
122 | (is (= (priority-queue::priority-queue-remove q) 8))
|
---|
123 | (is-true (priority-queue::priority-queue-empty-p q))))
|
---|
124 |
|
---|
125 |
|
---|
126 | (run! 'ngrobner-suite)
|
---|
127 | (format t "All tests done!~%")
|
---|
128 |
|
---|
129 |
|
---|