Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
veltman committed Jul 21, 2017
1 parent b5f936a commit cc00f88
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
40 changes: 40 additions & 0 deletions test/add-test.js
Expand Up @@ -96,3 +96,43 @@ tape("Bisect segments", function(test) {

test.end();
});

tape("Zero-length handling", function(test) {
let original = {
all: [[0, 0], [0, 0], [0, 0]],
partial: [[0, 0], [1, 1], [1, 1], [1, 1]],
single: [[0, 0]]
};

let added = {};

for (let key in original) {
added[key] = original[key].slice(0);
addPoints(added[key], 2);
}

test.inDelta(added.all, [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]);

test.inDelta(added.single, [[0, 0], [0, 0], [0, 0]]);

test.inDelta(added.partial, [[0, 0], [0.5, 0.5], [1, 1], [1, 1], [1, 1], [0.5, 0.5]]);

test.end();
});

tape("Line segment", function(test) {
let original = [[0, 0], [100, 0]],
added;

added = original.slice(0);
addPoints(added, 1);

test.inDelta(added, [[0, 0], [100, 0], [100, 0]]);

added = original.slice(0);
addPoints(added, 2);

test.inDelta(added, [[0, 0], [50, 0], [100, 0], [50, 0]]);

test.end();
});
12 changes: 6 additions & 6 deletions test/normalize-test.js
Expand Up @@ -59,12 +59,12 @@ tape("Expects valid ring or string", function(test) {

tape("Bisect", function(test) {

// No bisecting zero-length segments
test.deepEqual(normalizeRing([[0, 0]], 1e-6), [[0, 0]]);
test.deepEqual(normalizeRing([[0, 0], [0, 0], [0, 0]], 1e-6), [[0, 0], [0, 0]]);
test.deepEqual(normalizeRing([[0, 0], [0, 0], [1, 0]], 0.6), [[0, 0], [0, 0], [0.5, 0], [1, 0], [0.5, 0]]);
// No bisecting zero-length segments
test.deepEqual(normalizeRing([[0, 0]], 1e-6), [[0, 0]]);
test.deepEqual(normalizeRing([[0, 0], [0, 0], [0, 0]], 1e-6), [[0, 0], [0, 0]]);
test.deepEqual(normalizeRing([[0, 0], [0, 0], [1, 0]], 0.6), [[0, 0], [0, 0], [0.5, 0], [1, 0], [0.5, 0]]);

test.deepEqual(normalizeRing([[0, 0], [1, 0]], 0.6), [[0, 0], [0.5, 0], [1, 0], [0.5, 0]]);
test.end();
test.deepEqual(normalizeRing([[0, 0], [1, 0]], 0.6), [[0, 0], [0.5, 0], [1, 0], [0.5, 0]]);
test.end();

});

0 comments on commit cc00f88

Please sign in to comment.