[302] | 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 |
|
---|
[309] | 22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 23 | ;;
|
---|
[355] | 24 | ;; Run tests using 5am unit testing framework
|
---|
[309] | 25 | ;;
|
---|
| 26 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 27 |
|
---|
[342] | 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 |
|
---|
[286] | 38 | (ql:quickload :fiveam)
|
---|
[301] | 39 |
|
---|
[292] | 40 | (load "ngrobner.asd")
|
---|
[291] | 41 | (asdf:load-system :ngrobner)
|
---|
[286] | 42 |
|
---|
[367] | 43 | (defpackage #:ngrobner-tests
|
---|
[604] | 44 | (:use :cl :it.bese.fiveam
|
---|
| 45 | :ngrobner :priority-queue :monomial
|
---|
| 46 | :utils :order :ring :term
|
---|
[608] | 47 | :priority-queue
|
---|
[604] | 48 | )
|
---|
| 49 | )
|
---|
[286] | 50 |
|
---|
[367] | 51 | (in-package #:ngrobner-tests)
|
---|
[287] | 52 |
|
---|
[367] | 53 | (def-suite ngrobner-suite
|
---|
[368] | 54 | :description "New Groebner Package Suite")
|
---|
[281] | 55 |
|
---|
[367] | 56 | (in-suite ngrobner-suite)
|
---|
[287] | 57 |
|
---|
[312] | 58 | #+nil
|
---|
[289] | 59 | (test dummy-test
|
---|
[281] | 60 | "Makelist"
|
---|
| 61 | (is (= (+ 2 2)) "2 plus 2 wasn't equal to 4 (using #'= to test equality)")
|
---|
| 62 | (is (= 0 (+ -1 1)))
|
---|
| 63 | (signals
|
---|
| 64 | (error "Trying to add 4 to FOO didn't signal an error")
|
---|
| 65 | (+ 'foo 4))
|
---|
| 66 | (is (= 0 (+ 1 1)) "this should have failed"))
|
---|
[289] | 67 |
|
---|
[293] | 68 | (test makelist-1
|
---|
[303] | 69 | "makelist-1 test"
|
---|
[597] | 70 | (is (equal (makelist-1 (* 2 i) i 0 10) '(0 2 4 6 8 10 12 14 16 18 20)))
|
---|
| 71 | (is (equal (makelist-1 (* 2 i) i 0 10 3) '(0 6 12 18))))
|
---|
[294] | 72 |
|
---|
[303] | 73 | (test makelist
|
---|
[314] | 74 | "makelist"
|
---|
[598] | 75 | (is (equal (makelist (+ (* i i) (* j j)) (i 1 4) (j 1 i)) '(2 5 8 10 13 18 17 20 25 32)))
|
---|
| 76 | (is (equal (makelist (list i j '---> (+ (* i i) (* j j))) (i 1 4) (j 1 i))
|
---|
[303] | 77 | '((1 1 ---> 2) (2 1 ---> 5) (2 2 ---> 8) (3 1 ---> 10) (3 2 ---> 13)
|
---|
| 78 | (3 3 ---> 18) (4 1 ---> 17) (4 2 ---> 20) (4 3 ---> 25) (4 4 ---> 32)))))
|
---|
[290] | 79 |
|
---|
[314] | 80 | (test monom
|
---|
| 81 | "monom"
|
---|
[885] | 82 | (is (every #'= (make-monom :dimension 3) '(0 0 0)) "Trivial monomial is a vector of 0's")
|
---|
| 83 | (is (every #'= (make-monom :initial-exponents '(1 2 3)) '(1 2 3)) "Monomial with powers 1,2,3")
|
---|
[867] | 84 | (let ((p (make-monom :initial-exponents '(1 2 3))))
|
---|
[885] | 85 | (is (every #'= (monom-map (lambda (x) x) p) '(1 2 3)))))
|
---|
[867] | 86 |
|
---|
[303] | 87 |
|
---|
[347] | 88 | (test order
|
---|
| 89 | "order"
|
---|
[856] | 90 | (let ((p (make-monom :initial-exponents '(1 3 2)))
|
---|
| 91 | (q (make-monom :initial-exponents '(1 2 3))))
|
---|
[600] | 92 | (is-true (lex> p q))
|
---|
| 93 | (is-true (grlex> p q))
|
---|
| 94 | (is-true (revlex> p q))
|
---|
| 95 | (is-true (grevlex> p q))
|
---|
| 96 | (is-false (invlex> p q)))
|
---|
[855] | 97 | (let ((p (make-monom :initial-exponents '(1 2 3)))
|
---|
| 98 | (q (make-monom :initial-exponents '(4 5 6))))
|
---|
[600] | 99 | (is-false (elimination-order-1 p q))
|
---|
| 100 | (is-false (funcall (elimination-order 2) p q))))
|
---|
[347] | 101 |
|
---|
[381] | 102 | (test term
|
---|
| 103 | "term"
|
---|
[855] | 104 | (let* ((m1 (make-monom :initial-exponents '(1 2 3)))
|
---|
| 105 | (m2 (make-monom :initial-exponents '(3 5 2)))
|
---|
[602] | 106 | (m3 (monom-mul m1 m2))
|
---|
| 107 | (t1 (make-term m1 7))
|
---|
| 108 | (t2 (make-term m2 9))
|
---|
| 109 | (t3 (make-term m3 (* 7 9))))
|
---|
| 110 | (is (equalp (term-mul *ring-of-integers* t1 t2) t3))))
|
---|
[381] | 111 |
|
---|
| 112 | (test coerce-to-infix
|
---|
[582] | 113 | "Conversion to infix form"
|
---|
| 114 | (is (equal
|
---|
[605] | 115 | (coerce-to-infix :term (make-term-variable *ring-of-integers* 5 3) '(x y z w u v))
|
---|
[582] | 116 | '(* 1 (EXPT X 0) (EXPT Y 0) (EXPT Z 0) (EXPT W 1) (EXPT U 0)))))
|
---|
[381] | 117 |
|
---|
[584] | 118 | (test priority-queue
|
---|
| 119 | "Priority queue"
|
---|
[607] | 120 | (let ((q (make-priority-queue)))
|
---|
| 121 | (priority-queue-insert q 7)
|
---|
| 122 | (priority-queue-insert q 8)
|
---|
| 123 | (is (= (priority-queue-size q) 3) "Note that there is always a dummy element in the queue.")
|
---|
| 124 | (is (equalp (priority-queue-heap q) #(0 7 8)))
|
---|
| 125 | (is (= (priority-queue-remove q) 7))
|
---|
| 126 | (is (= (priority-queue-remove q) 8))
|
---|
[610] | 127 | (is-true (priority-queue-empty-p q))
|
---|
[613] | 128 | (signals
|
---|
| 129 | (error "Empty queue.")
|
---|
| 130 | (priority-queue-remove q))))
|
---|
[584] | 131 |
|
---|
[634] | 132 | ;;
|
---|
| 133 | ;; Currently parser cannot be tested, as it relies on many maxima functions
|
---|
| 134 | ;; to parse a polynomial expression.
|
---|
| 135 | ;;
|
---|
[614] | 136 | #|
|
---|
| 137 | (test parser
|
---|
| 138 | "Parser"
|
---|
| 139 | (let (($f '((MLIST SIMP) ((MPLUS SIMP) $X ((MTIMES SIMP) -1 $Y)) ((MPLUS SIMP) $X $Y)))
|
---|
[620] | 140 | ($v '((MLIST SIMP) $X $Y)))
|
---|
| 141 | (is-true (parse-poly-list $f $v))))
|
---|
[633] | 142 | |#
|
---|
[614] | 143 |
|
---|
[691] | 144 | (test infix-print
|
---|
[694] | 145 | "Infix printer"
|
---|
[691] | 146 | (is (string= (infix-print '(+ x y) nil) "X+Y"))
|
---|
| 147 | (is (string= (infix-print '(expt x 3) nil) "X^3"))
|
---|
[693] | 148 | (is (string= (infix-print '(+ 1 (expt x 3)) nil) "1+(X^3)"))
|
---|
| 149 | (is (string= (infix-print '(* x y) nil) "X*Y"))
|
---|
| 150 | (is (string= (infix-print '(* x (expt y 2)) nil) "X*(Y^2)")))
|
---|
[832] | 151 |
|
---|
| 152 | (test infix
|
---|
| 153 | "Infix parser"
|
---|
[693] | 154 | (is (equal '#I( x^2 + y^2 ) '(+ (expt x 2) (expt y 2))))
|
---|
[831] | 155 | (is (equal '#I( [ x, y ] ) '(:[ X Y)))
|
---|
| 156 | (is (equal '#I( x + y) '(+ x y)))
|
---|
[864] | 157 | (is (equal '#I( x^3 ) '(expt x 3)))
|
---|
| 158 | (is (equal '#I( 1 + x^3) '(+ 1 (expt x 3))))
|
---|
| 159 | (is (equal '#I( x * y^2 ) '(* x (expt y 2)))))
|
---|
[691] | 160 |
|
---|
[693] | 161 |
|
---|
[367] | 162 | (run! 'ngrobner-suite)
|
---|
[346] | 163 | (format t "All tests done!~%")
|
---|
[345] | 164 |
|
---|
| 165 |
|
---|