init
This commit is contained in:
14
common/colors/hex.go
Normal file
14
common/colors/hex.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package colors
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
)
|
||||
|
||||
func FromInt(in int32) color.Color {
|
||||
return color.RGBA{
|
||||
uint8(in >> 16),
|
||||
uint8(in >> 8),
|
||||
uint8(in),
|
||||
0xff,
|
||||
}
|
||||
}
|
||||
62
common/colors/hex_test.go
Normal file
62
common/colors/hex_test.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package colors
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFromInt(t *testing.T) {
|
||||
type args struct {
|
||||
in int32
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want color.Color
|
||||
}{
|
||||
{
|
||||
name: "black",
|
||||
args: args{
|
||||
in: 0x000000,
|
||||
},
|
||||
want: color.RGBA{
|
||||
0, 0, 0, 0xff,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "red",
|
||||
args: args{
|
||||
in: 0xff0000,
|
||||
},
|
||||
want: color.RGBA{
|
||||
0xff, 0, 0, 0xff,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "green",
|
||||
args: args{
|
||||
in: 0x00ff00,
|
||||
},
|
||||
want: color.RGBA{
|
||||
0, 0xff, 0, 0xff,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "blue",
|
||||
args: args{
|
||||
in: 0x0000ff,
|
||||
},
|
||||
want: color.RGBA{
|
||||
0, 0, 0xff, 0xff,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := FromInt(tt.args.in); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("FromInt() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user