Example #1
0
func TestColorOnly(t *testing.T) {
	action := actions.Action{C: gohue.NewMaybeColor(gohue.Yellow)}
	expected := []request{
		{L: 0,
			C: gohue.NewMaybeColor(gohue.Yellow),
			D: 0}}
	verifyAction(t, expected, action)
}
Example #2
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 #3
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 #4
0
func TestGradient3(t *testing.T) {
	action := actions.Action{
		G: &actions.Gradient{
			Cds: []actions.ColorDuration{
				{Bri: maybe.NewUint8(gohue.Bright), D: 0},
				{Bri: maybe.NewUint8(gohue.Bright),
					C: gohue.NewMaybeColor(gohue.Red),
					D: 1000},
				{C: gohue.NewMaybeColor(gohue.Red), D: 2000},
				{Bri: maybe.NewUint8(gohue.Dim), D: 3000},
				{Bri: maybe.NewUint8(gohue.Dim), D: 4000}},
			Refresh: 500}}
	expected := []request{
		{L: 0, Bri: maybe.NewUint8(gohue.Bright), D: 0},
		{L: 0, Bri: maybe.NewUint8(gohue.Bright), D: 500},
		{L: 0,
			Bri: maybe.NewUint8(gohue.Bright),
			C:   gohue.NewMaybeColor(gohue.Red),
			D:   1000},
		{L: 0,
			Bri: maybe.NewUint8(gohue.Bright),
			C:   gohue.NewMaybeColor(gohue.Red),
			D:   1500},
		{L: 0, C: gohue.NewMaybeColor(gohue.Red), D: 2000},
		{L: 0, C: gohue.NewMaybeColor(gohue.Red), D: 2500},
		{L: 0, Bri: maybe.NewUint8(gohue.Dim), D: 3000},
		{L: 0, Bri: maybe.NewUint8(gohue.Dim), D: 3500},
		{L: 0, Bri: maybe.NewUint8(gohue.Dim), D: 4000}}
	verifyAction(t, expected, action)
}
Example #5
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 #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)
}
Example #7
0
func maybeBlendColor(first, second gohue.MaybeColor, ratio float64) gohue.MaybeColor {
	if first.Valid && second.Valid {
		return gohue.NewMaybeColor(first.Blend(second.Color, ratio))
	}
	return first
}