Skip to content

Commit

Permalink
Added tests for all the matrix operators.
Browse files Browse the repository at this point in the history
  • Loading branch information
hamilton committed Jul 13, 2010
1 parent 931142e commit 9adceb9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/infer/matrix_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@
[0 0 3]]
(to-diag [1 2 3]))))

(deftest matrix-multiplication
(let [A (matrix [[1 1] [1 1]])
B (matrix [[2 2] [2 2]])
C (matrix [[2 0] [0 2]])]
(is (= (matrix [[4 4] [4 4]]) (times A B)))
(is (= (matrix [[8 8] [8 8]]) (times A B C)))))

;; (deftest matrix-divide
;; (let [A (matrix [[1 1] [1 1]])
;; B (matrix [[2 2] [2 2]])
;; C (matrix [[2 0] [0 2]])]
;; (is (= (matrix [[0.5 0.5] [0.5 0.5]]) (divide A B)))
;; (is (= (matrix [[8 8] [8 8]]) (divide A B C)))))

(deftest matrix-addition
(let [A (matrix [[1 1] [1 1]])
B (matrix [[2 2] [2 2]])
C (matrix [[2 0] [0 2]])]
(is (= (matrix [[3 3] [3 3]]) (plus A B)))
(is (= (matrix [[5 3] [3 5]]) (plus A B C)))))

(deftest matrix-subtraction
(let [A (matrix [[1 1] [1 1]])
B (matrix [[2 2] [2 2]])
C (matrix [[2 0] [0 2]])]
(is (= (matrix [[1 1] [1 1]]) (minus B A)))
(is (= (matrix [[-1 1] [1 -1]]) (minus B A C)))))

(deftest concat-columns
(is (= (from-matrix
(matrix [[1 2 3]
Expand Down

0 comments on commit 9adceb9

Please sign in to comment.