Fixes
This commit is contained in:
+24
-14
@@ -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)
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user