-
Notifications
You must be signed in to change notification settings - Fork 1
/
nearestPalette.test.js
72 lines (65 loc) · 1.96 KB
/
nearestPalette.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
68
69
70
71
72
const { expect } = require("@jest/globals");
import {
nearestPalette,
nearestColor,
distanceToColor,
} from "./nearestPalette.js";
const target = "#FFFFFF";
const k = 2;
const palettes = [
["#69d2e7", "#a7dbd8", "#e0e4cc", "#f38630", "#fa6900"],
[target, "#cbe86b", "#f2e9e1", "#1c140d", "#cbe86b"],
["#fe4365", "#fc9d9a", "#f9cdad", "#c8c8a9", "#83af9b"],
];
import nearestPalettes from "./nearestPalette";
var colors = require("nice-color-palettes/1000");
test("Check max palettes", () => {
const getPalettes = nearestPalettes("#ffddff", colors, 40);
const res = getPalettes.length;
expect(res).toBe(40);
});
test("TEST Distance", () => {
const res = distanceToColor(target, "#f2e9e1");
const er = 39.408120990476064;
expect(res).toBe(er);
});
test("TEST nearest Palettes", () => {
const res = nearestPalette(target, palettes, k);
let er = [
{
distance: 0,
palette: ["#FFFFFF", "#cbe86b", "#f2e9e1", "#1c140d", "#cbe86b"],
},
{
distance: 65.50572494064927,
palette: ["#69d2e7", "#a7dbd8", "#e0e4cc", "#f38630", "#fa6900"],
},
];
expect(res).toEqual(expect.arrayContaining(er));
});
test("TEST Nearest Colors", () => {
let res = nearestColor(target, palettes, k);
let er = [
{
distance: 65.50572494064927,
colors: [
{ color: "#e0e4cc", distance: 65.50572494064927 },
{ color: "#a7dbd8", distance: 102.76672613253767 },
{ color: "#69d2e7", distance: 158.43295111813072 },
{ color: "#f38630", distance: 240.0708228835816 },
{ color: "#fa6900", distance: 295.8884925102698 },
],
},
{
distance: 0,
colors: [
{ color: "#FFFFFF", distance: 0 },
{ color: "#f2e9e1", distance: 39.408120990476064 },
{ color: "#cbe86b", distance: 158.54652314068574 },
{ color: "#cbe86b", distance: 158.54652314068574 },
{ color: "#1c140d", distance: 406.59316275608967 },
],
},
];
expect(res).toEqual(er);
});