| 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 :ngrobner)) | 
|---|
| 45 |  | 
|---|
| 46 | (in-package #:ngrobner-tests) | 
|---|
| 47 |  | 
|---|
| 48 | (def-suite ngrobner-suite | 
|---|
| 49 | :description "New Groebner Package Suite") | 
|---|
| 50 |  | 
|---|
| 51 | (in-suite ngrobner-suite) | 
|---|
| 52 |  | 
|---|
| 53 | #+nil | 
|---|
| 54 | (test dummy-test | 
|---|
| 55 | "Makelist" | 
|---|
| 56 | (is (= (+ 2 2)) "2 plus 2 wasn't equal to 4 (using #'= to test equality)") | 
|---|
| 57 | (is (= 0 (+ -1 1))) | 
|---|
| 58 | (signals | 
|---|
| 59 | (error "Trying to add 4 to FOO didn't signal an error") | 
|---|
| 60 | (+ 'foo 4)) | 
|---|
| 61 | (is (= 0 (+ 1 1)) "this should have failed")) | 
|---|
| 62 |  | 
|---|
| 63 | (test makelist-1 | 
|---|
| 64 | "makelist-1 test" | 
|---|
| 65 | (is (equal (ngrobner:makelist-1 (* 2 i) i 0 10) '(0 2 4 6 8 10 12 14 16 18 20))) | 
|---|
| 66 | (is (equal (ngrobner:makelist-1 (* 2 i) i 0 10 3) '(0 6 12 18)))) | 
|---|
| 67 |  | 
|---|
| 68 | (test makelist | 
|---|
| 69 | "makelist" | 
|---|
| 70 | (is (equal (ngrobner:makelist (+ (* i i) (* j j)) (i 1 4) (j 1 i)) '(2 5 8 10 13 18 17 20 25 32))) | 
|---|
| 71 | (is (equal (ngrobner:makelist (list i j '---> (+ (* i i) (* j j))) (i 1 4) (j 1 i)) | 
|---|
| 72 | '((1 1 ---> 2) (2 1 ---> 5) (2 2 ---> 8) (3 1 ---> 10) (3 2 ---> 13) | 
|---|
| 73 | (3 3 ---> 18) (4 1 ---> 17) (4 2 ---> 20) (4 3 ---> 25) (4 4 ---> 32))))) | 
|---|
| 74 |  | 
|---|
| 75 | (test monom | 
|---|
| 76 | "monom" | 
|---|
| 77 | (is (equalp (ngrobner::make-monom 3) #(0 0 0)) "Trivial monomial is a vector of 0's") | 
|---|
| 78 | (is (equalp (ngrobner::make-monom 3 :initial-contents '(1 2 3)) #(1 2 3)) "Monomial with powers 1,2,3")) | 
|---|
| 79 |  | 
|---|
| 80 | (test order | 
|---|
| 81 | "order" | 
|---|
| 82 | (let ((p (make-monom 3 :initial-contents '(1 3 2))) | 
|---|
| 83 | (q (make-monom 3 :initial-contents '(1 2 3)))) | 
|---|
| 84 | (is-true (ngrobner:lex>  p q)) | 
|---|
| 85 | (is-true (ngrobner:grlex>  p q)) | 
|---|
| 86 | (is-true (ngrobner:revlex>  p q)) | 
|---|
| 87 | (is-true (ngrobner:grevlex>  p q)) | 
|---|
| 88 | (is-false (ngrobner:invlex>  p q)))) | 
|---|
| 89 |  | 
|---|
| 90 | (test order-mk | 
|---|
| 91 | "order factories" | 
|---|
| 92 | (let ((p (make-monom 3 :initial-contents '(1 2 3))) | 
|---|
| 93 | (q (make-monom 3 :initial-contents '(4 5 6)))) | 
|---|
| 94 | (is-false (ngrobner:elimination-order-1 p q)) | 
|---|
| 95 | (is-false (funcall (ngrobner:elimination-order 2) p q)))) | 
|---|
| 96 |  | 
|---|
| 97 | (test term | 
|---|
| 98 | "term" | 
|---|
| 99 | (let* ((m1 (ngrobner:make-monom 3 :initial-contents '(1 2 3))) | 
|---|
| 100 | (m2 (ngrobner:make-monom 3 :initial-contents '(3 5 2))) | 
|---|
| 101 | (m3 (ngrobner::monom-mul m1 m2)) | 
|---|
| 102 | (t1 (ngrobner:make-term m1 7)) | 
|---|
| 103 | (t2 (ngrobner:make-term m2 9)) | 
|---|
| 104 | (t3 (ngrobner:make-term m3 (* 7 9)))) | 
|---|
| 105 | (is (equalp (ngrobner::term-mul ngrobner::*ring-of-integers* t1 t2) t3)))) | 
|---|
| 106 |  | 
|---|
| 107 | (test coerce-to-infix | 
|---|
| 108 | "conversion" | 
|---|
| 109 | ) | 
|---|
| 110 |  | 
|---|
| 111 | (run! 'ngrobner-suite) | 
|---|
| 112 | (format t "All tests done!~%") | 
|---|
| 113 |  | 
|---|
| 114 |  | 
|---|