Monorepo for Aesthetic.Computer
aesthetic.computer
1import assert from 'node:assert/strict';
2
3// Minimal test for invert function logic
4// Testing the CPU implementation directly
5
6// Test 1: Basic RGB inversion formula
7{
8 const testCases = [
9 { input: [255, 0, 0, 255], expected: [0, 255, 255, 255], name: 'Red' },
10 { input: [0, 255, 0, 255], expected: [255, 0, 255, 255], name: 'Green' },
11 { input: [0, 0, 255, 255], expected: [255, 255, 0, 255], name: 'Blue' },
12 { input: [128, 128, 128, 255], expected: [127, 127, 127, 255], name: 'Gray' },
13 { input: [0, 0, 0, 255], expected: [255, 255, 255, 255], name: 'Black' },
14 { input: [255, 255, 255, 255], expected: [0, 0, 0, 255], name: 'White' },
15 ];
16
17 for (const { input, expected, name } of testCases) {
18 const result = [
19 255 - input[0],
20 255 - input[1],
21 255 - input[2],
22 input[3] // Alpha preserved
23 ];
24
25 assert.deepEqual(result, expected, `${name} inversion formula`);
26 }
27
28 console.log('✅ Basic RGB inversion formula tests passed');
29}
30
31// Test 2: Alpha preservation
32{
33 const testCases = [
34 { alpha: 255, name: 'Opaque' },
35 { alpha: 128, name: 'Semi-transparent' },
36 { alpha: 0, name: 'Fully transparent' },
37 { alpha: 64, name: '25% opacity' },
38 ];
39
40 for (const { alpha, name } of testCases) {
41 const input = [100, 150, 200, alpha];
42 const result = [
43 255 - input[0],
44 255 - input[1],
45 255 - input[2],
46 input[3]
47 ];
48
49 assert.equal(result[3], alpha, `${name}: Alpha should be preserved`);
50 assert.equal(result[0], 155, `${name}: R channel inverted correctly`);
51 assert.equal(result[1], 105, `${name}: G channel inverted correctly`);
52 assert.equal(result[2], 55, `${name}: B channel inverted correctly`);
53 }
54
55 console.log('✅ Alpha preservation tests passed');
56}
57
58// Test 3: Double invert should restore original
59{
60 const testPixels = [
61 [123, 45, 67, 255],
62 [0, 128, 255, 128],
63 [50, 100, 150, 200],
64 ];
65
66 for (const original of testPixels) {
67 // First invert
68 const inverted = [
69 255 - original[0],
70 255 - original[1],
71 255 - original[2],
72 original[3]
73 ];
74
75 // Second invert
76 const restored = [
77 255 - inverted[0],
78 255 - inverted[1],
79 255 - inverted[2],
80 inverted[3]
81 ];
82
83 assert.deepEqual(restored, original, `Double invert restores [${original.join(', ')}]`);
84 }
85
86 console.log('✅ Double invert restoration tests passed');
87}
88
89// Test 4: Boundary values
90{
91 const boundaryTests = [
92 { input: [0, 0, 0, 255], expected: [255, 255, 255, 255], name: 'Min values' },
93 { input: [255, 255, 255, 255], expected: [0, 0, 0, 255], name: 'Max values' },
94 { input: [1, 254, 127, 255], expected: [254, 1, 128, 255], name: 'Mixed values' },
95 ];
96
97 for (const { input, expected, name } of boundaryTests) {
98 const result = [
99 255 - input[0],
100 255 - input[1],
101 255 - input[2],
102 input[3]
103 ];
104
105 assert.deepEqual(result, expected, name);
106 }
107
108 console.log('✅ Boundary value tests passed');
109}
110
111console.log('✅ All invert logic tests passed');
112