From 7943430749a22e6f26aa16ca2c48e97e9277998f Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Wed, 4 May 2016 15:54:19 -0400 Subject: Initial commit --- utils_test.go | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 utils_test.go (limited to 'utils_test.go') diff --git a/utils_test.go b/utils_test.go new file mode 100644 index 0000000..c42ecef --- /dev/null +++ b/utils_test.go @@ -0,0 +1,74 @@ +package main + +import "testing" + +func TestLog(t *testing.T) { + tests := []struct { + input int64 + expected int64 + }{ + {1, 0}, + {2, 1}, + {0, 0}, + {3, 1}, + {4, 2}, + } + for _, test := range tests { + actual := Log(test.input) + if test.expected != actual { + t.Errorf("%d, expected: %d, actual: %d", test.input, test.expected, + actual) + } + } +} + +func TestPow(t *testing.T) { + tests := []struct { + x int64 + n int64 + expected int64 + }{ + {1, 0, 1}, + {2, 0, 1}, + {0, 0, 1}, + {0, 2, 0}, + {1, 1, 1}, + {1, 2, 1}, + {2, 1, 2}, + {2, 2, 4}, + {2, 3, 8}, + {3, 2, 9}, + {6, 7, 279936}, + } + for _, test := range tests { + actual := Pow(test.x, test.n) + if test.expected != actual { + t.Errorf("%d**%d, expected: %d, actual: %d", test.x, test.n, + test.expected, actual) + } + } + +} + +func TestPost(t *testing.T) { + tests := []struct { + size int64 + height int64 + id int64 + expected int64 + }{ + {14, 4, 7, 0}, + {14, 4, 8, 1}, + {14, 4, 3, 2}, + {14, 4, 5, 9}, + {14, 4, 0, 14}, + } + for _, test := range tests { + actual := Post(test.size, test.height, test.id) + if test.expected != actual { + t.Errorf("%d, %d, expected: %d, actual: %d", test.size, test.id, + test.expected, actual) + } + } + +} -- cgit v1.2.3-70-g09d2