pseudohkoo / test / pseudohkoo / test / core.clj

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


;; 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-columns
(deftest test-get-columns
  ; retrieve all columns from the grid (this is like rotating the grid by 90 degrees)
  (let [grid     [[1 4 7]
	          [2 5 8]
	          [3 6 9]]
	expected [[1 2 3]
		  [4 5 6]
		  [7 8 9]]
       ]
    (is (= expected (get-columns grid)))))


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


;; remap-columns-to-grid
(deftest test-remap-columns-to-grid
  ; test remapping of columns back to a grid
  (is (= [[1 2] [3 4]] (remap-columns-to-grid [[1 3] [2 4]] [[9 9] [9 9]]) )))

;; 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)))))

(deftest test-refine-grid-columns
  ; test refinement of a "nearly done" grid needing help from both row and column refinement
  (let [grid  [[  1   2   3,   4   5   6,   7 nil 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   9  1]]
	result (refine-grid grid)
      ]
    (is (= [1 2 3, 4 5 6, 7 8 9] (nth result 0)))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.