-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_color_test.ts
60 lines (51 loc) · 1.61 KB
/
random_color_test.ts
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
// Copyright 2023 mineejo. All rights reserved. MIT license.
import { randomColor } from "./random_color.ts";
import { assertEquals } from "./dev_deps.ts";
import { Rgb } from "./deps.ts";
export function truncComponents(components: Rgb): Rgb {
return components.map((component: number) => Math.trunc(component)) as Rgb;
}
Deno.test("random color function correct", () => {
const startRed: Rgb = randomColor({
hue: [0, 0],
saturation: [100, 100],
lightness: [50, 50],
});
assertEquals(truncComponents(startRed), [255, 0, 0], `"startRed"`);
const green: Rgb = randomColor({
hue: [33.33, 33.33],
saturation: [100, 100],
lightness: [50, 50],
});
assertEquals(truncComponents(green), [0, 255, 0], `"green"`);
const blue: Rgb = randomColor({
hue: [66.66, 66.66],
saturation: [100, 100],
lightness: [50, 50],
});
assertEquals(truncComponents(blue), [0, 0, 255], `"blue"`);
const endRed: Rgb = randomColor({
hue: [100, 100],
saturation: [100, 100],
lightness: [50, 50],
});
assertEquals(truncComponents(endRed), [255, 0, 0], `"endRed"`);
const grey: Rgb = randomColor({
hue: [100, 100],
saturation: [0, 0],
lightness: [50, 50],
});
assertEquals(truncComponents(grey), [64, 64, 64], `"grey"`);
const black: Rgb = randomColor({
hue: [100, 100],
saturation: [100, 100],
lightness: [0, 0],
});
assertEquals(truncComponents(black), [0, 0, 0], `"black"`);
const white: Rgb = randomColor({
hue: [100, 100],
saturation: [100, 100],
lightness: [100, 100],
});
assertEquals(truncComponents(white), [255, 255, 255], `"white"`);
});