You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

package m9zApi
import "testing"
func TestAutomaticModeDemoStoreReturnsCopies(t *testing.T) {
store := newAutomaticModeDemoStore()
start := store.getStartTask(0)
if len(start.Loops) == 0 {
t.Fatal("demo start task should include loops")
}
start.Loops[0].TurnOn = !start.Loops[0].TurnOn
start.Loops[0].Pwm = 1
got := store.getStartTask(0)
if got.Loops[0].Pwm == 1 {
t.Fatal("demo start task loop was mutated through returned value")
}
middle := store.getMiddleTask(0)
if len(middle.ControlTaskList) == 0 || len(middle.ControlTaskList[0].Loops) == 0 {
t.Fatal("demo middle task should include control tasks and loops")
}
middle.ControlTaskList[0].Loops[0].Pwm = 1
gotMiddle := store.getMiddleTask(0)
if gotMiddle.ControlTaskList[0].Loops[0].Pwm == 1 {
t.Fatal("demo middle task loop was mutated through returned value")
}
}
func TestNormalizeAutomaticMode(t *testing.T) {
if got := normalizeAutomaticMode(2); got != 2 {
t.Fatalf("normalizeAutomaticMode(2) = %d, want 2", got)
}
if got := normalizeAutomaticMode(3); got != 0 {
t.Fatalf("normalizeAutomaticMode(3) = %d, want 0", got)
}
}