package game

import "testing"

func TestCompareDictVersions(t *testing.T) {
	cases := []struct {
		a, b string
		want int
	}{
		{"v1.3.0", "v1.3.1", -1},
		{"v1.3.1", "v1.3.0", 1},
		{"v1.3.1", "v1.3.1", 0},
		{"v1.3.9", "v1.3.10", -1}, // numeric, not lexical
		{"v1.10.0", "v1.9.0", 1},
		{"v2.0.0", "v1.9.9", 1},
		{"1.3.1", "v1.3.1", 0}, // the leading v is optional
		// Non-semver falls back to a byte comparison, keeping the ordering total.
		{"weird", "weird", 0},
		{"a", "b", -1},
	}
	for _, c := range cases {
		if got := compareDictVersions(c.a, c.b); sign(got) != c.want {
			t.Errorf("compareDictVersions(%q, %q) = %d, want sign %d", c.a, c.b, got, c.want)
		}
	}
}

func sign(n int) int {
	switch {
	case n < 0:
		return -1
	case n > 0:
		return 1
	default:
		return 0
	}
}
