Navigation Menu

Skip to content

Commit

Permalink
Update brittle tests with more valid outcomes
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbrinkman committed Nov 10, 2018
1 parent eece4e0 commit 6fa33aa
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions test/sugiyama/decross/twoLayer-test.js
Expand Up @@ -3,6 +3,14 @@ const tape = require("tape"),
load = require("../../load"),
d3_dag = require("../../../");

// These tests are fragile as there are many possible configurations and not
// many invariants to acurately exploit.

/// One of expected is close to actual
function oneClose(actual, ...expected) {
return expected.some(expect => expect.every((v, i) => close(actual[i], v)));
}

tape("decrossTwoLayer() default works for grafo", test => {
const layout = d3_dag.sugiyama()
.layering(d3_dag.layeringLongestPath())
Expand All @@ -11,8 +19,9 @@ tape("decrossTwoLayer() default works for grafo", test => {
.size([140, 5]);
const dag = layout(load("grafo"));
const ordered = dag.descendants().sort((a, b) => a.id - b.id).map(n => n.x);
const expected = [60, 14, 56, 84, 140, 140, 35, 70, 28, 140, 105, 80, 140, 120, 0, 28, 70, 42, 140, 20, 112, 70];
test.ok(ordered.every((v, i) => close(v, expected[i])));
const expected1 = [60, 14, 56, 84, 140, 140, 35, 70, 28, 140, 105, 80, 140, 120, 0, 28, 70, 42, 140, 20, 112, 70];
const expected2 = [60, 28, 56, 84, 140, 140, 0, 70, 28, 140, 105, 80, 140, 120, 35, 14, 70, 42, 140, 20, 112, 70];
test.ok(oneClose(ordered, expected1, expected2))
test.end();
});

Expand All @@ -24,8 +33,9 @@ tape("decrossTwoLayer() median works for grafo", test => {
.size([140, 5]);
const dag = layout(load("grafo"));
const ordered = dag.descendants().sort((a, b) => a.id - b.id).map(n => n.x);
const expected = [60, 14, 56, 84, 140, 140, 35, 70, 28, 140, 105, 80, 140, 120, 0, 28, 70, 42, 140, 20, 112, 70];
test.ok(ordered.every((v, i) => close(v, expected[i])));
const expected1 = [60, 14, 56, 84, 140, 140, 35, 70, 28, 140, 105, 80, 140, 120, 0, 28, 70, 42, 140, 20, 112, 70];
const expected2 = [60, 28, 56, 84, 140, 140, 0, 70, 28, 140, 105, 80, 140, 120, 35, 14, 70, 42, 140, 20, 112, 70];
test.ok(oneClose(ordered, expected1, expected2))
test.end();
});

Expand All @@ -37,8 +47,9 @@ tape("decrossTwoLayer() mean works for grafo", test => {
.size([140, 5]);
const dag = layout(load("grafo"));
const ordered = dag.descendants().sort((a, b) => a.id - b.id).map(n => n.x);
const expected = [60, 14, 56, 84, 140, 140, 70, 35, 28, 140, 105, 80, 140, 120, 0, 28, 70, 42, 140, 20, 112, 70];
test.ok(ordered.every((v, i) => close(v, expected[i])));
const expected1 = [60, 14, 56, 84, 140, 140, 70, 35, 28, 140, 105, 80, 140, 120, 0, 28, 70, 42, 140, 20, 112, 70];
const expected2 = [60, 28, 56, 84, 140, 140, 70, 35, 28, 140, 105, 80, 140, 120, 0, 14, 70, 42, 140, 20, 112, 70];
test.ok(oneClose(ordered, expected1, expected2))
test.end();
});

Expand All @@ -50,8 +61,8 @@ tape("decrossTwoLayer() opt works for grafo", test => {
.size([140, 5]);
const dag = layout(load("grafo"));
const ordered = dag.descendants().sort((a, b) => a.id - b.id).map(n => n.x);
const expected = [20, 140, 112, 98, 84, 35, 105, 70, 0, 80, 0, 120, 140, 140, 140, 126, 14, 84, 70, 100, 112, 70];
test.ok(ordered.every((v, i) => close(v, expected[i])));
const expected1 = [20, 140, 112, 98, 84, 35, 105, 70, 0, 80, 0, 120, 140, 140, 140, 126, 14, 84, 70, 100, 112, 70];
test.ok(oneClose(ordered, expected1))
test.end();
});

Expand Down

0 comments on commit 6fa33aa

Please sign in to comment.