mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-17 22:24:49 +02:00
Much expanded tests for osmJoinWays
This commit is contained in:
@@ -23,8 +23,8 @@ describe('iD.actionAddMember', function() {
|
||||
});
|
||||
|
||||
it('appends the member if the ways are not connecting', function() {
|
||||
// Before: --->
|
||||
// After: ---> ... ===>
|
||||
// Before: a ---> b
|
||||
// After: a ---> b .. c ===> d
|
||||
var graph = iD.coreGraph([
|
||||
iD.osmNode({id: 'a', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'b', loc: [0, 0]}),
|
||||
@@ -42,8 +42,8 @@ describe('iD.actionAddMember', function() {
|
||||
});
|
||||
|
||||
it('appends the member if the way connects at end', function() {
|
||||
// Before: --->
|
||||
// After: ---> ===>
|
||||
// Before: a ---> b
|
||||
// After: a ---> b ===> c
|
||||
var graph = iD.coreGraph([
|
||||
iD.osmNode({id: 'a', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'b', loc: [0, 0]}),
|
||||
@@ -60,8 +60,8 @@ describe('iD.actionAddMember', function() {
|
||||
});
|
||||
|
||||
it('inserts the member if the way connects at beginning', function() {
|
||||
// Before: ---> ~~~>
|
||||
// After: ===> ---> ~~~>
|
||||
// Before: b ---> c ~~~> d
|
||||
// After: a ===> b ---> c ~~~> d
|
||||
var graph = iD.coreGraph([
|
||||
iD.osmNode({id: 'a', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'b', loc: [0, 0]}),
|
||||
@@ -81,8 +81,8 @@ describe('iD.actionAddMember', function() {
|
||||
});
|
||||
|
||||
it('inserts the member if the way connects in middle', function() {
|
||||
// Before: ---> ~~~>
|
||||
// After: ---> ===> ~~~>
|
||||
// Before: a ---> b .. c ~~~> d
|
||||
// After: a ---> b ===> c ~~~> d
|
||||
var graph = iD.coreGraph([
|
||||
iD.osmNode({id: 'a', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'b', loc: [0, 0]}),
|
||||
@@ -102,8 +102,8 @@ describe('iD.actionAddMember', function() {
|
||||
});
|
||||
|
||||
it('inserts the member multiple times if the way exists multiple times (middle)', function() {
|
||||
// Before: ---> ~~~> --->
|
||||
// After: ---> ===> ~~~> ===> --->
|
||||
// Before: a ---> b .. c ~~~> d <~~~ c .. b <--- a
|
||||
// After: a ---> b ===> c ~~~> d <~~~ c <=== b <--- a
|
||||
var graph = iD.coreGraph([
|
||||
iD.osmNode({id: 'a', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'b', loc: [0, 0]}),
|
||||
@@ -115,17 +115,18 @@ describe('iD.actionAddMember', function() {
|
||||
iD.osmRelation({id: 'r', members: [
|
||||
{id: '-', type: 'way'},
|
||||
{id: '~', type: 'way'},
|
||||
{id: '~', type: 'way'},
|
||||
{id: '-', type: 'way'}
|
||||
]})
|
||||
]);
|
||||
|
||||
graph = iD.actionAddMember('r', {id: '=', type: 'way'})(graph);
|
||||
expect(members(graph)).to.eql(['-', '=', '~', '=', '-']);
|
||||
expect(members(graph)).to.eql(['-', '=', '~', '~', '=', '-']);
|
||||
});
|
||||
|
||||
it('inserts the member multiple times if the way exists multiple times (beginning/end)', function() {
|
||||
// Before: ===> ~~~> ===>
|
||||
// After: ---> ===> ~~~> ===> --->
|
||||
// Before: b ===> c ~~~> d <~~~ c <=== b
|
||||
// After: a ---> b ===> c ~~~> d <~~~ c <=== b <--- a
|
||||
var graph = iD.coreGraph([
|
||||
iD.osmNode({id: 'a', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'b', loc: [0, 0]}),
|
||||
@@ -137,12 +138,13 @@ describe('iD.actionAddMember', function() {
|
||||
iD.osmRelation({id: 'r', members: [
|
||||
{id: '=', type: 'way'},
|
||||
{id: '~', type: 'way'},
|
||||
{id: '~', type: 'way'},
|
||||
{id: '=', type: 'way'}
|
||||
]})
|
||||
]);
|
||||
|
||||
graph = iD.actionAddMember('r', {id: '-', type: 'way'})(graph);
|
||||
expect(members(graph)).to.eql(['-', '=', '~', '=', '-']);
|
||||
expect(members(graph)).to.eql(['-', '=', '~', '~', '=', '-']);
|
||||
});
|
||||
|
||||
|
||||
|
||||
+224
-65
@@ -145,56 +145,122 @@ describe('iD.osmSimpleMultipolygonOuterMember', function() {
|
||||
|
||||
|
||||
describe('iD.osmJoinWays', function() {
|
||||
function getIDs(objects) {
|
||||
return objects.map(function(node) { return node.id; });
|
||||
}
|
||||
|
||||
it('returns an array of members with nodes properties', function() {
|
||||
var node = iD.osmNode({loc: [0, 0]});
|
||||
var way = iD.osmWay({nodes: [node.id]});
|
||||
var member = {id: way.id, type: 'way'};
|
||||
var node = iD.osmNode({id: 'a', loc: [0, 0]});
|
||||
var way = iD.osmWay({id: '-', nodes: ['a']});
|
||||
var member = {id: '-', type: 'way'};
|
||||
var graph = iD.coreGraph([node, way]);
|
||||
|
||||
var result = iD.osmJoinWays([member], graph);
|
||||
|
||||
expect(result.length).to.equal(1);
|
||||
expect(result[0].nodes.length).to.equal(1);
|
||||
expect(result[0].nodes[0]).to.equal(node);
|
||||
expect(getIDs(result[0].nodes)).to.eql(['a']);
|
||||
expect(result[0].length).to.equal(1);
|
||||
expect(result[0][0]).to.equal(member);
|
||||
expect(result[0][0]).to.have.own.property('id', '-');
|
||||
expect(result[0][0]).to.have.own.property('type', 'way');
|
||||
});
|
||||
|
||||
it('returns the members in the correct order', function() {
|
||||
// a <=== b ---> c ~~~> d
|
||||
var graph = iD.coreGraph([
|
||||
iD.osmNode({id: 'a', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'b', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'c', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'd', loc: [0, 0]}),
|
||||
iD.osmWay({id: '=', nodes: ['b', 'a']}),
|
||||
iD.osmWay({id: '-', nodes: ['b', 'c']}),
|
||||
iD.osmWay({id: '~', nodes: ['c', 'd']}),
|
||||
iD.osmRelation({id: 'r', members: [
|
||||
{id: '-', type: 'way'},
|
||||
{id: '~', type: 'way'},
|
||||
{id: '=', type: 'way'}
|
||||
]})
|
||||
]);
|
||||
it('joins ways', function() {
|
||||
//
|
||||
// a ---> b ===> c
|
||||
//
|
||||
var a = iD.osmNode({id: 'a', loc: [0, 0]});
|
||||
var b = iD.osmNode({id: 'b', loc: [1, 0]});
|
||||
var c = iD.osmNode({id: 'c', loc: [2, 0]});
|
||||
var w1 = iD.osmWay({id: '-', nodes: ['a', 'b']});
|
||||
var w2 = iD.osmWay({id: '=', nodes: ['b', 'c']});
|
||||
var graph = iD.coreGraph([a, b, c, w1, w2]);
|
||||
|
||||
var result = iD.osmJoinWays(graph.entity('r').members, graph);
|
||||
var ids = result[0].map(function (w) { return w.id; });
|
||||
expect(ids).to.have.ordered.members(['=', '-', '~']);
|
||||
var result = iD.osmJoinWays([w1, w2], graph);
|
||||
expect(result.length).to.equal(1);
|
||||
expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c']);
|
||||
expect(result[0].length).to.equal(2);
|
||||
expect(result[0][0]).to.eql(w1);
|
||||
expect(result[0][1]).to.eql(w2);
|
||||
});
|
||||
|
||||
it('joins relation members', function() {
|
||||
//
|
||||
// a ---> b ===> c
|
||||
// r: ['-', '=']
|
||||
//
|
||||
var a = iD.osmNode({id: 'a', loc: [0, 0]});
|
||||
var b = iD.osmNode({id: 'b', loc: [1, 0]});
|
||||
var c = iD.osmNode({id: 'c', loc: [2, 0]});
|
||||
var w1 = iD.osmWay({id: '-', nodes: ['a', 'b']});
|
||||
var w2 = iD.osmWay({id: '=', nodes: ['b', 'c']});
|
||||
var r = iD.osmRelation({id: 'r', members: [
|
||||
{id: '-', type: 'way'},
|
||||
{id: '=', type: 'way'}
|
||||
]});
|
||||
var graph = iD.coreGraph([a, b, c, w1, w2, r]);
|
||||
|
||||
var result = iD.osmJoinWays(r.members, graph);
|
||||
expect(result.length).to.equal(1);
|
||||
expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c']);
|
||||
expect(result[0].length).to.equal(2);
|
||||
expect(result[0][0]).to.have.own.property('id', '-');
|
||||
expect(result[0][0]).to.have.own.property('type', 'way');
|
||||
expect(result[0][1]).to.have.own.property('id', '=');
|
||||
expect(result[0][1]).to.have.own.property('type', 'way');
|
||||
});
|
||||
|
||||
it('returns joined members in the correct order', function() {
|
||||
//
|
||||
// a <=== b ---> c ~~~> d
|
||||
// r: ['-', '~', '=']
|
||||
//
|
||||
var a = iD.osmNode({id: 'a', loc: [0, 0]});
|
||||
var b = iD.osmNode({id: 'b', loc: [1, 0]});
|
||||
var c = iD.osmNode({id: 'c', loc: [2, 0]});
|
||||
var d = iD.osmNode({id: 'd', loc: [3, 0]});
|
||||
var w1 = iD.osmWay({id: '-', nodes: ['b', 'c']});
|
||||
var w2 = iD.osmWay({id: '=', nodes: ['b', 'a']});
|
||||
var w3 = iD.osmWay({id: '~', nodes: ['c', 'd']});
|
||||
var r = iD.osmRelation({id: 'r', members: [
|
||||
{id: '-', type: 'way'},
|
||||
{id: '~', type: 'way'},
|
||||
{id: '=', type: 'way'}
|
||||
]});
|
||||
var graph = iD.coreGraph([a, b, c, d, w1, w2, w3, r]);
|
||||
|
||||
var result = iD.osmJoinWays(r.members, graph);
|
||||
expect(result.length).to.equal(1);
|
||||
expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c', 'd']);
|
||||
expect(result[0].length).to.equal(3);
|
||||
expect(result[0][0]).to.have.own.property('id', '=');
|
||||
expect(result[0][0]).to.have.own.property('type', 'way');
|
||||
expect(result[0][1]).to.have.own.property('id', '-');
|
||||
expect(result[0][1]).to.have.own.property('type', 'way');
|
||||
expect(result[0][2]).to.have.own.property('id', '~');
|
||||
expect(result[0][2]).to.have.own.property('type', 'way');
|
||||
});
|
||||
|
||||
it('reverses member tags of reversed segements', function() {
|
||||
// a --> b <== c
|
||||
// Expected result:
|
||||
// a --> b --> c
|
||||
// tags on === reversed
|
||||
var graph = iD.coreGraph([
|
||||
iD.osmNode({id: 'a'}),
|
||||
iD.osmNode({id: 'b'}),
|
||||
iD.osmNode({id: 'c'}),
|
||||
iD.osmWay({id: '-', nodes: ['a', 'b']}),
|
||||
iD.osmWay({id: '=', nodes: ['c', 'b'], tags: {'oneway': 'yes', 'lanes:forward': 2}})
|
||||
]);
|
||||
//
|
||||
// Source:
|
||||
// a ---> b <=== c
|
||||
// Result:
|
||||
// a ---> b ===> c (and b === c reversed)
|
||||
//
|
||||
var a = iD.osmNode({id: 'a', loc: [0, 0]});
|
||||
var b = iD.osmNode({id: 'b', loc: [1, 0]});
|
||||
var c = iD.osmNode({id: 'c', loc: [2, 0]});
|
||||
var w1 = iD.osmWay({id: '-', nodes: ['a', 'b']});
|
||||
var w2 = iD.osmWay({id: '=', nodes: ['c', 'b'], tags: {'oneway': 'yes', 'lanes:forward': 2}});
|
||||
var graph = iD.coreGraph([a, b, c, w1, w2]);
|
||||
|
||||
var result = iD.osmJoinWays([graph.entity('-'), graph.entity('=')], graph);
|
||||
var result = iD.osmJoinWays([w1, w2], graph);
|
||||
expect(result.length).to.equal(1);
|
||||
expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c']);
|
||||
expect(result[0].length).to.equal(2);
|
||||
expect(result[0][0]).to.eql(w1);
|
||||
expect(result[0][1]).to.be.an.instanceof(iD.osmWay);
|
||||
expect(result[0][1].nodes).to.eql(['b', 'c']);
|
||||
expect(result[0][1].tags).to.eql({'oneway': '-1', 'lanes:backward': 2});
|
||||
});
|
||||
|
||||
@@ -211,35 +277,128 @@ describe('iD.osmJoinWays', function() {
|
||||
expect(iD.osmJoinWays([member], graph)).to.eql([]);
|
||||
});
|
||||
|
||||
it('understands doubled-back relation members', function() {
|
||||
// e
|
||||
// / \
|
||||
// a <=== b ---> c ~~~> d
|
||||
var graph = iD.coreGraph([
|
||||
iD.osmNode({id: 'a', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'b', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'c', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'd', loc: [0, 0]}),
|
||||
iD.osmNode({id: 'e', loc: [0, 0]}),
|
||||
iD.osmWay({id: '=', nodes: ['b', 'a']}),
|
||||
iD.osmWay({id: '-', nodes: ['b', 'c']}),
|
||||
iD.osmWay({id: '~', nodes: ['c', 'd']}),
|
||||
iD.osmWay({id: '\\', nodes: ['d', 'e']}),
|
||||
iD.osmWay({id: '/', nodes: ['c', 'e']}),
|
||||
iD.osmRelation({id: 'r', members: [
|
||||
{id: '=', type: 'way'},
|
||||
{id: '-', type: 'way'},
|
||||
{id: '~', type: 'way'},
|
||||
{id: '\\', type: 'way'},
|
||||
{id: '/', type: 'way'},
|
||||
{id: '-', type: 'way'},
|
||||
{id: '=', type: 'way'}
|
||||
]})
|
||||
]);
|
||||
it('returns multiple arrays for disjoint ways', function() {
|
||||
//
|
||||
// b
|
||||
// / \ d ---> e ===> f
|
||||
// a c
|
||||
//
|
||||
var a = iD.osmNode({id: 'a', loc: [0, -1]});
|
||||
var b = iD.osmNode({id: 'b', loc: [1, 1]});
|
||||
var c = iD.osmNode({id: 'c', loc: [2, -1]});
|
||||
var d = iD.osmNode({id: 'd', loc: [5, 0]});
|
||||
var e = iD.osmNode({id: 'e', loc: [6, 0]});
|
||||
var f = iD.osmNode({id: 'f', loc: [7, 0]});
|
||||
var w1 = iD.osmWay({id: '/', nodes: ['a', 'b']});
|
||||
var w2 = iD.osmWay({id: '\\', nodes: ['b', 'c']});
|
||||
var w3 = iD.osmWay({id: '-', nodes: ['d', 'e']});
|
||||
var w4 = iD.osmWay({id: '=', nodes: ['e', 'f']});
|
||||
var graph = iD.coreGraph([a, b, c, d, e, f, w1, w2, w3, w4]);
|
||||
|
||||
var result = iD.osmJoinWays(graph.entity('r').members, graph);
|
||||
var ids = result[0].map(function (w) { return w.id; });
|
||||
expect(ids).to.have.ordered.members(['=', '-', '~', '\\', '/', '-', '=']);
|
||||
var result = iD.osmJoinWays([w1, w2, w3, w4], graph);
|
||||
|
||||
expect(result.length).to.equal(2);
|
||||
expect(result[0].length).to.equal(2);
|
||||
expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c']);
|
||||
expect(result[0][0]).to.eql(w1);
|
||||
expect(result[0][1]).to.eql(w2);
|
||||
|
||||
expect(result[1].length).to.equal(2);
|
||||
expect(getIDs(result[1].nodes)).to.eql(['d', 'e', 'f']);
|
||||
expect(result[1][0]).to.eql(w3);
|
||||
expect(result[1][1]).to.eql(w4);
|
||||
});
|
||||
|
||||
it('returns multiple arrays for disjoint relations', function() {
|
||||
//
|
||||
// b
|
||||
// / \
|
||||
// a c d ---> e ===> f
|
||||
//
|
||||
// r: ['/', '\', '-', '=']
|
||||
//
|
||||
var a = iD.osmNode({id: 'a', loc: [0, 0]});
|
||||
var b = iD.osmNode({id: 'b', loc: [1, 1]});
|
||||
var c = iD.osmNode({id: 'c', loc: [2, 0]});
|
||||
var d = iD.osmNode({id: 'd', loc: [5, 0]});
|
||||
var e = iD.osmNode({id: 'e', loc: [6, 0]});
|
||||
var f = iD.osmNode({id: 'f', loc: [7, 0]});
|
||||
var w1 = iD.osmWay({id: '/', nodes: ['a', 'b']});
|
||||
var w2 = iD.osmWay({id: '\\', nodes: ['b', 'c']});
|
||||
var w3 = iD.osmWay({id: '-', nodes: ['d', 'e']});
|
||||
var w4 = iD.osmWay({id: '=', nodes: ['e', 'f']});
|
||||
var r = iD.osmRelation({id: 'r', members: [
|
||||
{id: '/', type: 'way'},
|
||||
{id: '\\', type: 'way'},
|
||||
{id: '-', type: 'way'},
|
||||
{id: '=', type: 'way'}
|
||||
]});
|
||||
var graph = iD.coreGraph([a, b, c, d, e, f, w1, w2, w3, w4, r]);
|
||||
var result = iD.osmJoinWays(r.members, graph);
|
||||
|
||||
expect(result.length).to.equal(2);
|
||||
expect(result[0].length).to.equal(2);
|
||||
expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c']);
|
||||
expect(result[0][0]).to.have.own.property('id', '/');
|
||||
expect(result[0][0]).to.have.own.property('type', 'way');
|
||||
expect(result[0][1]).to.have.own.property('id', '\\');
|
||||
expect(result[0][1]).to.have.own.property('type', 'way');
|
||||
|
||||
expect(result[1].length).to.equal(2);
|
||||
expect(getIDs(result[1].nodes)).to.eql(['d', 'e', 'f']);
|
||||
expect(result[1][0]).to.have.own.property('id', '-');
|
||||
expect(result[1][0]).to.have.own.property('type', 'way');
|
||||
expect(result[1][1]).to.have.own.property('id', '=');
|
||||
expect(result[1][1]).to.have.own.property('type', 'way');
|
||||
});
|
||||
|
||||
it('understands doubled-back relation members', function() {
|
||||
//
|
||||
// e
|
||||
// / \
|
||||
// a <=== b ---> c ~~~> d
|
||||
//
|
||||
// r: ['=', '-', '~', '\', '/', '-', '=']
|
||||
//
|
||||
var a = iD.osmNode({id: 'a', loc: [0, 0]});
|
||||
var b = iD.osmNode({id: 'b', loc: [1, 0]});
|
||||
var c = iD.osmNode({id: 'c', loc: [2, 0]});
|
||||
var d = iD.osmNode({id: 'd', loc: [4, 0]});
|
||||
var e = iD.osmNode({id: 'e', loc: [3, 1]});
|
||||
var w1 = iD.osmWay({id: '=', nodes: ['b', 'a']});
|
||||
var w2 = iD.osmWay({id: '-', nodes: ['b', 'c']});
|
||||
var w3 = iD.osmWay({id: '~', nodes: ['c', 'd']});
|
||||
var w4 = iD.osmWay({id: '\\', nodes: ['d', 'e']});
|
||||
var w5 = iD.osmWay({id: '/', nodes: ['c', 'e']});
|
||||
var r = iD.osmRelation({id: 'r', members: [
|
||||
{id: '=', type: 'way'},
|
||||
{id: '-', type: 'way'},
|
||||
{id: '~', type: 'way'},
|
||||
{id: '\\', type: 'way'},
|
||||
{id: '/', type: 'way'},
|
||||
{id: '-', type: 'way'},
|
||||
{id: '=', type: 'way'}
|
||||
]});
|
||||
var graph = iD.coreGraph([a, b, c, d, e, w1, w2, w3, w4, w5, r]);
|
||||
|
||||
var result = iD.osmJoinWays(r.members, graph);
|
||||
expect(result.length).to.equal(1);
|
||||
expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c', 'd', 'e', 'c', 'b', 'a']);
|
||||
expect(result[0].length).to.equal(7);
|
||||
expect(result[0][0]).to.have.own.property('id', '=');
|
||||
expect(result[0][0]).to.have.own.property('type', 'way');
|
||||
expect(result[0][1]).to.have.own.property('id', '-');
|
||||
expect(result[0][1]).to.have.own.property('type', 'way');
|
||||
expect(result[0][2]).to.have.own.property('id', '~');
|
||||
expect(result[0][2]).to.have.own.property('type', 'way');
|
||||
expect(result[0][3]).to.have.own.property('id', '\\');
|
||||
expect(result[0][3]).to.have.own.property('type', 'way');
|
||||
expect(result[0][4]).to.have.own.property('id', '/');
|
||||
expect(result[0][4]).to.have.own.property('type', 'way');
|
||||
expect(result[0][5]).to.have.own.property('id', '-');
|
||||
expect(result[0][5]).to.have.own.property('type', 'way');
|
||||
expect(result[0][6]).to.have.own.property('id', '=');
|
||||
expect(result[0][6]).to.have.own.property('type', 'way');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user