Files
JavaScript/Conversions/test/RgbHslConversion.test.js
Piyush Katyal ce86248b1e feat: add RGB to HSL color format conversion algorithm (#1475)
* feat: add RGB to HSL color format conversion algorithm

* test: add self-tests for rgb to hsl conversion algorithm

* fix: change function code to concise format

* fix: use throw and segregate the test cases

* chore: clean up the test format

* chore: use correct styling
2023-10-11 06:15:47 +00:00

44 lines
905 B
JavaScript

import { rgbToHsl } from '../RgbHslConversion'
describe('RgbHslConversion', () => {
test.each([
[
[215, 19, 180],
[311, 84, 46]
],
[
[21, 190, 18],
[119, 83, 41]
],
[
[80, 100, 160],
[225, 33, 47]
],
[
[80, 1, 16],
[349, 98, 16]
],
[
[8, 20, 0],
[96, 100, 4]
],
[
[0, 0, 0],
[0, 0, 0]
],
[
[255, 255, 255],
[0, 0, 100]
]
])('Should return the color in HSL format.', (colorRgb, expected) => {
expect(rgbToHsl(colorRgb)).toEqual(expected)
})
test.each([
[[256, 180, 9], 'Input is not a valid RGB color.'],
[[-90, 46, 8], 'Input is not a valid RGB color.'],
[[1, 39, 900], 'Input is not a valid RGB color.']
])('Should return the error message.', (colorRgb, expected) => {
expect(() => rgbToHsl(colorRgb)).toThrowError(expected)
})
})