| 1 | package calc |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestColLabel(t *testing.T) { |
| 6 | for _, tc := range []struct { |
| 7 | pos int |
| 8 | want string |
| 9 | }{ |
| 10 | {0, "A"}, {1, "B"}, {25, "Z"}, |
| 11 | {26, "AA"}, {27, "AB"}, {51, "AZ"}, |
| 12 | {52, "BA"}, {701, "ZZ"}, {702, "AAA"}, |
| 13 | } { |
| 14 | if got := ColLabel(tc.pos); got != tc.want { |
| 15 | t.Errorf("ColLabel(%d) = %q, want %q", tc.pos, got, tc.want) |
| 16 | } |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | func TestParseColLabelRoundTrip(t *testing.T) { |
| 21 | for pos := 0; pos < 3000; pos++ { |
| 22 | got, err := ParseColLabel(ColLabel(pos)) |
| 23 | if err != nil { |
| 24 | t.Fatalf("pos %d: %v", pos, err) |
| 25 | } |
| 26 | if got != pos { |
| 27 | t.Fatalf("round trip %d -> %q -> %d", pos, ColLabel(pos), got) |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func TestA1(t *testing.T) { |
| 33 | if got := A1(0, 0); got != "A1" { |
| 34 | t.Errorf("A1(0,0) = %q, want A1", got) |
| 35 | } |
| 36 | if got := A1(6, 1); got != "B7" { |
| 37 | t.Errorf("A1(6,1) = %q, want B7", got) |
| 38 | } |
| 39 | } |
| 40 | |