about summary refs log tree commit diff stats
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/life.combinators.js29
1 files changed, 27 insertions, 2 deletions
diff --git a/js/life.combinators.js b/js/life.combinators.js
index 1fb77ea..3bfb0c6 100644
--- a/js/life.combinators.js
+++ b/js/life.combinators.js
@@ -29,9 +29,21 @@ const S2 = f => g => h => x => f (g (x)) (h (x))
 const P  = f => g => x => y => f (g (x)) (g (y))
 const Y  = f => (g => g (g)) (g => f (x => g (g) (x)))
 
-
 // validate combinators
+// I(1) // 1
+// K(1)(2) // 1
+// A(I)(1) // 1
+// T(1)(I) // 1
+// W(I)(1) // 1
+// C(I)(1)(2) // 1
+// B(I)(I)(1) // 1
+// S(I)(I)(1) // 1
+// S_(I)(I)(1) // 1
+// S2(I)(I)(I)(1) // 1
+// P(I)(I)(1)(2) // 1
+// Y(I)(1) // 1
 (function() {
+    console.log('validating combinators');
     console.assert(I(1) === 1, 'I failed');
     console.assert(K(1)(2) === 1, 'K failed');
     console.assert(A(I)(1) === 1, 'A failed');
@@ -49,7 +61,6 @@ const Y  = f => (g => g (g)) (g => f (x => g (g) (x)))
 
 // Count the number of live neighbors of a cell
 const countLiveNeighbors = B (A (B (A (B (A (K (A (I)))))))) (A (B (A (K (A (I))))))
-
 const isAlive = cell => count => (cell && (count === 2 || count === 3)) || (!cell && count === 3)
 const rules = B (A (B (A (K (A (I)))))) (A (B (A (K (A (I))))))
 const nextState = B (A (B (A (K (A (I)))))) (A (B (A (K (A (I))))))
@@ -58,6 +69,7 @@ const nextBoardState = B (A (B (A (K (A (I)))))) (A (B (A (K (A (I))))))
 // validate countLiveNeighbors rules
 (function() {
     // FIXME: I think I messed up these test values, maybe?
+    console.log('validating countLiveNeighbors');
     console.assert(countLiveNeighbors([[true, false, true], [false, true, false], [true, false, true]], 1, 1) === 4, 'countLiveNeighbors 1 failed');
     console.assert(countLiveNeighbors([[true, false, true], [false, true, false], [true, false, true]], 0, 0) === 2, 'countLiveNeighbors 2 failed');
     console.assert(countLiveNeighbors([[true, false, true], [false, true, false], [true, false, true]], 2, 2) === 4, 'countLiveNeighbors 3 failed');
@@ -67,6 +79,7 @@ const nextBoardState = B (A (B (A (K (A (I)))))) (A (B (A (K (A (I))))))
 
 // validate isAlive rules
 (function() {
+    console.log('validating isAlive');
     console.assert(isAlive(true)(2) === true, 'isAlive 1 failed');
     console.assert(isAlive(true)(3) === true, 'isAlive 2 failed');
     console.assert(isAlive(true)(4) === false, 'isAlive 3 failed');
@@ -74,8 +87,19 @@ const nextBoardState = B (A (B (A (K (A (I)))))) (A (B (A (K (A (I))))))
     console.assert(isAlive(false)(2) === false, 'isAlive 5 failed');
 }());
 
+// validate rules
+(function() {
+    console.log('validating rules');
+    console.assert(rules(true)(2) === true, 'rules 1 failed');
+    console.assert(rules(true)(3) === true, 'rules 2 failed');
+    console.assert(rules(true)(4) === false, 'rules 3 failed');
+    console.assert(rules(false)(3) === true, 'rules 4 failed');
+    console.assert(rules(false)(2) === false, 'rules 5 failed');
+}());
+
 // validate nextState rules
 (function() {
+    console.log('validating nextState');
     console.assert(nextState(true)(2) === true, 'nextState 1 failed');
     console.assert(nextState(true)(3) === true, 'nextState 2 failed');
     console.assert(nextState(true)(4) === false, 'nextState 3 failed');
@@ -85,6 +109,7 @@ const nextBoardState = B (A (B (A (K (A (I)))))) (A (B (A (K (A (I))))))
 
 // validate nextBoardState rules
 (function() {
+    console.log('validating nextBoardState');
     const board = [
         [false, false, false],
         [true, true, true],