more unit tests

This commit is contained in:
Clément GOUIN
2019-07-11 15:59:48 +02:00
parent 1acf493441
commit a0f5af5c0e
2 changed files with 107 additions and 18 deletions
+76
View File
@@ -112,4 +112,80 @@ describe('nodeBetween', () => {
}, 'a', 'b');
expect(res).toBe(true);
});
});
describe('getPosition', () => {
test('free node', () => {
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
'a': {
const: {
afterX: [],
beforeX: [],
afterY: [],
beforeY: []
}
},
'b': {x: 0, y: 0}
}, 'a', true);
expect(res).toEqual({x: null, y: null, free: true});
});
test('constrained to another', () => {
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
'a': {
const: {
afterX: [],
beforeX: ['b'],
afterY: [],
beforeY: []
}
},
'b': {x: 0, y: 0}
}, 'a', true);
expect(res).toEqual({x: 1, y: 0, free: false});
});
test('double constrained diagonal', () => {
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
'a': {
const: {
afterX: [],
beforeX: ['b'],
afterY: ['c'],
beforeY: []
}
},
'b': {x: 0, y: 0},
'c': {x: 2, y: 1}
}, 'a', true);
expect(res).toEqual({x: 1, y: 0, free: false});
});
test('double constrained no diagonal', () => {
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
'a': {
const: {
afterX: [],
beforeX: ['b'],
afterY: ['c'],
beforeY: []
}
},
'b': {x: 0, y: 0},
'c': {x: 2, y: 1}
}, 'a', false);
expect(res).toEqual({x: 2, y: 0, free: false});
});
test('double constrained impossible', () => {
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
'a': {
const: {
afterX: [],
beforeX: ['b'],
afterY: ['c'],
beforeY: []
}
},
'b': {x: 0, y: 0},
'c': {x: 2, y: 10}
}, 'a', false);
expect(res).toEqual(null);
});
});