package main

import "testing"

// The relay count is decided in Go and mirrored in the panel. When the HTTP
// board was added to one and not the other, an operator could pick 8 channels
// and still get 4 rows — the selector "did nothing".
//
// This pins the Go side, which is the one the driver is built from.
func TestDeviceRelayCountHonoursTheChosenChannels(t *testing.T) {
	for _, typ := range []string{"httpgen", "usbrelay", "denkovi", "dingtian"} {
		for _, n := range []int{1, 2, 4, 8, 16} {
			if got := deviceRelayCount(StationDevice{Type: typ, Channels: n}); got != n {
				t.Errorf("%s with %d channels → %d", typ, n, got)
			}
		}
	}
	// Fixed-size boards ignore it: their hardware decides.
	for typ, want := range map[string]int{"webswitch": 5, "kmtronic": 8} {
		if got := deviceRelayCount(StationDevice{Type: typ, Channels: 3}); got != want {
			t.Errorf("%s → %d, want its fixed %d", typ, got, want)
		}
	}
	// Unset falls back to something sensible per type, not to another's default.
	for typ, want := range map[string]int{"httpgen": 4, "dingtian": 2, "usbrelay": 8, "denkovi": 8} {
		if got := deviceRelayCount(StationDevice{Type: typ}); got != want {
			t.Errorf("%s with no choice → %d, want %d", typ, got, want)
		}
	}
}
