Skip to content

Commit

Permalink
A bit more test coverage for buildPermutationTable
Browse files Browse the repository at this point in the history
  • Loading branch information
jwagner committed Jul 23, 2022
1 parent 6a374ac commit c4d3bfb
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions test/simplex-noise-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@ function getRandom(seed = 'seed') {
return alea(seed);
}

// TODO improve those
describe('buildPermutationTable', function () {
it('contains all indices exactly once', function () {
it('first half contains all indices exactly once', function () {
const table = buildPermutationTable(getRandom());
const aTable = Array.prototype.slice.call(table);
for (let i = 0; i < aTable.length / 2; i++) {
assert.include(aTable, i);
const firstHalf = Array.prototype.slice.call(table, 0, table.length / 2);
for (let i = 0; i < firstHalf.length / 2; i++) {
assert.include(firstHalf, i);
}
});
it('is shuffled', function () {
const tableA = buildPermutationTable(getRandom('A'));
const tableB = buildPermutationTable(getRandom('B'));
assert.notDeepEqual(tableA, tableB);
});
it('second half mirrors first half', function () {
const table = buildPermutationTable(getRandom());
const firstHalf = Array.prototype.slice.call(table, 0, table.length / 2);
const secondHalf = Array.prototype.slice.call(table, table.length / 2);
assert.deepEqual(firstHalf, secondHalf);
});
it('can contain 0 in the first position', function () {
function zero() { return 0; }
const table = buildPermutationTable(zero);
Expand Down

0 comments on commit c4d3bfb

Please sign in to comment.