-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support create Rgb color from Hsl value, issue#40
- Loading branch information
Showing
7 changed files
with
226 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package color | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRgb2basic(t *testing.T) { | ||
assert.Equal(t, uint8(31), Rgb2basic(134, 56, 56, false)) | ||
assert.Equal(t, uint8(41), Rgb2basic(134, 56, 56, true)) | ||
assert.Equal(t, uint8(46), Rgb2basic(57, 187, 226, true)) | ||
} | ||
|
||
func TestHslToRgb(t *testing.T) { | ||
// red #ff0000 255,0,0 0,100%,50% | ||
rgbVal := HslToRgb(0, 1, 0.5) | ||
// fmt.Println(rgbVal) | ||
assert.Equal(t, []uint8{255, 0, 0}, rgbVal) | ||
|
||
rgbVal = HslIntToRgb(0, 100, 50) | ||
// fmt.Println(rgbVal) | ||
assert.Equal(t, []uint8{255, 0, 0}, rgbVal) | ||
|
||
rgbVal = HslIntToRgb(0, 100, 25) | ||
// fmt.Println(rgbVal) | ||
assert.Equal(t, []uint8{128, 0, 0}, rgbVal) | ||
|
||
// darkgray #a9a9a9 169,169,169 0,0%,66% | ||
rgbVal = HslIntToRgb(0, 0, 66) | ||
fmt.Println(rgbVal) | ||
assert.Equal(t, []uint8{168, 168, 168}, rgbVal) | ||
|
||
rgbVal = HslToRgb(0, 0, 0.6627) | ||
fmt.Println(rgbVal) | ||
assert.Equal(t, []uint8{169, 169, 169}, rgbVal) | ||
|
||
hslVal := RgbToHslInt(rgbVal[0], rgbVal[1], rgbVal[2]) | ||
fmt.Println(hslVal) | ||
assert.Equal(t, []int{0, 0, 66}, hslVal) | ||
|
||
hslFVal := RgbToHsl(rgbVal[0], rgbVal[1], rgbVal[2]) | ||
fmt.Println(hslFVal) | ||
} |
Oops, something went wrong.