-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
113 lines (111 loc) · 3.7 KB
/
test.js
File metadata and controls
113 lines (111 loc) · 3.7 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const { renderHypercube } = require('../build/ascii-hypercube.js');
const tests = [
// Edge case: zero-cube
{
dimensions: [],
expectedText: ``,
},
// Cube (3D)
{
dimensions: [
{length: 4, xPerGlyph: 2, yPerGlyph: 0, text: "CUBIC"},
{length: 4, xPerGlyph: 0, yPerGlyph: 1, text: "CUBIC"},
{length: 2, xPerGlyph: 2, yPerGlyph: 1, text: "\\"},
],
expectedText: `C U B I C
U \\ U \\
B C U B I C
I U I U
C U B I C B
\\ I \\ I
C U B I C`,
},
// Cube (3D) with extra dimensions of length 0
{
dimensions: [
{length: 4, xPerGlyph: 2, yPerGlyph: 0, text: "CUBIC"},
{length: 4, xPerGlyph: 0, yPerGlyph: 1, text: "CUBIC"},
{length: 2, xPerGlyph: 2, yPerGlyph: 1, text: "\\"},
{length: 0, xPerGlyph: 3, yPerGlyph: 1, text: "~"},
{length: 0, xPerGlyph: -1, yPerGlyph: 1, text: "/"},
],
expectedText: `C U B I C
U \\ U \\
B C U B I C
I U I U
C U B I C B
\\ I \\ I
C U B I C`,
},
// Tesseract (4D)
{
dimensions: [
{length: 4, xPerGlyph: 2, yPerGlyph: 0, text: "CUBIC"},
{length: 4, xPerGlyph: 0, yPerGlyph: 1, text: "CUBIC"},
{length: 2, xPerGlyph: 2, yPerGlyph: 1, text: "\\"},
{length: 3, xPerGlyph: -1, yPerGlyph: 1, text: "/"},
],
expectedText: ` C U B I C
/U \\ /U \\
/ B C U B I C
C UIB IUC I /U
U \\C U BUI\\C / B
B / C\\UIB I C\\ I
I/ U CIU BUI C
C U B I C B /
\\ I/ \\ I/
C U B I C`,
},
// 5-cube (5D)
{
dimensions: [
{length: 11, xPerGlyph: 2, yPerGlyph: 0, text: "RATHER HYPER"},
{length: 11, xPerGlyph: 0, yPerGlyph: 1, text: "RATHER HYPER"},
{length: 4, xPerGlyph: 1, yPerGlyph: 1, text: "\\"},
{length: 8, xPerGlyph: 3, yPerGlyph: 1, text: "~"},
{length: 3, xPerGlyph: -1, yPerGlyph: 1, text: "/"},
],
expectedText: ` R A T H E R H Y P E R
/A\\ ~ /A\\ ~
/ T \\ ~ / T \\ ~
R AHT H E R H Y P E R H \\ ~
A\\ ~ R A T H E R HA\\ ~ E R ~
T \\R ~A ~ ~ T \\R ~A ~ ~
H \\ / T ~ ~ ~H \\ / T ~ ~ ~
E HR AHT H E R H Y P EHR H ~ ~ ~
R YA ~ ~ ~ R YAR ~ T H E ~ H Y P E R
PT R ~ ~ PTA\\R ~ ~ ~ /A\\
H EH ~ ~H EHT \\ ~ ~ ~ T \\
Y REA H H E R ~H Y PYERRAHTHH E R H Y P E R H~ \\
P / R ~Y ~ P A\\RE~Y R A T H E ~ HA\\ P E R
E/ \\ P ~ E/T \\R P/A ~ T \\R /A
R A H HEE R H Y P E R H~H\\\\E T ~ H~ \\ / T
\\ ~Y R A T H E R H \\E~YHRRAHT H E~R H Y P EHR H
\\ P ~ ~ ~ R PYA E~ ~ R YA E
\\E/ ~ ~ ~ \\EPT ~ ~ ~ PT R
R A T H E R H Y P H REH ~ ~ H EH
~ ~ ~ Y RE~ H H E ~ H Y PYE RE H
~ ~ ~ P / R Y~ ~ ~ P / R Y
~ ~ E~ \\ P ~ ~ E~ \\ P
~ R A H HEE R H Y P E R H \\E
~ \\ Y R A T H E ~ H \\ PYE R
~ \\ P / ~ \\ P /
~ \\E/ ~ \\E/
R A T H E R H Y P E R`,
},
];
let failed = false;
tests.forEach(({ dimensions, expectedText }, i) => {
const actual = renderHypercube(dimensions);
if (actual.text !== expectedText) {
console.error(`Test ${i} failed: expected\n${expectedText}\nbut got\n${actual.text}\n`);
// Comparing text with whitespace from the terminal can be hard. Hex is an option, although it's not great since it's super abstract.
// console.error(`Test ${i} failed: expected\n${new Buffer(expectedText).toString('hex')}\nbut got\n${new Buffer(actual.text).toString('hex')}`);
failed = true;
}
});
if (failed) {
process.exit(1);
} else {
console.log('All tests passed');
}