Skip to content

Commit

Permalink
replace tape with node:test
Browse files Browse the repository at this point in the history
  • Loading branch information
pirxpilot committed Jan 12, 2024
1 parent 5779177 commit 71b4a2b
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 1,040 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ lint:
$(NODE_BIN)/jshint *.js lib test

test:
$(NODE_BIN)/tape test/*.js test/lame-tiff/*.js | $(NODE_BIN)/tap-dot
node --test test/*.js test/lame-tiff/*.js

.PHONY: check lint test
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@
"server-timings": "^2.0.1"
},
"devDependencies": {
"jshint": "~2",
"supertest": "~6",
"tap-dot": "~2",
"tape": "~5"
"@pirxpilot/jshint": "~3",
"supertest": "~6"
},
"bin": "./server.js",
"scripts": {
Expand All @@ -44,4 +42,4 @@
"index.js",
"lib"
]
}
}
12 changes: 6 additions & 6 deletions test/bounds.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const test = require('tape');
const test = require('node:test');
const assert = require('node:assert/strict');
const path = require('path');

const bounds = require('../lib/bounds');

test('nounds should extract bounds for file', async function (t) {
test('nounds should extract bounds for file', async function () {
const file = path.resolve(__dirname, 'fixtures', 'data', 'srmt-250m_13_3.tif');

t.plan(1);
t.same(await bounds(file), {
assert.deepEqual(await bounds(file), {
minX: -107.00208331573002,
maxX: -106.00208331733002,
minY: 40.408333172679995,
Expand All @@ -21,8 +21,8 @@ test('nounds should extract bounds for file', async function (t) {
tileWidth: 480,
tilesPerCol: 24,
tilesPerRow: 1,
byteCounts: [ 7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680 ],
offsets: [ 578, 8258, 15938, 23618, 31298, 38978, 46658, 54338, 62018, 69698, 77378, 85058, 92738, 100418, 108098, 115778, 123458, 131138, 138818, 146498, 154178, 161858, 169538, 177218 ],
byteCounts: [7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680],
offsets: [578, 8258, 15938, 23618, 31298, 38978, 46658, 54338, 62018, 69698, 77378, 85058, 92738, 100418, 108098, 115778, 123458, 131138, 138818, 146498, 154178, 161858, 169538, 177218],
it: [
51361.000073728006,
480.00000076799995,
Expand Down
32 changes: 15 additions & 17 deletions test/file-bag.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
const test = require('tape');
const test = require('node:test');
const assert = require('node:assert/strict');
const fileBag = require('../lib/file-bag');


test('file bag', function (t) {
test('file bag', async function (t) {

t.test('find file for valid point', function (t) {
await t.test('find file for valid point', function () {

const data = require('./fixtures/data-with-meta/tatry.json');
const fb = fileBag(data);

const { file, meta } = fb.find([ -106.827126, 40.483468 ]);
t.equal(file, '/var/lib/tatry/srmt-250m_13_3.tif');
const { file, meta } = fb.find([-106.827126, 40.483468]);
assert.equal(file, '/var/lib/tatry/srmt-250m_13_3.tif');

t.equal(meta.width, 480);
t.equal(meta.height, 192);
t.equal(meta.it.length, 6);
t.end();
assert.equal(meta.width, 480);
assert.equal(meta.height, 192);
assert.equal(meta.it.length, 6);
});

t.test('find file with best resolution', function (t) {
await t.test('find file with best resolution', function () {

const data = require('./fixtures/data-with-meta/tatry-resolution.json');
const fb = fileBag(data);

const { file, meta } = fb.find([ -106.827126, 40.483468 ]);
t.equal(file, '/var/lib/tatry/srmt-60m_13_3.tif');
const { file, meta } = fb.find([-106.827126, 40.483468]);
assert.equal(file, '/var/lib/tatry/srmt-60m_13_3.tif');

t.equal(meta.width, 480);
t.equal(meta.height, 192);
t.equal(meta.it.length, 6);
t.end();
assert.equal(meta.width, 480);
assert.equal(meta.height, 192);
assert.equal(meta.it.length, 6);
});

});
10 changes: 5 additions & 5 deletions test/interpolate.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const test = require('tape');
const test = require('node:test');
const assert = require('node:assert/strict');
const interpolate = require('../lib/interpolate');


test('interpolate should calculate bilinear interpolation', function (t) {
test('interpolate should calculate bilinear interpolation', function () {
function approx(a, b, e, msg = `${a} should differ from ${b} by no more than ${e}`) {
t.ok(Math.abs(a - b) < e, msg);
assert(Math.abs(a - b) < e, msg);
}

let window = [
14, 20,
15, 21
];
let point = [ 14.5, 20.2 ];
let point = [14.5, 20.2];
let values = [
91, 210,
162, 95
];

t.plan(1);
let v = interpolate(point, window, values);
approx(v, 146.1, 0.000000001);
});
57 changes: 23 additions & 34 deletions test/lame-tiff/file.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,61 @@
const test = require('tape');
const test = require('node:test');
const assert = require('node:assert/strict');
const { promises: { open }, constants: { O_RDONLY } } = require('fs');
const path = require('path');

const { header, ifd, parse } = require('../../lib/lame-tiff/file');

test('tiff file', function (t) {
test('tiff file', async function (t) {
const file = path.resolve(__dirname, '..', 'fixtures', 'data', 'srmt-250m_13_3.tif');
let fh;
const fh = await open(file, O_RDONLY);

t.test('before', async function(t) {
fh = await open(file, O_RDONLY);
t.end();
});

t.test('should parse header', async function (t) {

t.plan(3);
await t.test('should parse header', async function () {
const h = await header(fh);

t.equal(h.fh, fh);
t.equal(h.littleEndian, true);
t.equal(h.ifdOffset, 8);
assert.equal(h.fh, fh);
assert.equal(h.littleEndian, true);
assert.equal(h.ifdOffset, 8);
});

t.test('should parse ifd', async function (t) {
await t.test('should parse ifd', async function () {

const data = await ifd({
fh: fh,
littleEndian: true,
ifdOffset: 8
});

t.equal(data.length, 12);
assert.equal(data.length, 12);
data.forEach(d => {
t.ok(d.name);
t.ok(d.value);
assert(d.name);
assert(d.value);
});
t.end();
});

t.test('should parse file directory', async function (t) {

t.plan(4);
await t.test('should parse file directory', async function () {

const result = await parse(file);

t.ok(result.fh);
t.ok(result.littleEndian);
t.ok(result.fileDirectory);
t.same(result.fileDirectory, {
assert(result.fh);
assert(result.littleEndian);
assert(result.fileDirectory);
assert.deepEqual(result.fileDirectory, {
ImageWidth: 480,
ImageLength: 192,
BitsPerSample: 16,
Compression: 1,
StripOffsets: [ 578, 8258, 15938, 23618, 31298, 38978, 46658, 54338, 62018, 69698, 77378, 85058, 92738, 100418, 108098, 115778, 123458, 131138, 138818, 146498, 154178, 161858, 169538, 177218 ],
StripOffsets: [578, 8258, 15938, 23618, 31298, 38978, 46658, 54338, 62018, 69698, 77378, 85058, 92738, 100418, 108098, 115778, 123458, 131138, 138818, 146498, 154178, 161858, 169538, 177218],
SamplesPerPixel: 1,
RowsPerStrip: 8,
StripByteCounts: [ 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680 ],
StripByteCounts: [7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680],
PlanarConfiguration: 1,
SampleFormat: 2,
ModelPixelScale: [ 0.00208333333, 0.00208333333, 0 ],
ModelTiepoint: [ 0, 0, 0, -107.00208331573002, 40.808333172039994, 0 ],
ModelPixelScale: [0.00208333333, 0.00208333333, 0],
ModelTiepoint: [0, 0, 0, -107.00208331573002, 40.808333172039994, 0],
});
});

t.test('after', async function(t) {
await fh.close();
t.end();
await result.fh.close();
});

await fh.close();
});
44 changes: 21 additions & 23 deletions test/lookup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const test = require('tape');
const test = require('node:test');
const assert = require('node:assert/strict');
const path = require('path');

const makeFileBag = require('../lib/file-bag');
Expand All @@ -19,8 +20,8 @@ const data = [
tileWidth: 480,
tilesPerCol: 24,
tilesPerRow: 1,
byteCounts: Uint32Array.from([ 7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680,7680 ]),
offsets: Uint32Array.from([ 578, 8258, 15938, 23618, 31298, 38978, 46658, 54338, 62018, 69698, 77378, 85058, 92738, 100418, 108098, 115778, 123458, 131138, 138818, 146498, 154178, 161858, 169538, 177218 ]),
byteCounts: Uint32Array.from([7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680]),
offsets: Uint32Array.from([578, 8258, 15938, 23618, 31298, 38978, 46658, 54338, 62018, 69698, 77378, 85058, 92738, 100418, 108098, 115778, 123458, 131138, 138818, 146498, 154178, 161858, 169538, 177218]),
it: [
51361.000073728006,
480.00000076799995,
Expand All @@ -33,45 +34,42 @@ const data = [
}
];

test('lookup', function (t) {
t.test('find a single point', async function (t) {
test('lookup', async function (t) {
await t.test('find a single point', async function () {

const fileBag = makeFileBag(data);
const { lookup } = makeLookup({ fileBag });

const point = [ -106.827126, 40.483468 ];
const point = [-106.827126, 40.483468];

t.plan(1);
const result = await lookup([ point ]);
t.same(result, [ 2082.5 ]);
const result = await lookup([point]);
assert.deepEqual(result, [2082.5]);
});

t.test('find a multiple points', async function (t) {
await t.test('find a multiple points', async function () {

const fileBag = makeFileBag(data);
const { lookup } = makeLookup({ fileBag });

const pointA = [ -106.827126, 40.483468 ];
const pointB = [ -106.1, 40.5 ];
const pointC = [ -106.9, 40.8 ];
const pointA = [-106.827126, 40.483468];
const pointB = [-106.1, 40.5];
const pointC = [-106.9, 40.8];

t.plan(1);
const result = await lookup([ pointA, pointB, pointC ]);
t.same(result, [ 2082.5, 3065, 2474 ]);
const result = await lookup([pointA, pointB, pointC]);
assert.deepEqual(result, [2082.5, 3065, 2474]);
});

t.test('find a multiple points - some invalid', async function (t) {
await t.test('find a multiple points - some invalid', async function () {

const fileBag = makeFileBag(data);
const { lookup } = makeLookup({ fileBag });

const pointA = [ -106.827126, 40.483468 ];
const pointB = [ -110, 44 ]; // invalid point - outside range
const pointC = [ -106.9, 40.8 ];
const pointA = [-106.827126, 40.483468];
const pointB = [-110, 44]; // invalid point - outside range
const pointC = [-106.9, 40.8];

t.plan(1);
const result = await lookup([ pointA, pointB, pointC ]);
t.same(result, [
const result = await lookup([pointA, pointB, pointC]);
assert.deepEqual(result, [
2082.5,
-32768, // invalid elevation
2474
Expand Down
11 changes: 5 additions & 6 deletions test/metas.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const test = require('tape');
const test = require('node:test');
const assert = require('node:assert/strict');
const path = require('path');

const metas = require('../lib/metas');

test('metas should extract metas from directory', async function (t) {
test('metas should extract metas from directory', async function () {

const dir = path.resolve(__dirname, 'fixtures', 'data');

t.plan(2);

const data = await metas(dir);
t.ok(data);
t.equal(data.length, 2);
assert(data);
assert.equal(data.length, 2);
});

0 comments on commit 71b4a2b

Please sign in to comment.