-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
67 lines (58 loc) · 2.28 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const fs = require("fs");
const test = require("flug");
const fastMin = require("./index");
test("gettings minimum from a normal array", ({ eq }) => {
const numbers = [920, -550, 340, 690, 550, -340, 840, 700, 550, 210, 540];
const result = fastMin(numbers, { debug: false });
eq(result, -550);
});
test("getting minimum from an array of image band values", ({ eq }) => {
const numbers = Uint8Array.from(JSON.parse(fs.readFileSync("uint8-numbers.json", "utf-8")));
console.log("loaded uint8 numbers of length:", numbers.length);
const result = fastMin(numbers, { debug: true });
eq(result, 0);
});
test("getting minimum from typed arrays", ({ eq }) => {
[
[Int8Array, -128],
[Uint8Array, 0],
[Int16Array, -32768],
[Uint16Array, 0]
].forEach(([array_type, expected_min]) => {
const filename = array_type.name.replace("Array", "").toLowerCase() + "-numbers.json";
const numbers = array_type.from(JSON.parse(fs.readFileSync(filename, "utf-8")));
const result = fastMin(numbers, { debug: true });
eq(result, expected_min);
});
});
/// new
test("getting no minimum from normal arrays with all no data values", ({ eq }) => {
const numbers = [99, 99, 99, 99];
const result = fastMin(numbers, { no_data: 99 });
eq(result, undefined);
});
test("getting minimum from normal arrays with some data values", ({ eq }) => {
const numbers = [1, 99, 2, 99, 4, 99, 6, 99, -10];
const result = fastMin(numbers, { no_data: 99 });
eq(result, -10);
});
test("getting no minimum from typed arrays with all no data values", ({ eq }) => {
const numbers = Uint8Array.from([99, 99, 99, 99]);
const result = fastMin(numbers, { no_data: 99 });
eq(result, undefined);
});
test("getting minimum from typed arrays with some data values", ({ eq }) => {
const numbers = Int8Array.from([1, 99, 2, 99, 4, 99, 6, 99, -10]);
const result = fastMin(numbers, { no_data: 99 });
eq(result, -10);
});
test("multiple no data values", ({ eq }) => {
const numbers = Int8Array.from([1, 99, 2, 99, 4, 99, 6, 99, -10]);
const result = fastMin(numbers, { no_data: [-10, 99] });
eq(result, 1);
});
test("multiple no data values", ({ eq }) => {
const numbers = [NaN, 1, 99, 2, 99, 4, 99, 6, 99, -10, null, undefined];
const result = fastMin(numbers, { no_data: [-10, 99] });
eq(result, 1);
});