12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 'use strict';
- function test_DB_getNeighbours() {
- var db = new Blockly.ConnectionDB();
-
- assertEquals(helper_getNeighbours(db, 10 , 10 , 100 ).length, 0);
-
- for (var i = 0; i < 10; i++) {
- db.addConnection_(helper_createConnection(0, i, Blockly.PREVIOUS_STATEMENT));
- }
-
- var result = helper_getNeighbours(db, 0, 0, 4);
- assertEquals(5, result.length);
- for (i = 0; i < result.length; i++) {
- assertNotEquals(result.indexOf(db[i]), -1);
- }
-
- result = helper_getNeighbours(db, 0, 4, 2);
- assertEquals(5, result.length);
- for (i = 0; i < result.length; i++) {
- assertNotEquals(result.indexOf(db[i + 2]), -1);
- }
-
- result = helper_getNeighbours(db, 0, 9, 4);
- assertEquals(5, result.length);
- for (i = 0; i < result.length; i++) {
- assertNotEquals(result.indexOf(db[i + 5]), -1);
- }
-
- result = helper_getNeighbours(db, 10, 9, 4);
- assertEquals(result.length, 0);
-
- result = helper_getNeighbours(db, 0, 19, 4);
- assertEquals(result.length, 0);
-
- result = helper_getNeighbours(db, -2, -2, 2);
- assertEquals(result.length, 0);
- }
- function helper_getNeighbours(db, x, y, radius) {
- return db.getNeighbours(helper_createConnection(x, y, Blockly.NEXT_STATEMENT), radius);
- }
- function helper_createConnection(x, y, type) {
- var conn = new Blockly.Connection({workspace: {}}, type);
- conn.x_ = x;
- conn.y_ = y;
- return conn;
- }
|