mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-23 16:49:40 +02:00
Specs for Way#areAdjacent
This commit is contained in:
+1
-1
@@ -59,7 +59,7 @@ _.extend(iD.Way.prototype, {
|
||||
|
||||
areAdjacent: function(n1, n2) {
|
||||
for (var i = 0; i < this.nodes.length; i++) {
|
||||
if (this.nodes[i] === n1) {
|
||||
if (this.nodes[i] === n1) {
|
||||
if (this.nodes[i - 1] === n2) return true;
|
||||
if (this.nodes[i + 1] === n2) return true;
|
||||
}
|
||||
|
||||
@@ -141,6 +141,30 @@ describe('iD.Way', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#areAdjacent", function() {
|
||||
it("returns false for nodes not in the way", function() {
|
||||
expect(iD.Way().areAdjacent('a', 'b')).to.equal(false);
|
||||
});
|
||||
|
||||
it("returns false for non-adjacent nodes in the way", function() {
|
||||
expect(iD.Way({nodes: ['a', 'b', 'c']}).areAdjacent('a', 'c')).to.equal(false);
|
||||
});
|
||||
|
||||
it("returns true for adjacent nodes in the way (forward)", function() {
|
||||
var way = iD.Way({nodes: ['a', 'b', 'c', 'd']});
|
||||
expect(way.areAdjacent('a', 'b')).to.equal(true);
|
||||
expect(way.areAdjacent('b', 'c')).to.equal(true);
|
||||
expect(way.areAdjacent('c', 'd')).to.equal(true);
|
||||
});
|
||||
|
||||
it("returns true for adjacent nodes in the way (reverse)", function() {
|
||||
var way = iD.Way({nodes: ['a', 'b', 'c', 'd']});
|
||||
expect(way.areAdjacent('b', 'a')).to.equal(true);
|
||||
expect(way.areAdjacent('c', 'b')).to.equal(true);
|
||||
expect(way.areAdjacent('d', 'c')).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#geometry", function() {
|
||||
it("returns 'line' when the way is not an area", function () {
|
||||
expect(iD.Way().geometry()).to.equal('line');
|
||||
|
||||
Reference in New Issue
Block a user