Commits

Shlomi Fish committed 9c09214 Merge

Merged.

Comments (0)

Files changed (2)

abc-path/js/abc-path-test.html

 
   <script type="text/javascript">
       $(document).ready(function () { 
-          test_abc_path();
+          try {
+              test_abc_path();
+          }
+          catch (err) {
+            module("Meta");
+            test("global_failure", function() {
+                ok (false, 'test_abc_path() has thrown an exception or is invalid.');
+            });
+          }
           // Hide passed tests by default.
           $('#qunit-tests').addClass('hidepass');
       });

abc-path/js/abc-path-test.js

         expect(3);
 
         var myboard = new ABC_Path.Solver.Board({});
-        // TEST
         var layout_string = myboard._perl_range(1,25).map(
             function (x) { return String.fromCharCode(x); }
         ).join('');
     module("ABC_Path.Generator.Generator");
 
     test("_get_next_cells", function() {
+        expect(2);
         var pos_array = _shlomif_repeat(['\0'], 5*5);
         
         pos_array[0*5+0] = String.fromCharCode(1);
         var pos_s = pos_array.join('');
 
         var gen = new ABC_Path.Generator.Generator({seed : 1});
+        // TEST
         deepEqual (gen._get_next_cells(pos_s, 1*5+1),
             [0*5+1, 0*5+2, 1*5+0, 1*5+2, 2*5+0, 2*5+1, 2*5+2],
             'get_next_cells for (1,1)'
         );
 
+        // TEST
         deepEqual (gen._get_next_cells(pos_s, 0*5+1),
             [0*5+2, 1*5+0, 1*5+2],
             'get_next_cells for (0,1) - an edge cell.'
     });
 
     test("_get_num_connected", function() {
+        expect(1);
         var pos_array = _shlomif_repeat(['\0'], 5*5);
         
         pos_array[0*5+0] = String.fromCharCode(1);
         var pos_s = pos_array.join('');
 
         var gen = new ABC_Path.Generator.Generator({seed : 1});
+        // TEST
         equal(gen._get_num_connected(pos_s), 2);
     });
+
+    test("calc_final_layout seed 1.", function() {
+        expect(1);
+
+        var gen = new ABC_Path.Generator.Generator({seed : 1});
+        var final_layout = gen.calc_final_layout();
+        var expected_string =
+            'YXRST' +
+            'EDWQU' +
+            'FBCVP' +
+            'GAKLO' +
+            'HIJNM';
+
+        var got_matrix = final_layout._y_indexes().map(function (y) { 
+            return final_layout._x_indexes().map(function(x) {
+                return final_layout.get_letter_at_pos({y : y, x: x})
+            }
+            )
+            });
+
+        var got_string = [].concat.apply([], got_matrix).join('');
+
+        // TEST
+        equal(got_string, expected_string, 'Layout with seed 1 is right.');
+    });
 }