close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

Changeset 3597 for branches/f4grobner


Ignore:
Timestamp:
2015-09-05T18:30:20-07:00 (9 years ago)
Author:
Marek Rychlik
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/f4grobner/5am-monom.lisp

    r3593 r3597  
    128128    (is-false (funcall elim-order-2 p q))))
    129129
     130;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     131;;
     132;;        TERM class tests
     133;;
     134;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     135
     136(def-fixture term-context ()
     137  (symbol-macrolet
     138      ((z (make-instance 'term  :dimension 3 :coeff 5))
     139       (m (make-instance 'term  :dimension 3 :exponents '(1 2 3) :coeff 6))
     140       (n (make-instance 'term  :dimension 3 :exponents '(4 5 6) :coeff 12))
     141       (m*n (make-instance 'term  :dimension 3 :exponents '(5 7 9) :coeff 72))
     142       (n/m (make-instance 'term  :dimension 3 :exponents '(3 3 3) :coeff 2))
     143       (m-tensor-n (make-instance 'term  :exponents '(1 2 3 4 5 6) :coeff 72))
     144       (m-uminus (make-instance 'term  :dimension 3 :exponents '(1 2 3) :coeff -6)))
     145    (&body)))
     146
     147(test term-basics
     148  "Term basics"
     149  (with-fixture term-context ()
     150    (is (= (r-dimension m) 3))
     151    (is (= (r-elt m 2) 3))
     152    (is (= (r-total-degree m) 6))
     153    (is (= (r-sugar m) 6))
     154    (is (equalp  (r->list z) '(0 0 0)) "Trivial term is a vector of 0's")
     155    (is (r-equalp (r* m n) m*n))
     156    (is (r-equalp (r/ n m) n/m))
     157    (is (r-equalp (right-tensor-product-by m n) m-tensor-n))
     158    (signals
     159        (error "EXPONENTS must have length DIMENSION")
     160      (make-instance 'term  :dimension 3 :exponents '(1 2 3 4 5 6) :coeff 77))
     161    (is-true (r-divides-p m n))
     162    (is-false (r-divides-p n m))
     163    (is (r-equalp (r-gcd m n) m))
     164    (is (r-equalp (r-lcm m n) n))
     165    (is-true (r-depends-p m 0))
     166    (signals
     167        (error "Index out of bounds")
     168      (r-depends-p m 3))
     169    )
     170  (with-fixture term-context ()
     171    (is (r-equalp (multiply-by m n) m*n)))
     172  (with-fixture term-context ()
     173    (is (r-equalp (divide-by n m) n/m)))
     174  (with-fixture term-context ()
     175    (is (r-equalp (unary-minus m) m-uminus))))
     176
     177
     178(def-fixture monom/term-conversion-context ()
     179  (symbol-macrolet
     180      ((term (make-instance 'term :exponents '(1 2 3) :coeff 4))
     181       (monom (make-instance 'monom :exponents '(1 2 3)))
     182       (promoted-monom  (make-instance 'term :exponents '(1 2 3) :coeff 1)))
     183    (&body)))
     184
     185(test monom/term-conversion
     186  "Monom/term conversion"
     187  (with-fixture monom/term-conversion-context ()
     188    (is (r-equalp (change-class term 'monom) monom)))
     189  (with-fixture monom/term-conversion-context ()
     190    (is (r-equalp (change-class monom 'term) promoted-monom))))
     191
     192(test monom/term-copy
     193  "Monom/term copy"
     194  (with-fixture monom/term-conversion-context ()
     195    (is (r-equalp (copy-instance monom) monom))
     196    (is (r-equalp (copy-instance term) term)))
     197  )
     198
     199(test term-tensor-product
     200  "Term tensor product"
     201  (let ((term1 (make-instance 'term :exponents '(1 2 3) :coeff 4))
     202        (term2 (make-instance 'term :exponents '(4 5) :coeff 3))
     203        (term1-left-tensor-by-term2 (make-instance 'term :exponents '(4 5 1 2 3) :coeff 12)))
     204    (is (r-equalp (left-tensor-product-by term1 term2) term1-left-tensor-by-term2))))
     205
     206(test term-contract
     207  "Term contract"
     208  (let ((term (make-instance 'term :exponents '(1 2 3) :coeff 4))
     209        (term-contracted (make-instance 'term :exponents '(2 3) :coeff 4)))
     210    (is (r-equalp (left-contract term 1) term-contracted))))
     211
     212
     213
     214
    130215(run! 'monom-suite)
    131216(format t "All tests done!~%")
Note: See TracChangeset for help on using the changeset viewer.