Commits

John Chandler committed e188997

Make refining of rows and columns the same thing, and push the column problem elsewhere

Comments (0)

Files changed (2)

src/pseudohkoo/core.clj

   ; returns the set of numbers that are still missing from the row
   (clojure.set/difference (required-values row) (current-values row)))
 
+(defn refine-line [line]
+  ; returns a line with non-definite values refined, where possible
+  (map (fn [cell]
+	 (if (nil? cell)
+	   (format-value (missing-values line))
+	   (if (vector? cell)
+	     (format-value (clojure.set/intersection (missing-values line) (set cell)))
+	     cell)))
+       line))
+
 (defn refine-row [row]
   ; return a row with non-definite values refined, where possible
-  (map (fn [cell]
-	 (if (nil? cell)
-	   (format-value (missing-values row))
-	   (if (vector? cell)
-	     (format-value (clojure.set/intersection (missing-values row) (set cell)))
-	     cell)))
-       row))
+  (refine-line row))
+
+(defn refine-column [column]
+  ; return a column with non-definite values refined, where possible
+  (refine-line column))
 
 (defn refine-grid [grid]
   ; return a "refined" grid - replacing nil cells with definite or possible values as appropriate 

test/pseudohkoo/test/core.clj

 
 
 ;; refine-column
-;(deftest test-refine-column-nearly-done
+(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)))
-;
-;  )
+  (is (= [1 2 3, 4 5 6, 7 8 9]         (refine-column [1 2 3, 4 5 6, 7 8 nil])))
+  (is (= [1 2 [3 9], 4 5 6, 7 8 [3 9]] (refine-column [1 2 nil, 4 5 6, 7 8 nil])))
+  (is (= [1 2 3, 4 5 6, 7 8 9]         (refine-column [1 2 3, 4 5 6, 7 8 [3 9]]))))
 
 
 ;; refine-grid
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.