Example #1
0
func TestOnColor(t *testing.T) {
	action := actions.Action{
		On: true, C: gohue.NewMaybeColor(gohue.NewColor(0.4, 0.2))}
	expected := []request{
		{L: 0,
			C:  gohue.NewMaybeColor(gohue.NewColor(0.4, 0.2)),
			On: maybe.NewBool(true),
			D:  0}}
	verifyAction(t, expected, action)
}
Example #2
0
func TestGradient2(t *testing.T) {
	action := actions.Action{
		G: &actions.Gradient{
			Cds: []actions.ColorDuration{
				{C: gohue.NewMaybeColor(gohue.NewColor(0.2, 0.1)), D: 0},
				{C: gohue.NewMaybeColor(gohue.NewColor(0.3, 0.3)), D: 1000}},
			Refresh: 600}}
	expected := []request{
		{L: 0, C: gohue.NewMaybeColor(gohue.NewColor(0.2, 0.1)), D: 0},
		{L: 0, C: gohue.NewMaybeColor(gohue.NewColor(0.26, 0.22)), D: 600},
		{L: 0, C: gohue.NewMaybeColor(gohue.NewColor(0.3, 0.3)), D: 1200}}
	verifyAction(t, expected, action)
}
Example #3
0
func TestColorBlend(t *testing.T) {
	c1 := gohue.NewColor(0.3, 0.2)
	c2 := gohue.NewColor(0.2, 0.6)
	expected := gohue.NewColor(0.23, 0.48)
	if actual := c1.Blend(c2, 0.7); actual != expected {
		t.Errorf("Expected %s, got %s", expected, actual)
	}
	expected = gohue.NewColor(0.2, 0.6)
	if actual := c1.Blend(c2, 1.0); actual != expected {
		t.Errorf("Expected %s, got %s", expected, actual)
	}
	expected = gohue.NewColor(0.3, 0.2)
	if actual := c1.Blend(c2, 0.0); actual != expected {
		t.Errorf("Expected %s, got %s", expected, actual)
	}
}
Example #4
0
func TestMaybeColor(t *testing.T) {
	var m, c gohue.MaybeColor
	v := gohue.NewColor(0.4, 0.6)
	m.Set(v)
	if m != gohue.NewMaybeColor(v) {
		t.Error("MaybeColor Set broken.")
	}
	verifyString(t, "Just (0.4000, 0.6000)", m.String())
	m.Clear()
	if m != c {
		t.Error("MaybeColor Clear broken.")
	}
	verifyString(t, "Nothing", m.String())
}
Example #5
0
func TestColorXY(t *testing.T) {
	c := gohue.NewColor(0.0, 1.0)
	if c != gohue.NewColor(c.X(), c.Y()) {
		t.Error("Round trip of X and Y failed.")
	}
	c = gohue.NewColor(1.0, 0.0)
	if c != gohue.NewColor(c.X(), c.Y()) {
		t.Error("Round trip of X and Y failed.")
	}
	c = gohue.NewColor(7.0, 0.2)
	if c != gohue.NewColor(c.X(), c.Y()) {
		t.Error("Round trip of X and Y failed.")
	}
}
Example #6
0
func TestGradient(t *testing.T) {
	action := actions.Action{
		Lights: []int{2},
		G: &actions.Gradient{
			Cds: []actions.ColorDuration{
				{C: gohue.NewMaybeColor(gohue.NewColor(0.2, 0.1)),
					Bri: maybe.NewUint8(0), D: 0},
				{C: gohue.NewMaybeColor(gohue.NewColor(0.3, 0.3)),
					Bri: maybe.NewUint8(30), D: 1000},
				{C: gohue.NewMaybeColor(gohue.NewColor(0.9, 0.9)),
					Bri: maybe.NewUint8(100), D: 1000},
				{C: gohue.NewMaybeColor(gohue.NewColor(0.8, 0.7)),
					Bri: maybe.NewUint8(100), D: 1000},
				{C: gohue.NewMaybeColor(gohue.NewColor(0.2, 0.4)),
					Bri: maybe.NewUint8(10), D: 1750},
				{C: gohue.NewMaybeColor(gohue.NewColor(0.29, 0.46)),
					Bri: maybe.NewUint8(22), D: 2500}},
			Refresh: 500},
		On: true}
	expected := []request{
		{L: 2,
			C:   gohue.NewMaybeColor(gohue.NewColor(0.2, 0.1)),
			Bri: maybe.NewUint8(0),
			On:  maybe.NewBool(true),
			D:   0},
		{L: 2,
			C:   gohue.NewMaybeColor(gohue.NewColor(0.25, 0.2)),
			Bri: maybe.NewUint8(15),
			D:   500},
		{L: 2,
			C:   gohue.NewMaybeColor(gohue.NewColor(0.8, 0.7)),
			Bri: maybe.NewUint8(100),
			D:   1000},
		{L: 2,
			C:   gohue.NewMaybeColor(gohue.NewColor(0.4, 0.5)),
			Bri: maybe.NewUint8(40),
			D:   1500},
		{L: 2,
			C:   gohue.NewMaybeColor(gohue.NewColor(0.23, 0.42)),
			Bri: maybe.NewUint8(14),
			D:   2000},
		{L: 2,
			C:   gohue.NewMaybeColor(gohue.NewColor(0.29, 0.46)),
			Bri: maybe.NewUint8(22),
			D:   2500}}
	verifyAction(t, expected, action)
}