Source

pseudohkoo / test / pseudohkoo / test / core.clj

Full commit
(ns pseudohkoo.test.core
  (:use [pseudohkoo.core] :reload)
  (:use [clojure.test]))


;; get-cell
(deftest test-get-cell-value
  ; cell value retrieval
  (let [grid [[0 0 0]
	      [1 0 0]
	      [0 0 0]]
       ]
    (is (= 1 (get-cell grid 1 0)))))

(deftest test-get-cell-value-out-of-bounds
  ; cell value retrieval when out-of-bounds
  (let [grid [[0 0 0]
	      [1 0 0]
	      [0 0 0]]
       ]
    (is (nil? (get-cell grid 3 0)))
    (is (nil? (get-cell grid 0 3)))))


;; get-column
(deftest test-get-column
  ; retrieve a column from the grid
  (let [grid [[1 0 0]
	      [2 0 0]
	      [3 0 0]]
       ]
    (is (= [1 2 3] (get-column grid 0)))))


;; get-row
(deftest test-get-row
  ; retrieve a row from the grid
  (let [grid [[0 0 0]
	      [0 1 0]
	      [0 0 0]]
       ]
    (is (= [0 1 0] (get-row grid 1)))))

(deftest test-get-row-out-of-bounds
  ; retrieve a non-existent row from the grid
  (let [grid [[0 0 0]
	      [0 1 0]
	      [0 0 0]]
       ]
    (is (= [] (get-row grid 3)))))


;; update-row
(deftest test-update-row
  ; set first cell in the row
  (is (= [1 0 0] (update-row [0 0 0] 0, 1)))
  ; set middle cell in the row
  (is (= [0 1 0] (update-row [0 0 0] 1, 1)))
  ; set last cell in the row
  (is (= [0 0 1] (update-row [0 0 0] 2, 1))))


;; get-box
(deftest test-get-box
  ; test getting values from a box
  (let [grid [[11 1 2,  12 7 8,  13 4 7]
	      [14 3 4,  15 9 1,  16 5 8]
	      [17 5 6,  18 2 3,  19 6 9]
              [21 1 2,  22 7 8,  23 4 7]
	      [24 3 4,  25 9 1,  26 5 8]
	      [27 5 6,  28 2 3,  29 6 9]
              [31 1 2,  32 7 8,  33 4 7]
	      [34 3 4,  35 9 1,  36 5 8]
	      [37 5 6,  38 2 3,  39 6 9]]
	]
    (is (= (set [1 2 3 4 5 6 11 14 17]) (get-box grid 0 0)))
    (is (= (set [1 2 3 7 8 9 22 25 28]) (get-box grid 4 5)))
    (is (= (set [4 5 6 7 8 9 33 36 39]) (get-box grid 8 8)))))


;; row-complete?
(deftest test-row-incomplete
  ; test if row is incomplete
  (let [row [1 nil nil]]
    (is (false? (row-complete? row)))))

(deftest test-row-complete
  ; test if row is complete
  (let [row [1 2 3]]
    (is (true? (row-complete? row)))))


;; grid-complete?
(deftest test-grid-incomplete
  ; test if grid is incomplete
  (let [grid [[  1   2   3]
	      [nil nil nil]
	      [  2 nil nil]]
       ]
    (is (false? (grid-complete? grid)))))

(deftest test-grid-complete
  ; test if grid is complete
  (let [grid [[1 2 3]
	      [3 1 2]
	      [2 3 1]]
       ]
    (is (true? (grid-complete? grid)))))


;; refine-row
(deftest test-refine-row-nearly-done
  ; test refining of a "nearly done" row i.e. we're missing a value or two
  (is (= [1 2 3, 4 5 6, 7 8 9]         (refine-row [1 2 3, 4 5 6, 7 8 nil])))
  (is (= [1 2 [3 9], 4 5 6, 7 8 [3 9]] (refine-row [1 2 nil, 4 5 6, 7 8 nil])))
  (is (= [1 2 3, 4 5 6, 7 8 9]         (refine-row [1 2 3, 4 5 6, 7 8 [3 9]]))))


;; refine-column
;(deftest test-refine-column-nearly-done
  ; test refining of a "nearly done" column i.e. we're missing a value or two
;  (is (=  (refine-col)))
;
;  )


;; refine-grid
(deftest test-refine-grid-nearly-done
  ; test refinement of a "nearly done" grid i.e. we're missing 9s
  (let [grid  [[  1   2   3,   4   5   6,   7   8 nil]
	       [nil   1   2,   3   4   5,   6   7   8]
	       [  8 nil   1,   2   3   4,   5   6   7]
	       [  7   8 nil,   1   2   3,   4   5   6]
	       [  6   7   8, nil   1   2,   3   4   5]
	       [  5   6   7,   8 nil   1,   2   3   4]
	       [  4   5   6,   7   8 nil,   1   2   3]
	       [  3   4   5,   6   7   8, nil   1   2]
	       [  2   3   4,   5   6   7,   8  nil  1]]
	result (refine-grid grid)
      ]
    (is (= [1 2 3, 4 5 6, 7 8 9] (nth result 0)))

    )
  )