more unit tests
This commit is contained in:
+3
-3
@@ -23,7 +23,7 @@ module.exports = (options) => {
|
|||||||
/**
|
/**
|
||||||
* @param {Object<string,Node1>} nodes
|
* @param {Object<string,Node1>} nodes
|
||||||
*/
|
*/
|
||||||
debugMap: (nodes) => {
|
/*debugMap: (nodes) => {
|
||||||
const b = self.getBounds(nodes);
|
const b = self.getBounds(nodes);
|
||||||
|
|
||||||
const map = newmap(b.w, b.h).map(row => row.map(() => []));
|
const map = newmap(b.w, b.h).map(row => row.map(() => []));
|
||||||
@@ -38,7 +38,7 @@ module.exports = (options) => {
|
|||||||
}));
|
}));
|
||||||
out = out.map(row => row.map(cell => cell + new Array(maxLen - cell.length).fill(' ').join('')));
|
out = out.map(row => row.map(cell => cell + new Array(maxLen - cell.length).fill(' ').join('')));
|
||||||
console.log('\n' + out.map(row => row.join('|')).join('\n') + '\n');
|
console.log('\n' + out.map(row => row.join('|')).join('\n') + '\n');
|
||||||
},
|
},*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current bounds of the graph of nodes
|
* Get the current bounds of the graph of nodes
|
||||||
@@ -255,7 +255,7 @@ module.exports = (options) => {
|
|||||||
* @returns {null|Object<string,Node1>}
|
* @returns {null|Object<string,Node1>}
|
||||||
*/
|
*/
|
||||||
applyLinks: (nodes, links, depth = 0) => {
|
applyLinks: (nodes, links, depth = 0) => {
|
||||||
if (self.debug) self.debugMap(nodes);
|
//if (self.debug) self.debugMap(nodes);
|
||||||
|
|
||||||
if (!self.isValid(nodes, links)) {
|
if (!self.isValid(nodes, links)) {
|
||||||
if (self.debug) console.log(`${new Array(depth).fill('.').join('')}invalid node placement`);
|
if (self.debug) console.log(`${new Array(depth).fill('.').join('')}invalid node placement`);
|
||||||
|
|||||||
+57
-1
@@ -129,7 +129,21 @@ describe('getPosition', () => {
|
|||||||
}, 'a', true);
|
}, 'a', true);
|
||||||
expect(res).toEqual({x: null, y: null, free: true});
|
expect(res).toEqual({x: null, y: null, free: true});
|
||||||
});
|
});
|
||||||
test('constrained to another', () => {
|
test('constrained to another not placed', () => {
|
||||||
|
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
||||||
|
'a': {
|
||||||
|
const: {
|
||||||
|
afterX: [],
|
||||||
|
beforeX: ['b'],
|
||||||
|
afterY: [],
|
||||||
|
beforeY: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'b': {}
|
||||||
|
}, 'a', true);
|
||||||
|
expect(res).toEqual({x: null, y: null, free: true});
|
||||||
|
});
|
||||||
|
test('constrained to another left', () => {
|
||||||
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
||||||
'a': {
|
'a': {
|
||||||
const: {
|
const: {
|
||||||
@@ -143,6 +157,48 @@ describe('getPosition', () => {
|
|||||||
}, 'a', true);
|
}, 'a', true);
|
||||||
expect(res).toEqual({x: 1, y: 0, free: false});
|
expect(res).toEqual({x: 1, y: 0, free: false});
|
||||||
});
|
});
|
||||||
|
test('constrained to another right', () => {
|
||||||
|
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
||||||
|
'a': {
|
||||||
|
const: {
|
||||||
|
afterX: ['b'],
|
||||||
|
beforeX: [],
|
||||||
|
afterY: [],
|
||||||
|
beforeY: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'b': {x: 0, y: 0}
|
||||||
|
}, 'a', true);
|
||||||
|
expect(res).toEqual({x: -1, y: 0, free: false});
|
||||||
|
});
|
||||||
|
test('constrained to another up', () => {
|
||||||
|
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
||||||
|
'a': {
|
||||||
|
const: {
|
||||||
|
afterX: [],
|
||||||
|
beforeX: [],
|
||||||
|
afterY: [],
|
||||||
|
beforeY: ['b']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'b': {x: 0, y: 0}
|
||||||
|
}, 'a', true);
|
||||||
|
expect(res).toEqual({x: 0, y: 1, free: false});
|
||||||
|
});
|
||||||
|
test('constrained to another down', () => {
|
||||||
|
const res = placing({debug: true, 'max-link-length': 2}).getPosition({
|
||||||
|
'a': {
|
||||||
|
const: {
|
||||||
|
afterX: [],
|
||||||
|
beforeX: [],
|
||||||
|
afterY: ['b'],
|
||||||
|
beforeY: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'b': {x: 0, y: 0}
|
||||||
|
}, 'a', true);
|
||||||
|
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({debug: true, 'max-link-length': 2}).getPosition({
|
||||||
'a': {
|
'a': {
|
||||||
|
|||||||
Reference in New Issue
Block a user