This commit is contained in:
Lani Aung
2025-06-07 16:45:53 -07:00
parent aa58a30b6d
commit 660dd859d1
4 changed files with 63 additions and 25 deletions
+24 -14
View File
@@ -2,20 +2,30 @@ import HSL from "../src/hsl"
import RGB from "../src/rgb"
describe("HSL", () => {
it("should match provided base RBG values", () => {
const red = HSL.fromRgb(new RGB(255, 0, 0))
expect(red.hue).toEqual(0)
expect(red.lightness).toEqual(.5)
expect(red.saturation).toEqual(1)
const names = ["red", "green", "blue", "F0C80E", "7E7EB8"]
const green = HSL.fromRgb(new RGB(0, 255, 0))
expect(green.hue).toEqual(120)
expect(green.lightness).toEqual(.5)
expect(green.saturation).toEqual(1)
const values = [
new RGB(255, 0, 0),
new RGB(0, 255, 0),
new RGB(0, 0, 255),
new RGB(240, 200, 14),
new RGB(126, 126, 184)
]
const blue = HSL.fromRgb(new RGB(0, 0, 255))
expect(blue.hue).toEqual(240)
expect(blue.lightness).toEqual(.5)
expect(blue.saturation).toEqual(1)
})
const expected = [
new HSL(0, 1, .5),
new HSL(120, 1, .5),
new HSL(240, 1, .5),
new HSL(49, .89, .5),
new HSL(240, .29, .61)
]
for (let index = 0; index < names.length; index++) {
it(`should match provided value: ${names[index]}`, () => {
const value = HSL.fromRgb(values[index])
expect(value.hue).toBeCloseTo(expected[index].hue, .1)
expect(value.lightness).toBeCloseTo(expected[index].lightness, .01)
expect(value.saturation).toBeCloseTo(expected[index].saturation, .01)
})
}
})