Skip to content

Commit

Permalink
tests: add some; change names
Browse files Browse the repository at this point in the history
  • Loading branch information
mhyfritz committed Oct 3, 2019
1 parent 6135f62 commit b6f45a1
Showing 1 changed file with 58 additions and 28 deletions.
86 changes: 58 additions & 28 deletions src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,111 @@
const hilberCurve = require("../");

test("[truth] order=2, index=0", () => {
test("[indexToPoint] order=0, index=0", () => {
expect(hilberCurve.indexToPoint(0, 0)).toEqual({ x: 0, y: 0 });
});

test("[indexToPoint] order=1, index=0", () => {
expect(hilberCurve.indexToPoint(0, 1)).toEqual({ x: 0, y: 0 });
});

test("[indexToPoint] order=1, index=1", () => {
expect(hilberCurve.indexToPoint(1, 1)).toEqual({ x: 0, y: 1 });
});

test("[indexToPoint] order=1, index=2", () => {
expect(hilberCurve.indexToPoint(2, 1)).toEqual({ x: 1, y: 1 });
});

test("[indexToPoint] order=1, index=3", () => {
expect(hilberCurve.indexToPoint(3, 1)).toEqual({ x: 1, y: 0 });
});

test("[indexToPoint] order=2, index=0", () => {
expect(hilberCurve.indexToPoint(0, 2)).toEqual({ x: 0, y: 0 });
});

test("[truth] order=2, index=1", () => {
test("[indexToPoint] order=2, index=1", () => {
expect(hilberCurve.indexToPoint(1, 2)).toEqual({ x: 1, y: 0 });
});

test("[truth] order=2, index=2", () => {
test("[indexToPoint] order=2, index=2", () => {
expect(hilberCurve.indexToPoint(2, 2)).toEqual({ x: 1, y: 1 });
});

test("[truth] order=2, index=3", () => {
test("[indexToPoint] order=2, index=3", () => {
expect(hilberCurve.indexToPoint(3, 2)).toEqual({ x: 0, y: 1 });
});

test("[truth] order=2, index=4", () => {
test("[indexToPoint] order=2, index=4", () => {
expect(hilberCurve.indexToPoint(4, 2)).toEqual({ x: 0, y: 2 });
});

test("[truth] order=2, index=5", () => {
test("[indexToPoint] order=2, index=5", () => {
expect(hilberCurve.indexToPoint(5, 2)).toEqual({ x: 0, y: 3 });
});

test("[truth] order=2, index=6", () => {
test("[indexToPoint] order=2, index=6", () => {
expect(hilberCurve.indexToPoint(6, 2)).toEqual({ x: 1, y: 3 });
});

test("[truth] order=2, index=7", () => {
test("[indexToPoint] order=2, index=7", () => {
expect(hilberCurve.indexToPoint(7, 2)).toEqual({ x: 1, y: 2 });
});

test("[truth] order=2, index=8", () => {
test("[indexToPoint] order=2, index=8", () => {
expect(hilberCurve.indexToPoint(8, 2)).toEqual({ x: 2, y: 2 });
});

test("[truth] order=2, index=9", () => {
test("[indexToPoint] order=2, index=9", () => {
expect(hilberCurve.indexToPoint(9, 2)).toEqual({ x: 2, y: 3 });
});

test("[truth] order=2, index=10", () => {
test("[indexToPoint] order=2, index=10", () => {
expect(hilberCurve.indexToPoint(10, 2)).toEqual({ x: 3, y: 3 });
});

test("[truth] order=2, index=11", () => {
test("[indexToPoint] order=2, index=11", () => {
expect(hilberCurve.indexToPoint(11, 2)).toEqual({ x: 3, y: 2 });
});

test("[truth] order=2, index=12", () => {
test("[indexToPoint] order=2, index=12", () => {
expect(hilberCurve.indexToPoint(12, 2)).toEqual({ x: 3, y: 1 });
});

test("[truth] order=2, index=13", () => {
test("[indexToPoint] order=2, index=13", () => {
expect(hilberCurve.indexToPoint(13, 2)).toEqual({ x: 2, y: 1 });
});

test("[truth] order=2, index=14", () => {
test("[indexToPoint] order=2, index=14", () => {
expect(hilberCurve.indexToPoint(14, 2)).toEqual({ x: 2, y: 0 });
});

test("[truth] order=2, index=15", () => {
test("[indexToPoint] order=2, index=15", () => {
expect(hilberCurve.indexToPoint(15, 2)).toEqual({ x: 3, y: 0 });
});

test("[truth] order=2", () => {
for (order = 0; order <= 5; order += 1) {
const n = Math.pow(2, order);
for (let index = 0; index < n * n; index += 1) {
test(`[roundtrip: indexToPoint/pointToIndex] order=${order}, index=${index}`, () => {
expect(
hilberCurve.pointToIndex(hilberCurve.indexToPoint(index, order), order)
).toBe(index);
});
}
}

test("[construct] order=0", () => {
const data = [1];
expect(hilberCurve.construct(data, 0)).toEqual([1]);
});

test("[construct] order=1", () => {
const data = [1, 2, 3, 4];
expect(hilberCurve.construct(data, 1)).toEqual([1, 4, 2, 3]);
});

test("[construct] order=2", () => {
const data = Array.from({ length: 4 * 4 }, (_, i) => i + 1);
expect(hilberCurve.construct(data, 2)).toEqual([
1,
Expand All @@ -85,14 +126,3 @@ test("[truth] order=2", () => {
11
]);
});

for (order = 0; order <= 5; order += 1) {
const n = Math.pow(2, order);
for (let index = 0; index < n * n; index += 1) {
test(`[inversion] order=${order}, index=${index}`, () => {
expect(
hilberCurve.pointToIndex(hilberCurve.indexToPoint(index, order), order)
).toBe(index);
});
}
}

0 comments on commit b6f45a1

Please sign in to comment.