More tests, add uniq operator

This commit is contained in:
Jon D
2016-11-05 20:36:34 +00:00
parent 05421e1c25
commit 1eaa284afe
2 changed files with 52 additions and 7 deletions
+3 -1
View File
@@ -27,8 +27,10 @@ export function actionFlip(wayId, isVertical, projection) {
.map(function (nodeId) {
return graph.entity(nodeId);
})
// Only process each node once, as the first node will be listed twice in the way
.uniqBy(function (node) { return node.id; })
// Get distance from midPoint and produce a translated node
.map(function (node) {
// Get distance from midPoint
const delta = isVertical ?
node.loc[1] - midPoint :
node.loc[0] - midPoint;
+49 -6
View File
@@ -21,14 +21,57 @@ describe('iD.actionFlip', function() {
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}})
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}})
]);
graph = iD.actionFlip('-', false, projection)(graph);
expect(graph.entity('a').loc[0]).to.equal(2); // A should be 2,0 now
expect(graph.entity('b').loc[0]).to.equal(0); // B should be 0,0 now
expect(graph.entity('c').loc[0]).to.equal(0); // C should be 0,2 now
expect(graph.entity('d').loc[0]).to.equal(2); // D should be 2,0 now
expect(graph.entity('a').loc[0]).to.equal(2); // A should be 2,0 now
expect(graph.entity('b').loc[0]).to.equal(0); // B should be 0,0 now
expect(graph.entity('c').loc[0]).to.equal(0); // C should be 0,2 now
expect(graph.entity('d').loc[0]).to.equal(2); // D should be 2,2 now
});
it('flips horizontally - does not alter y value', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}})
]);
graph = iD.actionFlip('-', false, projection)(graph);
expect(graph.entity('a').loc[1]).to.equal(0); // A should be 2,0 now
expect(graph.entity('b').loc[1]).to.equal(0); // B should be 0,0 now
expect(graph.entity('c').loc[1]).to.equal(2); // C should be 0,2 now
expect(graph.entity('d').loc[1]).to.equal(2); // D should be 2,2 now
});
it('flips vertically - alters y value', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}})
]);
graph = iD.actionFlip('-', true, projection)(graph);
expect(graph.entity('a').loc[1]).to.equal(2); // A should be 0,2 now
expect(graph.entity('b').loc[1]).to.equal(2); // B should be 2,2 now
expect(graph.entity('c').loc[1]).to.equal(0); // C should be 2,0 now
expect(graph.entity('d').loc[1]).to.equal(0); // D should be 0,0 now
});
it('flips vertically - does not alter x value', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}})
]);
graph = iD.actionFlip('-', true, projection)(graph);
expect(graph.entity('a').loc[0]).to.equal(0); // A should be 0,2 now
expect(graph.entity('b').loc[0]).to.equal(2); // B should be 2,2 now
expect(graph.entity('c').loc[0]).to.equal(2); // C should be 2,0 now
expect(graph.entity('d').loc[0]).to.equal(0); // D should be 0,0 now
});
});