diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2016-05-04 15:54:19 -0400 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2016-05-04 15:54:19 -0400 |
| commit | 7943430749a22e6f26aa16ca2c48e97e9277998f (patch) | |
| tree | 51a4d95e987d60f1b2936d5a5da9f5040efdf835 /utils_test.go | |
| download | pos-7943430749a22e6f26aa16ca2c48e97e9277998f.tar.gz | |
Initial commit
Diffstat (limited to 'utils_test.go')
| -rw-r--r-- | utils_test.go | 74 |
1 files changed, 74 insertions, 0 deletions
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) + } + } + +} |
