1. Steve Losh
  2. khan

Source

khan / test / khan / test / linear.clj

(ns khan.test.linear
  (:use [khan.linear])
  (:use [clojure.test]))

(deftest test-row-count
         (is (= (row-count [[1 2]
                            [3 4]]) 2)
             "Incorrect number of rows.")
         (is (= (row-count [[1 2]
                            [3 4]
                            [5 6]]) 3)
             "Incorrect number of rows."))

(deftest test-col-count
         (is (= (col-count [[1 2]
                            [3 4]]) 2)
             "Incorrect number of columns.")
         (is (= (col-count [[1 2]
                            [3 4]
                            [5 6]]) 2)
             "Incorrect number of columns."))

(deftest test-rows
         (is (= [[1 2 3] [0 0 0]]
                (rows [[1 2 3]
                       [0 0 0]]))
             "Incorrect rows.")
         (is (= [[0 0 0]]
                (rows [[0 0 0]]))
             "Incorrect rows."))

(deftest test-cols
         (is (= [[1 0] [2 0] [3 0]]
                (cols [[1 2 3]
                       [0 0 0]]))
             "Incorrect columns.")
         (is (= [[0] [0] [0]]
                (cols [[0 0 0]]))
             "Incorrect columns."))

(deftest test-matrix+
         (is (= (matrix+ [[1 2]
                          [3 4]]
                         [[5 6]
                          [7 8]])
                [[6 8]
                 [10 12]])
             "Invalid addition."))

(deftest test-matrix-
         (is (= (matrix- [[1 2]
                          [3 4]]
                         [[5 6]
                          [7 8]])
                [[-4 -4]
                 [-4 -4]])
             "Invalid subtraction."))

(deftest test-dot-product
         (is (= (dot-product [1 2 3] [10 100 1000])
                (+ (* 1 10)
                   (* 2 100)
                   (* 3 1000)))
             "Invalid dot product."))