Преглед на файлове

Fully comment poly.cl and add new tests.cl with some testing

Matt Coles преди 10 години
родител
ревизия
2c7b699d1b
променени са 2 файла, в които са добавени 28 реда и са изтрити 3 реда
  1. 4 3
      poly.cl
  2. 24 0
      tests.cl

+ 4 - 3
poly.cl

@@ -89,9 +89,11 @@
89 89
                        (term-addition (car poly) y))
90 90
              (cdr poly)) (car poly))))))))
91 91
 
92
+;; Map a single polynomial onto each term of another polynomial
92 93
 (defun map-onto-poly (single-poly poly)
93 94
   (map 'list #'(lambda (x) (multiply-singles single-poly x)) poly))
94 95
 
96
+;; Multiply two singular polynomials together
95 97
 (defun multiply-singles (single-poly1 single-poly2)
96 98
   (cond
97 99
     ((equal (variable-symbol single-poly1) (variable-symbol single-poly2))
@@ -109,11 +111,10 @@
109 111
                         (exponent single-poly2)))
110 112
             (* (multiplier single-poly1) (multiplier single-poly2))))))
111 113
 
114
+;; Multiply two polynomials together, see the map-poly will be recursed
115
+;; and the poly will remain constant
112 116
 (defun multiply-terms (map-poly poly)
113 117
   (cond
114 118
     ((equal map-poly nil) nil)
115 119
     (T (remove nil (append (map-onto-poly (car map-poly) poly) 
116 120
                (multiply-terms (cdr map-poly) poly))))))
117
-
118
-; (poly+ '(((x 2) 3)) '(((y 2) 4)))
119
-; (poly+ '(((x 2) 3) ((y 2) 3)) '(((y 2) 4)))

+ 24 - 0
tests.cl

@@ -0,0 +1,24 @@
1
+(require "poly.cl")
2
+
3
+(defun run-tests ()
4
+  (if (equal 
5
+        (poly+ '(((x 2) 5)) '(((x 2) 3)))
6
+        '(((x 2) 8)))
7
+    (format t "5x^2 + 3x^2 ... passed - simple addition~%")
8
+    (format t "5x^2 + 3x^2 ... failed - simple addition~%"))
9
+  (if (equal
10
+        (poly+ '(((x 2) 5) ((y 2) 6)) '(((x 2) 3) ((y 2) 3) ((z 3) 4)))
11
+        '(((z 3) 4) ((x 2) 8) ((y 2) 9)))
12
+    (format t "5x^2+6y^2 + 3x^2+3y^2+4z^3 ... passed - complex addition~%")
13
+    (format t "5x^2+6y^2 + 3x^2+3y^2+4z^3 ... failed - complex addition~%"))
14
+  (if (equal 
15
+        (poly- '(((x 2) 5)) '(((x 2) 3)))
16
+        '(((x 2) 2)))
17
+    (format t "5x^2 - 3x^2 ... passed - simple subtraction~%")
18
+    (format t "5x^2 - 3x^2 ... failed - simple subtraction~%"))
19
+  (if (equal
20
+        (poly- '(((x 2) 5) ((y 2) 6)) '(((x 2) 3) ((y 2) 3) ((z 3) 4)))
21
+        '(((z 3) -4) ((x 2) 2) ((y 2) 3)))
22
+    (format t "5x^2+6y^2 - 3x^2+3y^2+4z^3 ... passed - complex subtraction~%")
23
+    (format t "5x^2+6y^2 - 3x^2+3y^2+4z^3 ... failed - complex subtraction~%"))
24
+  )