Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn- proper? [matrix]
- "Returns true if the matrix has the same number of elements for each row."
- (apply = (map #(count %) matrix)))
- (defn get-row [matrix row]
- "Returns the nth row"
- {:pre [(proper? matrix) (< row (count matrix))]}
- (nth matrix row))
- ; ClojureMatrix.test.matrix
- (def sample-matrix [[1 2 3] [4 5 6] [7 8 9]])
- (deftest get-row-test
- (is (= [1 2 3] (get-row sample-matrix 0)))
- (is (= [7 8 9] (get-row sample-matrix 2)))
- (is (thrown? AssertionError (get-row sample-matrix 5))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement