mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
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
This commit is contained in:
43
Conversions/test/RgbHslConversion.test.js
Normal file
43
Conversions/test/RgbHslConversion.test.js
Normal file
@@ -0,0 +1,43 @@
|
||||
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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user