changeset 2:3b1bf1d2f3d9 default tip

Enable tests.
author Oleksandr Gavenko <gavenkoa@gmail.com>
date Fri, 11 Mar 2016 20:57:38 +0200
parents b8942066e4a0
children
files test.js
diffstat 1 files changed, 61 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/test.js	Fri Mar 11 20:57:26 2016 +0200
+++ b/test.js	Fri Mar 11 20:57:38 2016 +0200
@@ -1,92 +1,86 @@
 
-// var world = new World();
-// world.add(0, 1, "red");
-// world.add(1, 2, "blue");
-// world.add(2, 3, "red");
+var world = new World();
+world.add(0, 1, "red");
+world.add(1, 2, "blue");
+world.add(2, 3, "red");
 
-// console.assert(Object.keys(world.graph.store).length === 4, Object.keys(world.graph.store).length);
-// console.assert(world.red.store.size === 2, world.red.store.size);
-// console.assert(world.blue.store.size === 1, world.blue.store.size);
+console.assert(Object.keys(world.graph.store).length === 4, Object.keys(world.graph.store).length);
+console.assert(world.red.store.size === 2, world.red.store.size);
+console.assert(world.blue.store.size === 1, world.blue.store.size);
 
-// world.add(3, 4, "red");
+world.add(3, 4, "red");
 
-// console.assert(Object.keys(world.graph.store).length === 5, Object.keys(world.graph.store).length);
-// console.assert(world.red.store.size === 3, world.red.store.size);
-// console.assert(world.blue.store.size === 1, world.blue.store.size);
+console.assert(Object.keys(world.graph.store).length === 5, Object.keys(world.graph.store).length);
+console.assert(world.red.store.size === 3, world.red.store.size);
+console.assert(world.blue.store.size === 1, world.blue.store.size);
 
-// world.add(0, 4, "blue");
+world.add(0, 4, "blue");
 
-// console.assert(Object.keys(world.graph.store).length === 5, Object.keys(world.graph.store).length);
-// console.assert(world.red.store.size === 3, world.red.store.size);
-// console.assert(world.blue.store.size === 2, world.blue.store.size);
-// console.assert(world.blue.filterNode(2).size === 1, world.blue.filterNode(2));
+console.assert(Object.keys(world.graph.store).length === 5, Object.keys(world.graph.store).length);
+console.assert(world.red.store.size === 3, world.red.store.size);
+console.assert(world.blue.store.size === 2, world.blue.store.size);
+console.assert(world.blue.filterNode(2).size === 1, world.blue.filterNode(2));
 
-// world.deleteXY(1, 2);
+world.deleteXY(1, 2);
 
-// console.assert(Object.keys(world.graph.store).length === 5, Object.keys(world.graph.store).length);
-// console.assert(world.red.store.size === 3, world.red.store.size);
-// console.assert(world.blue.store.size === 1, world.blue.store.size);
-// console.assert(world.blue.filterNode(2).size === 0, world.blue.filterNode(2).size);
+console.assert(Object.keys(world.graph.store).length === 5, Object.keys(world.graph.store).length);
+console.assert(world.red.store.size === 3, world.red.store.size);
+console.assert(world.blue.store.size === 1, world.blue.store.size);
+console.assert(world.blue.filterNode(2).size === 0, world.blue.filterNode(2).size);
 
-// world.deleteXY(3, 2);
+world.deleteXY(3, 2);
 
-// console.assert(Object.keys(world.graph.store).length === 5, Object.keys(world.graph.store).length);
-// console.assert(world.red.store.size === 2, world.red.store.size);
-// console.assert(world.blue.store.size === 1, world.blue.store.size);
-// console.assert(world.graph.connectedTo(2).size === 1, world.graph.connectedTo(2).size);
+console.assert(Object.keys(world.graph.store).length === 5, Object.keys(world.graph.store).length);
+console.assert(world.red.store.size === 2, world.red.store.size);
+console.assert(world.blue.store.size === 1, world.blue.store.size);
+console.assert(world.graph.connectedTo(2).size === 1, world.graph.connectedTo(2).size);
 
-// world.deleteNode(2);
+world.deleteNode(2);
 
-// console.assert(Object.keys(world.graph.store).length === 4, Object.keys(world.graph.store).length);
-// console.assert(world.red.store.size === 2, world.red.store.size);
-// console.assert(world.blue.store.size === 1, world.blue.store.size);
-// console.assert(world.graph.connectedTo(2).size === 0, world.graph.connectedTo(2).size);
+console.assert(Object.keys(world.graph.store).length === 4, Object.keys(world.graph.store).length);
+console.assert(world.red.store.size === 2, world.red.store.size);
+console.assert(world.blue.store.size === 1, world.blue.store.size);
+console.assert(world.graph.connectedTo(2).size === 0, world.graph.connectedTo(2).size);
 
-// var copy = world.clone();
+var copy = world.clone();
 
-// console.assert(Object.keys(copy.graph.store).length === 4, Object.keys(copy.graph.store).length);
-// console.assert(copy.red.store.size === 2, copy.red.store.size);
-// console.assert(copy.blue.store.size === 1, copy.blue.store.size);
-
-// var world = new World();
-// world.add(0, 1, "red");
+console.assert(Object.keys(copy.graph.store).length === 4, Object.keys(copy.graph.store).length);
+console.assert(copy.red.store.size === 2, copy.red.store.size);
+console.assert(copy.blue.store.size === 1, copy.blue.store.size);
 
-// var connected = world.graph.connectedTo(world.ground);
-// console.assert(connected.size === 2, connected);
-// var nodes = world.red.filterNode(0)
-// console.assert(nodes.size === 1, nodes);
-// var nodes = world.blue.filterNode(0)
-// console.assert(nodes.size === 0, nodes);
+var world = new World();
+world.add(0, 1, "red");
 
-// var result = play(world, "red");
-// console.assert(result[0] === "red", result);
-// console.assert(result[1][0] === 0, result);
-// console.assert(result[1][1] === 1, result);
+var connected = world.graph.connectedTo(world.ground);
+console.assert(connected.size === 2, connected);
+var nodes = world.red.filterNode(0)
+console.assert(nodes.size === 1, nodes);
+var nodes = world.blue.filterNode(0)
+console.assert(nodes.size === 0, nodes);
 
-// var result = play(world, "blue");
-// console.assert(result[0] === "red", result);
-// console.assert(result[1] === null, result);
+var result = play(world, "red");
+console.assert(result[0] === "red", result);
+console.assert(result[1][0] === 0, result);
+console.assert(result[1][1] === 1, result);
 
-// var world = new World();
-// world.add(0, 1, "blue");
-// world.add(0, 2, "red");
-// var result = play(world, "blue");
-// console.log(result);
-// console.assert(result[0] === "blue", result);
-// console.assert(result[1] === null, result);
-// var result = play(world, "blue");
-// console.assert(result[0] === "red", result);
-// console.assert(result[1] === null, result);
+var result = play(world, "blue");
+console.assert(result[0] === "red", result);
+console.assert(result[1] === null, result);
 
-// var world = new World();
-// world.add(0, 1, "blue");
-// world.add(0, 2, "red");
-// world.add(2, 3, "blue");
-// var result = play(world, "blue");
-// console.log(result);
+var world = new World();
+world.add(0, 1, "blue");
+world.add(0, 2, "red");
+var result = play(world, "blue");
+console.log(result);
+console.assert(result[0] === "blue", result);
+console.assert(result[1] === null, result);
+var result = play(world, "blue");
+console.assert(result[0] === "red", result);
+console.assert(result[1] === null, result);
 
 // TASKS from class.
 // https://www.coursera.org/learn/combinatorial-game-theory/supplement/vPHWa/extra-problems
+// https://www.coursera.org/learn/combinatorial-game-theory/discussions/vHc0-11vEeW-tBLRsFjxBw?sort=createdAtDesc
 
 var world = new World();
 world.add(0, 1, "blue");