summaryrefslogtreecommitdiff
path: root/lib_test.go
blob: 3a4dc2c309dcb4f2a8a89c4c6145499a7dcc9f44 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package excelize

import "testing"

func TestAxisLowerOrEqualThan(t *testing.T) {
	trueExpectedInputList := [][2]string{
		[2]string{"A", "B"},
		[2]string{"A", "AA"},
		[2]string{"B", "AA"},
		[2]string{"BC", "ABCD"},
		[2]string{"1", "2"},
		[2]string{"2", "11"},
	}

	for _, trueExpectedInput := range trueExpectedInputList {
		isLowerOrEqual := axisLowerOrEqualThan(trueExpectedInput[0], trueExpectedInput[1])
		if !isLowerOrEqual {
			t.Fatalf("Expected %v <= %v = true, got false\n", trueExpectedInput[0], trueExpectedInput[1])
		}
	}

	falseExpectedInputList := [][2]string{
		[2]string{"B", "A"},
		[2]string{"AA", "A"},
		[2]string{"AA", "B"},
		[2]string{"ABCD", "AB"},
		[2]string{"2", "1"},
		[2]string{"11", "2"},
	}

	for _, falseExpectedInput := range falseExpectedInputList {
		isLowerOrEqual := axisLowerOrEqualThan(falseExpectedInput[0], falseExpectedInput[1])
		if isLowerOrEqual {
			t.Fatalf("Expected %v <= %v = false, got true\n", falseExpectedInput[0], falseExpectedInput[1])
		}
	}
}

func TestGetCellColRow(t *testing.T) {
	cellExpectedColRowList := map[string][2]string{
		"C220":    [2]string{"C", "220"},
		"aaef42":  [2]string{"aaef", "42"},
		"bonjour": [2]string{"bonjour", ""},
		"59":      [2]string{"", "59"},
		"":        [2]string{"", ""},
	}

	for cell, expectedColRow := range cellExpectedColRowList {
		col, row := getCellColRow(cell)

		if col != expectedColRow[0] {
			t.Fatalf("Expected cell %v to return col %v, got col %v\n", cell, expectedColRow[0], col)
		}

		if row != expectedColRow[1] {
			t.Fatalf("Expected cell %v to return row %v, got row %v\n", cell, expectedColRow[1], row)
		}
	}
}