From 96e1357ca6b5ceb4ac2155271fd1645564f25c36 Mon Sep 17 00:00:00 2001 From: Lloyd Kupchanko Date: Mon, 11 Mar 2024 22:05:48 -0600 Subject: [PATCH 1/2] Port color modification tests Closes #395 --- test/modifications.js | 100 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 test/modifications.js diff --git a/test/modifications.js b/test/modifications.js new file mode 100644 index 000000000..e183bcd17 --- /dev/null +++ b/test/modifications.js @@ -0,0 +1,100 @@ +import Color from "../src/index.js"; +import { check } from "./util.mjs"; + +export default { + name: "Color modification tests", + description: "These tests modify one or more coordinates and check the result.", + run (func) { + return func(); + }, + check: check.deep(check.proximity({epsilon: .005})), + tests: [ + { + name: "sRGB to LCH", + tests: [ + { + name: "color.lch.c = 13", + args: () => { + var color = new Color("slategray"); + color.lch.c = 13; + return color.lch.c; + }, + expect: 13, + }, + { + name: "color.set('lch.c', 13)", + args: () => { + var color = new Color("slategray"); + color.set("lch.c", 13); + return color.get("lch.c"); + }, + expect: 13, + }, + { + name: "color.lch[1] = 13", + args: () => { + var color = new Color("slategray"); + color.lch[1] = 13; + return color.lch.c; + }, + expect: 13, + }, + { + name: "color.set('c', 13)", + args: () => { + var color = new Color("slategray").to("lch"); + color.set("c", 13); + return color.lch.c; + }, + expect: 13, + }, + { + name: "color.set({'lch.c': 13, 'lch.l': 40})", + args: () => { + var color = new Color("slategray"); + color.set({"lch.c": 13, "lch.l": 40}); + return [color.lch.c, color.lch.l]; + }, + expect: [13, 40], + }, + { + name: "color.set('lch.c', 13)", + args: () => { + var color = new Color("slategray"); + color.set("lch.c", 13); + return color.lch.c; + }, + expect: 13, + }, + { + name: "chroma *= 1.2", + args: () => { + var color = new Color("slategray"); + color.lch.c *= 1.2; + return color.lch.c; + }, + expect: 13.480970445148008, + }, + { + name: "color.set('c', c => c * 1.2)", + args: () => { + var color = new Color("slategray").to("lch"); + color.set("c", c => c * 1.2); + return color.lch.c; + }, + expect: 13.480970445148008, + }, + { + name: "c *= 1.25", + args: () => { + var color = new Color("slategray").to("lch"); + color.lch.c *= 1.25; + var lch = color.lch; + return [lch[0], lch[1], lch[2]]; + }, + expect: [52.69726799102946, 14.04267594002497, 253.0004426214531], + }, + ], + }, + ], +}; From b64fd6890878da51fbea3d2855dcafc2ae5cb7ef Mon Sep 17 00:00:00 2001 From: Lloyd Kupchanko Date: Tue, 12 Mar 2024 11:59:24 -0600 Subject: [PATCH 2/2] Use run instead of args --- test/modifications.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/test/modifications.js b/test/modifications.js index e183bcd17..267a1f4e4 100644 --- a/test/modifications.js +++ b/test/modifications.js @@ -4,9 +4,6 @@ import { check } from "./util.mjs"; export default { name: "Color modification tests", description: "These tests modify one or more coordinates and check the result.", - run (func) { - return func(); - }, check: check.deep(check.proximity({epsilon: .005})), tests: [ { @@ -14,7 +11,7 @@ export default { tests: [ { name: "color.lch.c = 13", - args: () => { + run: () => { var color = new Color("slategray"); color.lch.c = 13; return color.lch.c; @@ -23,7 +20,7 @@ export default { }, { name: "color.set('lch.c', 13)", - args: () => { + run: () => { var color = new Color("slategray"); color.set("lch.c", 13); return color.get("lch.c"); @@ -32,7 +29,7 @@ export default { }, { name: "color.lch[1] = 13", - args: () => { + run: () => { var color = new Color("slategray"); color.lch[1] = 13; return color.lch.c; @@ -41,7 +38,7 @@ export default { }, { name: "color.set('c', 13)", - args: () => { + run: () => { var color = new Color("slategray").to("lch"); color.set("c", 13); return color.lch.c; @@ -50,7 +47,7 @@ export default { }, { name: "color.set({'lch.c': 13, 'lch.l': 40})", - args: () => { + run: () => { var color = new Color("slategray"); color.set({"lch.c": 13, "lch.l": 40}); return [color.lch.c, color.lch.l]; @@ -59,7 +56,7 @@ export default { }, { name: "color.set('lch.c', 13)", - args: () => { + run: () => { var color = new Color("slategray"); color.set("lch.c", 13); return color.lch.c; @@ -68,7 +65,7 @@ export default { }, { name: "chroma *= 1.2", - args: () => { + run: () => { var color = new Color("slategray"); color.lch.c *= 1.2; return color.lch.c; @@ -77,7 +74,7 @@ export default { }, { name: "color.set('c', c => c * 1.2)", - args: () => { + run: () => { var color = new Color("slategray").to("lch"); color.set("c", c => c * 1.2); return color.lch.c; @@ -86,7 +83,7 @@ export default { }, { name: "c *= 1.25", - args: () => { + run: () => { var color = new Color("slategray").to("lch"); color.lch.c *= 1.25; var lch = color.lch;