-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfixture.ts
More file actions
57 lines (47 loc) · 1.48 KB
/
Copy pathfixture.ts
File metadata and controls
57 lines (47 loc) · 1.48 KB
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
export function now(): number {
return performance.now();
}
export function expectContents(actual: any, exp: any) {
const size = exp.byteLength;
if (actual.byteLength !== size) {
return 'size mismatch';
}
const lines = [];
let failedPixels = 0;
for (let i = 0; i < size; ++i) {
if (actual[i] !== exp[i]) {
if (failedPixels > 4) {
lines.push('... and more');
break;
}
failedPixels++;
lines.push(`at [${i}], expected ${exp[i]}, got ${actual[i]}`);
}
} // TODO: Could make a more convenient message, which could look like e.g.:
//
// Starting at offset 48,
// got 22222222 ABCDABCD 99999999
// but expected 22222222 55555555 99999999
//
// or
//
// Starting at offset 0,
// got 00000000 00000000 00000000 00000000 (... more)
// but expected 00FF00FF 00FF00FF 00FF00FF 00FF00FF (... more)
//
// Or, maybe these diffs aren't actually very useful (given we have the prints
// just above here), and we should remove them. More important will be logging
// of texture data in a visual format.
if (size <= 256 && failedPixels > 0) {
const expHex =
Array.from(exp).map(x => x.toString().padStart(2, '0')).join('');
const actHex =
Array.from(actual).map(x => x.toString().padStart(2, '0')).join('');
lines.push('EXPECT: ' + expHex);
lines.push('ACTUAL: ' + actHex);
}
if (failedPixels) {
return lines.join('\n');
}
return undefined;
}