summaryrefslogtreecommitdiff
path: root/go/octal/octal_test.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-08-30 13:45:03 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-08-30 13:45:03 +0200
commite3b7162a22f331a7e8b44982764d9b3977918294 (patch)
tree765b2cc1b4a9373ce494c724460fd1df25e4783b /go/octal/octal_test.go
parent51a16a7abbf34e01b9f669711f8eeef4b01f02f8 (diff)
Solve octal
Diffstat (limited to 'go/octal/octal_test.go')
-rw-r--r--go/octal/octal_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/go/octal/octal_test.go b/go/octal/octal_test.go
new file mode 100644
index 0000000..35247ee
--- /dev/null
+++ b/go/octal/octal_test.go
@@ -0,0 +1,50 @@
+package octal
+
+import (
+ "testing"
+)
+
+var testCases = []struct {
+ input string
+ expectedNum int64
+ expectErr bool
+}{
+ {"1", 1, false},
+ {"10", 8, false},
+ {"1234567", 342391, false},
+ {"carrot", 0, true},
+ {"35682", 0, true},
+}
+
+func TestParseOctal(t *testing.T) {
+ for _, test := range testCases {
+ actualNum, actualErr := ParseOctal(test.input)
+ if actualNum != test.expectedNum {
+ t.Fatalf("ParseOctal(%s): expected[%d], actual [%d]",
+ test.input, test.expectedNum, actualNum)
+ }
+
+ // if we expect an error and there isn't one
+ if test.expectErr && actualErr == nil {
+ t.Errorf("ParseOctal(%s): expected an error, but error is nil", test.input)
+ }
+ // if we don't expect an error and there is one
+ if !test.expectErr && actualErr != nil {
+ t.Errorf("ParseOctal(%s): expected no error, but error is: %s", test.input, actualErr)
+ }
+ }
+}
+
+func BenchmarkParseOctal(b *testing.B) {
+ b.StopTimer()
+
+ for _, test := range testCases {
+ b.StartTimer()
+
+ for i := 0; i < b.N; i++ {
+ ParseOctal(test.input)
+ }
+
+ b.StopTimer()
+ }
+}