Advertisement
Guest User

Untitled

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