more unit tests
This commit is contained in:
@@ -38,7 +38,6 @@ const DEFAULT_OPTIONS = {
|
|||||||
|
|
||||||
const self = {
|
const self = {
|
||||||
options: DEFAULT_OPTIONS,
|
options: DEFAULT_OPTIONS,
|
||||||
debug: false,
|
|
||||||
compute: (data) => {
|
compute: (data) => {
|
||||||
const options = merge(DEFAULT_OPTIONS, data['options']);
|
const options = merge(DEFAULT_OPTIONS, data['options']);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/* jshint -W117 */
|
||||||
|
const faDiagrams = require('../src/index');
|
||||||
|
|
||||||
|
test('test fail placing', () => {
|
||||||
|
const data = {
|
||||||
|
options: {
|
||||||
|
'diagonals': false,
|
||||||
|
},
|
||||||
|
nodes: [
|
||||||
|
{name: '1', icon: ''},
|
||||||
|
{name: '2', icon: ''},
|
||||||
|
{name: '3', icon: ''},
|
||||||
|
],
|
||||||
|
links: [
|
||||||
|
{from: '1', to: '2', direction: 'left'},
|
||||||
|
{from: '1', to: '3', direction: 'left'},
|
||||||
|
]
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
faDiagrams.compute(data);
|
||||||
|
fail('no error thrown');
|
||||||
|
} catch (err) {
|
||||||
|
expect(err).toBe('Failed to place nodes');
|
||||||
|
}
|
||||||
|
});
|
||||||
+43
-43
@@ -3,35 +3,35 @@ const placing = require('../src/placing');
|
|||||||
|
|
||||||
describe('getBounds', () => {
|
describe('getBounds', () => {
|
||||||
test('no nodes', () => {
|
test('no nodes', () => {
|
||||||
const res = placing({debug: true}).getBounds({});
|
const res = placing({}).getBounds({});
|
||||||
expect(res).toEqual({x: 0, y: 0, w: 0, h: 0});
|
expect(res).toEqual({x: 0, y: 0, w: 0, h: 0});
|
||||||
});
|
});
|
||||||
test('no placed nodes', () => {
|
test('no placed nodes', () => {
|
||||||
const res = placing({debug: true}).getBounds({
|
const res = placing({}).getBounds({
|
||||||
'a': {}, 'b': {}
|
'a': {}, 'b': {}
|
||||||
});
|
});
|
||||||
expect(res).toEqual({x: 0, y: 0, w: 0, h: 0});
|
expect(res).toEqual({x: 0, y: 0, w: 0, h: 0});
|
||||||
});
|
});
|
||||||
test('first node', () => {
|
test('first node', () => {
|
||||||
const res = placing({debug: true}).getBounds({
|
const res = placing({}).getBounds({
|
||||||
'a': {x: 0, y: 0}, 'b': {}
|
'a': {x: 0, y: 0}, 'b': {}
|
||||||
});
|
});
|
||||||
expect(res).toEqual({x: 0, y: 0, w: 1, h: 1});
|
expect(res).toEqual({x: 0, y: 0, w: 1, h: 1});
|
||||||
});
|
});
|
||||||
test('one node not 0,0', () => {
|
test('one node not 0,0', () => {
|
||||||
const res = placing({debug: true}).getBounds({
|
const res = placing({}).getBounds({
|
||||||
'a': {x: 5, y: 6}, 'b': {}
|
'a': {x: 5, y: 6}, 'b': {}
|
||||||
});
|
});
|
||||||
expect(res).toEqual({x: 5, y: 6, w: 1, h: 1});
|
expect(res).toEqual({x: 5, y: 6, w: 1, h: 1});
|
||||||
});
|
});
|
||||||
test('2 nodes', () => {
|
test('2 nodes', () => {
|
||||||
const res = placing({debug: true}).getBounds({
|
const res = placing({}).getBounds({
|
||||||
'a': {x: 0, y: 0}, 'b': {x: 1, y: 1}, 'c': {}
|
'a': {x: 0, y: 0}, 'b': {x: 1, y: 1}, 'c': {}
|
||||||
});
|
});
|
||||||
expect(res).toEqual({x: 0, y: 0, w: 2, h: 2});
|
expect(res).toEqual({x: 0, y: 0, w: 2, h: 2});
|
||||||
});
|
});
|
||||||
test('2 nodes special', () => {
|
test('2 nodes special', () => {
|
||||||
const res = placing({debug: true}).getBounds({
|
const res = placing({}).getBounds({
|
||||||
'a': {x: 1, y: 2}, 'b': {x: -5, y: 6}, 'c': {}
|
'a': {x: 1, y: 2}, 'b': {x: -5, y: 6}, 'c': {}
|
||||||
});
|
});
|
||||||
expect(res).toEqual({x: -5, y: 2, w: 7, h: 5});
|
expect(res).toEqual({x: -5, y: 2, w: 7, h: 5});
|
||||||
@@ -40,29 +40,29 @@ describe('getBounds', () => {
|
|||||||
|
|
||||||
describe('getNewPos', () => {
|
describe('getNewPos', () => {
|
||||||
test('no nodes', () => {
|
test('no nodes', () => {
|
||||||
const res = placing({debug: true}).getNewPos({});
|
const res = placing({}).getNewPos({});
|
||||||
expect(res).toEqual({x: 0, y: 0});
|
expect(res).toEqual({x: 0, y: 0});
|
||||||
});
|
});
|
||||||
test('no placed nodes', () => {
|
test('no placed nodes', () => {
|
||||||
const res = placing({debug: true}).getNewPos({
|
const res = placing({}).getNewPos({
|
||||||
'a': {}, 'b': {}
|
'a': {}, 'b': {}
|
||||||
});
|
});
|
||||||
expect(res).toEqual({x: 0, y: 0});
|
expect(res).toEqual({x: 0, y: 0});
|
||||||
});
|
});
|
||||||
test('one node', () => {
|
test('one node', () => {
|
||||||
const res = placing({debug: true}).getNewPos({
|
const res = placing({}).getNewPos({
|
||||||
'a': {x: 0, y: 0}, 'b': {}
|
'a': {x: 0, y: 0}, 'b': {}
|
||||||
});
|
});
|
||||||
expect(res).toEqual({x: 1, y: 0});
|
expect(res).toEqual({x: 1, y: 0});
|
||||||
});
|
});
|
||||||
test('one node not 0,0', () => {
|
test('one node not 0,0', () => {
|
||||||
const res = placing({debug: true}).getNewPos({
|
const res = placing({}).getNewPos({
|
||||||
'a': {x: 5, y: 6}, 'b': {}
|
'a': {x: 5, y: 6}, 'b': {}
|
||||||
});
|
});
|
||||||
expect(res).toEqual({x: 6, y: 6});
|
expect(res).toEqual({x: 6, y: 6});
|
||||||
});
|
});
|
||||||
test('2 nodes', () => {
|
test('2 nodes', () => {
|
||||||
const res = placing({debug: true}).getNewPos({
|
const res = placing({}).getNewPos({
|
||||||
'a': {x: 0, y: 0}, 'b': {x: 1, y: 1}
|
'a': {x: 0, y: 0}, 'b': {x: 1, y: 1}
|
||||||
});
|
});
|
||||||
expect(res).toEqual({x: 1, y: 0});
|
expect(res).toEqual({x: 1, y: 0});
|
||||||
@@ -71,43 +71,43 @@ describe('getNewPos', () => {
|
|||||||
|
|
||||||
describe('nodeBetween', () => {
|
describe('nodeBetween', () => {
|
||||||
test('only 2 nodes', () => {
|
test('only 2 nodes', () => {
|
||||||
const res = placing({debug: true}).nodeBetween({
|
const res = placing({}).nodeBetween({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 1, y: 0}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 1, y: 0}
|
||||||
}, 'a', 'b');
|
}, 'a', 'b');
|
||||||
expect(res).toBe(false);
|
expect(res).toBe(false);
|
||||||
});
|
});
|
||||||
test('other node not between', () => {
|
test('other node not between', () => {
|
||||||
const res = placing({debug: true}).nodeBetween({
|
const res = placing({}).nodeBetween({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 0, y: 1}, 'c': {name: 'c', x: 1, y: 0}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 0, y: 1}, 'c': {name: 'c', x: 1, y: 0}
|
||||||
}, 'a', 'b');
|
}, 'a', 'b');
|
||||||
expect(res).toBe(false);
|
expect(res).toBe(false);
|
||||||
});
|
});
|
||||||
test('between aligned h', () => {
|
test('between aligned h', () => {
|
||||||
const res = placing({debug: true}).nodeBetween({
|
const res = placing({}).nodeBetween({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 0}, 'c': {name: 'c', x: 1, y: 0}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 0}, 'c': {name: 'c', x: 1, y: 0}
|
||||||
}, 'a', 'b');
|
}, 'a', 'b');
|
||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
});
|
});
|
||||||
test('between aligned v', () => {
|
test('between aligned v', () => {
|
||||||
const res = placing({debug: true}).nodeBetween({
|
const res = placing({}).nodeBetween({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 0, y: 2}, 'c': {name: 'c', x: 0, y: 1}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 0, y: 2}, 'c': {name: 'c', x: 0, y: 1}
|
||||||
}, 'a', 'b');
|
}, 'a', 'b');
|
||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
});
|
});
|
||||||
test('between diagonal', () => {
|
test('between diagonal', () => {
|
||||||
const res = placing({debug: true}).nodeBetween({
|
const res = placing({}).nodeBetween({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 2}, 'c': {name: 'c', x: 1, y: 1}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 2}, 'c': {name: 'c', x: 1, y: 1}
|
||||||
}, 'a', 'b');
|
}, 'a', 'b');
|
||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
});
|
});
|
||||||
test('between diagonal 2', () => {
|
test('between diagonal 2', () => {
|
||||||
const res = placing({debug: true}).nodeBetween({
|
const res = placing({}).nodeBetween({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 1}, 'c': {name: 'c', x: 1, y: 1}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 1}, 'c': {name: 'c', x: 1, y: 1}
|
||||||
}, 'a', 'b');
|
}, 'a', 'b');
|
||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
});
|
});
|
||||||
test('between diagonal 3', () => {
|
test('between diagonal 3', () => {
|
||||||
const res = placing({debug: true}).nodeBetween({
|
const res = placing({}).nodeBetween({
|
||||||
'1': {'name': '1', 'x': 1, 'y': 0},
|
'1': {'name': '1', 'x': 1, 'y': 0},
|
||||||
'2': {'name': '2', 'x': 2, 'y': 0},
|
'2': {'name': '2', 'x': 2, 'y': 0},
|
||||||
'3': {'name': '3', 'x': 1, 'y': 1},
|
'3': {'name': '3', 'x': 1, 'y': 1},
|
||||||
@@ -121,7 +121,7 @@ describe('nodeBetween', () => {
|
|||||||
|
|
||||||
describe('getPosition', () => {
|
describe('getPosition', () => {
|
||||||
test('free node', () => {
|
test('free node', () => {
|
||||||
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
const res = placing({'max-link-length': 2}).getPosition({
|
||||||
'a': {
|
'a': {
|
||||||
const: {
|
const: {
|
||||||
afterX: [],
|
afterX: [],
|
||||||
@@ -135,7 +135,7 @@ describe('getPosition', () => {
|
|||||||
expect(res).toEqual({x: null, y: null, free: true});
|
expect(res).toEqual({x: null, y: null, free: true});
|
||||||
});
|
});
|
||||||
test('constrained to another not placed', () => {
|
test('constrained to another not placed', () => {
|
||||||
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
const res = placing({'max-link-length': 2}).getPosition({
|
||||||
'a': {
|
'a': {
|
||||||
const: {
|
const: {
|
||||||
afterX: [],
|
afterX: [],
|
||||||
@@ -149,7 +149,7 @@ describe('getPosition', () => {
|
|||||||
expect(res).toEqual({x: null, y: null, free: true});
|
expect(res).toEqual({x: null, y: null, free: true});
|
||||||
});
|
});
|
||||||
test('constrained to another left', () => {
|
test('constrained to another left', () => {
|
||||||
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
const res = placing({'max-link-length': 2}).getPosition({
|
||||||
'a': {
|
'a': {
|
||||||
const: {
|
const: {
|
||||||
afterX: [],
|
afterX: [],
|
||||||
@@ -163,7 +163,7 @@ describe('getPosition', () => {
|
|||||||
expect(res).toEqual({x: 1, y: 0, free: false});
|
expect(res).toEqual({x: 1, y: 0, free: false});
|
||||||
});
|
});
|
||||||
test('constrained to another right', () => {
|
test('constrained to another right', () => {
|
||||||
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
const res = placing({'max-link-length': 2}).getPosition({
|
||||||
'a': {
|
'a': {
|
||||||
const: {
|
const: {
|
||||||
afterX: ['b'],
|
afterX: ['b'],
|
||||||
@@ -177,7 +177,7 @@ describe('getPosition', () => {
|
|||||||
expect(res).toEqual({x: -1, y: 0, free: false});
|
expect(res).toEqual({x: -1, y: 0, free: false});
|
||||||
});
|
});
|
||||||
test('constrained to another up', () => {
|
test('constrained to another up', () => {
|
||||||
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
const res = placing({'max-link-length': 2}).getPosition({
|
||||||
'a': {
|
'a': {
|
||||||
const: {
|
const: {
|
||||||
afterX: [],
|
afterX: [],
|
||||||
@@ -191,7 +191,7 @@ describe('getPosition', () => {
|
|||||||
expect(res).toEqual({x: 0, y: 1, free: false});
|
expect(res).toEqual({x: 0, y: 1, free: false});
|
||||||
});
|
});
|
||||||
test('constrained to another down', () => {
|
test('constrained to another down', () => {
|
||||||
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
const res = placing({'max-link-length': 2}).getPosition({
|
||||||
'a': {
|
'a': {
|
||||||
const: {
|
const: {
|
||||||
afterX: [],
|
afterX: [],
|
||||||
@@ -205,7 +205,7 @@ describe('getPosition', () => {
|
|||||||
expect(res).toEqual({x: 0, y: -1, free: false});
|
expect(res).toEqual({x: 0, y: -1, free: false});
|
||||||
});
|
});
|
||||||
test('double constrained diagonal', () => {
|
test('double constrained diagonal', () => {
|
||||||
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
const res = placing({'max-link-length': 2}).getPosition({
|
||||||
'a': {
|
'a': {
|
||||||
const: {
|
const: {
|
||||||
afterX: [],
|
afterX: [],
|
||||||
@@ -220,7 +220,7 @@ describe('getPosition', () => {
|
|||||||
expect(res).toEqual({x: 1, y: 0, free: false});
|
expect(res).toEqual({x: 1, y: 0, free: false});
|
||||||
});
|
});
|
||||||
test('double constrained no diagonal', () => {
|
test('double constrained no diagonal', () => {
|
||||||
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
const res = placing({'max-link-length': 2}).getPosition({
|
||||||
'a': {
|
'a': {
|
||||||
const: {
|
const: {
|
||||||
afterX: [],
|
afterX: [],
|
||||||
@@ -235,7 +235,7 @@ describe('getPosition', () => {
|
|||||||
expect(res).toEqual({x: 2, y: 0, free: false});
|
expect(res).toEqual({x: 2, y: 0, free: false});
|
||||||
});
|
});
|
||||||
test('double constrained impossible', () => {
|
test('double constrained impossible', () => {
|
||||||
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
const res = placing({'max-link-length': 2}).getPosition({
|
||||||
'a': {
|
'a': {
|
||||||
const: {
|
const: {
|
||||||
afterX: [],
|
afterX: [],
|
||||||
@@ -253,11 +253,11 @@ describe('getPosition', () => {
|
|||||||
|
|
||||||
describe('isValid', () => {
|
describe('isValid', () => {
|
||||||
test('no nodes', () => {
|
test('no nodes', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({}, []);
|
const res = placing({diagonals: true}).isValid({}, []);
|
||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
});
|
});
|
||||||
test('no placed nodes', () => {
|
test('no placed nodes', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({
|
const res = placing({diagonals: true}).isValid({
|
||||||
'a': {}, 'b': {}
|
'a': {}, 'b': {}
|
||||||
}, [
|
}, [
|
||||||
{from: 'a', to: 'b'}
|
{from: 'a', to: 'b'}
|
||||||
@@ -265,7 +265,7 @@ describe('isValid', () => {
|
|||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
});
|
});
|
||||||
test('one nodes', () => {
|
test('one nodes', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({
|
const res = placing({diagonals: true}).isValid({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {}
|
||||||
}, [
|
}, [
|
||||||
{from: 'a', to: 'b'}
|
{from: 'a', to: 'b'}
|
||||||
@@ -273,13 +273,13 @@ describe('isValid', () => {
|
|||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
});
|
});
|
||||||
test('overlapping nodes', () => {
|
test('overlapping nodes', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({
|
const res = placing({diagonals: true}).isValid({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 0, y: 0}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 0, y: 0}
|
||||||
}, []);
|
}, []);
|
||||||
expect(res).toBe(false);
|
expect(res).toBe(false);
|
||||||
});
|
});
|
||||||
test('in between node', () => {
|
test('in between node', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({
|
const res = placing({diagonals: true}).isValid({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 0}, 'c': {name: 'c', x: 1, y: 0}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 0}, 'c': {name: 'c', x: 1, y: 0}
|
||||||
}, [
|
}, [
|
||||||
{from: 'a', to: 'b'}
|
{from: 'a', to: 'b'}
|
||||||
@@ -287,7 +287,7 @@ describe('isValid', () => {
|
|||||||
expect(res).toBe(false);
|
expect(res).toBe(false);
|
||||||
});
|
});
|
||||||
test('invalid right link', () => {
|
test('invalid right link', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({
|
const res = placing({diagonals: true}).isValid({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: -2, y: 2}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: -2, y: 2}
|
||||||
}, [
|
}, [
|
||||||
{from: 'a', to: 'b', direction: 'right'}
|
{from: 'a', to: 'b', direction: 'right'}
|
||||||
@@ -295,7 +295,7 @@ describe('isValid', () => {
|
|||||||
expect(res).toBe(false);
|
expect(res).toBe(false);
|
||||||
});
|
});
|
||||||
test('invalid left link', () => {
|
test('invalid left link', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({
|
const res = placing({diagonals: true}).isValid({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 2}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 2}
|
||||||
}, [
|
}, [
|
||||||
{from: 'a', to: 'b', direction: 'left'}
|
{from: 'a', to: 'b', direction: 'left'}
|
||||||
@@ -303,7 +303,7 @@ describe('isValid', () => {
|
|||||||
expect(res).toBe(false);
|
expect(res).toBe(false);
|
||||||
});
|
});
|
||||||
test('invalid up link', () => {
|
test('invalid up link', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({
|
const res = placing({diagonals: true}).isValid({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 2}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 2}
|
||||||
}, [
|
}, [
|
||||||
{from: 'a', to: 'b', direction: 'up'}
|
{from: 'a', to: 'b', direction: 'up'}
|
||||||
@@ -311,7 +311,7 @@ describe('isValid', () => {
|
|||||||
expect(res).toBe(false);
|
expect(res).toBe(false);
|
||||||
});
|
});
|
||||||
test('invalid down link', () => {
|
test('invalid down link', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({
|
const res = placing({diagonals: true}).isValid({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: -2}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: -2}
|
||||||
}, [
|
}, [
|
||||||
{from: 'a', to: 'b', direction: 'down'}
|
{from: 'a', to: 'b', direction: 'down'}
|
||||||
@@ -319,7 +319,7 @@ describe('isValid', () => {
|
|||||||
expect(res).toBe(false);
|
expect(res).toBe(false);
|
||||||
});
|
});
|
||||||
test('valid right link', () => {
|
test('valid right link', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({
|
const res = placing({diagonals: true}).isValid({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 2}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 2}
|
||||||
}, [
|
}, [
|
||||||
{from: 'a', to: 'b', direction: 'right'}
|
{from: 'a', to: 'b', direction: 'right'}
|
||||||
@@ -327,7 +327,7 @@ describe('isValid', () => {
|
|||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
});
|
});
|
||||||
test('valid left link', () => {
|
test('valid left link', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({
|
const res = placing({diagonals: true}).isValid({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: -2, y: 2}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: -2, y: 2}
|
||||||
}, [
|
}, [
|
||||||
{from: 'a', to: 'b', direction: 'left'}
|
{from: 'a', to: 'b', direction: 'left'}
|
||||||
@@ -335,7 +335,7 @@ describe('isValid', () => {
|
|||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
});
|
});
|
||||||
test('valid up link', () => {
|
test('valid up link', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({
|
const res = placing({diagonals: true}).isValid({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: -2}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: -2}
|
||||||
}, [
|
}, [
|
||||||
{from: 'a', to: 'b', direction: 'up'}
|
{from: 'a', to: 'b', direction: 'up'}
|
||||||
@@ -343,7 +343,7 @@ describe('isValid', () => {
|
|||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
});
|
});
|
||||||
test('valid down link', () => {
|
test('valid down link', () => {
|
||||||
const res = placing({debug: true, diagonals: true}).isValid({
|
const res = placing({diagonals: true}).isValid({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 2}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 2}
|
||||||
}, [
|
}, [
|
||||||
{from: 'a', to: 'b', direction: 'down'}
|
{from: 'a', to: 'b', direction: 'down'}
|
||||||
@@ -351,7 +351,7 @@ describe('isValid', () => {
|
|||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
});
|
});
|
||||||
test('invalid diagonal link', () => {
|
test('invalid diagonal link', () => {
|
||||||
const res = placing({debug: true, diagonals: false}).isValid({
|
const res = placing({diagonals: false}).isValid({
|
||||||
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 2}
|
'a': {name: 'a', x: 0, y: 0}, 'b': {name: 'b', x: 2, y: 2}
|
||||||
}, [
|
}, [
|
||||||
{from: 'a', to: 'b'}
|
{from: 'a', to: 'b'}
|
||||||
@@ -363,7 +363,7 @@ describe('isValid', () => {
|
|||||||
describe('correctPlacing', () => {
|
describe('correctPlacing', () => {
|
||||||
test('no nodes', () => {
|
test('no nodes', () => {
|
||||||
const nodes = {};
|
const nodes = {};
|
||||||
placing({debug: true}).correctPlacing(nodes);
|
placing({}).correctPlacing(nodes);
|
||||||
expect(nodes).toEqual({});
|
expect(nodes).toEqual({});
|
||||||
});
|
});
|
||||||
test('several nodes', () => {
|
test('several nodes', () => {
|
||||||
@@ -372,7 +372,7 @@ describe('correctPlacing', () => {
|
|||||||
'b': {x: -2, y: 5},
|
'b': {x: -2, y: 5},
|
||||||
'c': {x: -4, y: 3}
|
'c': {x: -4, y: 3}
|
||||||
};
|
};
|
||||||
placing({debug: true}).correctPlacing(nodes);
|
placing({}).correctPlacing(nodes);
|
||||||
expect(nodes).toEqual({
|
expect(nodes).toEqual({
|
||||||
'a': {x: 7, y: 0},
|
'a': {x: 7, y: 0},
|
||||||
'b': {x: 2, y: 3},
|
'b': {x: 2, y: 3},
|
||||||
|
|||||||
Reference in New Issue
Block a user