2020-04-11 12:14:37 +02:00
|
|
|
package colors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
2020-11-21 18:08:41 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-04-11 12:14:37 +02:00
|
|
|
)
|
|
|
|
|
2020-04-28 14:50:39 +02:00
|
|
|
func TestLightMap_Hex(t *testing.T) {
|
|
|
|
lum := []Luminance{1, 16, 2, 4, 15, 16, 1, 0, 8}
|
|
|
|
lMap := LightMap(lum)
|
2023-02-11 20:18:04 +01:00
|
|
|
assert.Equal(t, "1F24FF108", lMap.Hex())
|
2020-04-28 14:50:39 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-11 12:14:37 +02:00
|
|
|
func TestLightMap_Diff(t *testing.T) {
|
|
|
|
t.Run("random", func(t *testing.T) {
|
|
|
|
lum := []Luminance{1, 16, 2, 4, 15, 16, 1, 0, 8}
|
|
|
|
lMap := LightMap(lum)
|
|
|
|
result := lMap.Diff()
|
|
|
|
|
|
|
|
if result != 845 {
|
|
|
|
t.Errorf("result should be 845: %d", result)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty", func(t *testing.T) {
|
|
|
|
var lum []Luminance
|
|
|
|
lMap := LightMap(lum)
|
|
|
|
result := lMap.Diff()
|
|
|
|
|
|
|
|
if result != 0 {
|
|
|
|
t.Errorf("result should be 0: %d", result)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("one", func(t *testing.T) {
|
|
|
|
lum := []Luminance{0}
|
|
|
|
lMap := LightMap(lum)
|
|
|
|
result := lMap.Diff()
|
|
|
|
|
|
|
|
if result != 0 {
|
|
|
|
t.Errorf("result should be 0: %d", result)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("same", func(t *testing.T) {
|
|
|
|
lum := []Luminance{1, 1, 1, 1, 1, 1, 1, 1, 1}
|
|
|
|
lMap := LightMap(lum)
|
|
|
|
result := lMap.Diff()
|
|
|
|
|
|
|
|
if result != 1023 {
|
|
|
|
t.Errorf("result should be 1023: %d", result)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("similar", func(t *testing.T) {
|
|
|
|
lum := []Luminance{1, 1, 1, 1, 1, 1, 1, 1, 2}
|
|
|
|
lMap := LightMap(lum)
|
|
|
|
result := lMap.Diff()
|
|
|
|
|
|
|
|
if result != 1023 {
|
|
|
|
t.Errorf("result should be 1023: %d", result)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("happy", func(t *testing.T) {
|
|
|
|
m1 := LightMap{8, 13, 7, 2, 2, 3, 6, 3, 4}
|
|
|
|
d1 := m1.Diff()
|
|
|
|
t.Log(strconv.FormatUint(uint64(d1), 2))
|
|
|
|
m2 := LightMap{8, 13, 7, 3, 1, 3, 5, 3, 4}
|
|
|
|
d2 := m2.Diff()
|
|
|
|
t.Log(strconv.FormatUint(uint64(d2), 2))
|
|
|
|
m3 := LightMap{9, 13, 7, 8, 2, 4, 5, 3, 4}
|
|
|
|
d3 := m3.Diff()
|
|
|
|
t.Log(strconv.FormatUint(uint64(d3), 2))
|
|
|
|
m4 := LightMap{9, 13, 7, 7, 2, 4, 6, 2, 3}
|
|
|
|
d4 := m4.Diff()
|
|
|
|
t.Log(strconv.FormatUint(uint64(d4), 2))
|
|
|
|
|
|
|
|
t.Logf("values: %d, %d, %d, %d", d1, d2, d3, d4)
|
|
|
|
})
|
|
|
|
}
|