From 723f0ca43a0ee1891ced6a641449c1d8dc47025a Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Fri, 23 Dec 2016 14:58:18 -0500 Subject: [PATCH] Add tests for transitioned straighten action --- test/spec/actions/straighten.js | 89 +++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 16 deletions(-) diff --git a/test/spec/actions/straighten.js b/test/spec/actions/straighten.js index 93097f44d..e9c63ed4f 100644 --- a/test/spec/actions/straighten.js +++ b/test/spec/actions/straighten.js @@ -5,12 +5,11 @@ describe('iD.actionStraighten', function () { it('returns falsy for ways with internal nodes near centerline', function () { var graph = iD.Graph([ iD.Node({id: 'a', loc: [0, 0]}), - iD.Node({id: 'b', loc: [1, 0.1]}), + iD.Node({id: 'b', loc: [1, 0.01]}), iD.Node({id: 'c', loc: [2, 0]}), iD.Node({id: 'd', loc: [3, 0]}), iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']}) ]); - expect(iD.actionStraighten('-', projection).disabled(graph)).not.to.be.ok; }); @@ -22,7 +21,6 @@ describe('iD.actionStraighten', function () { iD.Node({id: 'd', loc: [3, 0]}), iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']}) ]); - expect(iD.actionStraighten('-', projection).disabled(graph)).to.equal('too_bendy'); }); @@ -34,49 +32,108 @@ describe('iD.actionStraighten', function () { iD.Node({id: 'd', loc: [0, 0]}), iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']}) ]); - expect(iD.actionStraighten('-', projection).disabled(graph)).to.equal('too_bendy'); }); }); + it('deletes empty nodes', function() { var graph = iD.Graph([ iD.Node({id: 'a', loc: [0, 0]}), - iD.Node({id: 'b', loc: [2, 0], tags: {}}), - iD.Node({id: 'c', loc: [2, 2]}), + iD.Node({id: 'b', loc: [1, 0.01], tags: {}}), + iD.Node({id: 'c', loc: [2, 0]}), iD.Way({id: '-', nodes: ['a', 'b', 'c']}) ]); graph = iD.actionStraighten('-', projection)(graph); - + expect(graph.entity('-').nodes).to.eql(['a', 'c']); expect(graph.hasEntity('b')).to.eq(undefined); }); it('does not delete tagged nodes', function() { var graph = iD.Graph([ iD.Node({id: 'a', loc: [0, 0]}), - iD.Node({id: 'b', loc: [2, 0], tags: {foo: 'bar'}}), - iD.Node({id: 'c', loc: [2, 2]}), + iD.Node({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}), + iD.Node({id: 'c', loc: [2, 0]}), iD.Way({id: '-', nodes: ['a', 'b', 'c']}) ]); graph = iD.actionStraighten('-', projection)(graph); - expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c']); + expect(graph.entity('b').loc[0]).to.be.closeTo(1, 1e-6); + expect(graph.entity('b').loc[1]).to.be.closeTo(0, 1e-6); }); it('does not delete nodes connected to other ways', 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']}), + iD.Node({id: 'b', loc: [1, 0.01]}), + iD.Node({id: 'c', loc: [2, 0]}), + iD.Way({id: '-', nodes: ['a', 'b', 'c']}), iD.Way({id: '=', nodes: ['b']}) ]); graph = iD.actionStraighten('-', projection)(graph); - - expect(graph.entity('-').nodes).to.have.length(3); + expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c']); + expect(graph.entity('b').loc[0]).to.be.closeTo(1, 1e-6); + expect(graph.entity('b').loc[1]).to.be.closeTo(0, 1e-6); }); + + + describe('transitions', function () { + it('is transitionable', function() { + expect(iD.actionStraighten().transitionable).to.be.true; + }); + + it('straighten at t = 0', function() { + var graph = iD.Graph([ + iD.Node({id: 'a', loc: [0, 0]}), + iD.Node({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}), + iD.Node({id: 'c', loc: [2, -0.01]}), + iD.Node({id: 'd', loc: [3, 0]}), + iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']}) + ]); + + graph = iD.actionStraighten('-', projection)(graph, 0); + expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c', 'd']); + expect(graph.entity('b').loc[0]).to.be.closeTo(1, 1e-6); + expect(graph.entity('b').loc[1]).to.be.closeTo(0.01, 1e-6); + expect(graph.entity('c').loc[0]).to.be.closeTo(2, 1e-6); + expect(graph.entity('c').loc[1]).to.be.closeTo(-0.01, 1e-6); + }); + + it('straighten at t = 0.5', function() { + var graph = iD.Graph([ + iD.Node({id: 'a', loc: [0, 0]}), + iD.Node({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}), + iD.Node({id: 'c', loc: [2, -0.01]}), + iD.Node({id: 'd', loc: [3, 0]}), + iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']}) + ]); + + graph = iD.actionStraighten('-', projection)(graph, 0.5); + expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c', 'd']); + expect(graph.entity('b').loc[0]).to.be.closeTo(1, 1e-6); + expect(graph.entity('b').loc[1]).to.be.closeTo(0.005, 1e-6); + expect(graph.entity('c').loc[0]).to.be.closeTo(2, 1e-6); + expect(graph.entity('c').loc[1]).to.be.closeTo(-0.005, 1e-6); + }); + + it('straighten at t = 1', function() { + var graph = iD.Graph([ + iD.Node({id: 'a', loc: [0, 0]}), + iD.Node({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}), + iD.Node({id: 'c', loc: [2, -0.01]}), + iD.Node({id: 'd', loc: [3, 0]}), + iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']}) + ]); + + graph = iD.actionStraighten('-', projection)(graph, 1); + expect(graph.entity('-').nodes).to.eql(['a', 'b', 'd']); + expect(graph.entity('b').loc[0]).to.be.closeTo(1, 1e-6); + expect(graph.entity('b').loc[1]).to.be.closeTo(0, 1e-6); + expect(graph.hasEntity('c')).to.eq(undefined); + }); + }); + });