Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port color modification tests #480

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions test/modifications.js
Original file line number Diff line number Diff line change
@@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is never needed, you can just have a run on each individual test. :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, that's way better.

},
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],
},
],
},
],
};