summaryrefslogtreecommitdiff
path: root/go/variable-length-quantity/variable_length_quantity_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/variable-length-quantity/variable_length_quantity_test.go')
-rw-r--r--go/variable-length-quantity/variable_length_quantity_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/go/variable-length-quantity/variable_length_quantity_test.go b/go/variable-length-quantity/variable_length_quantity_test.go
new file mode 100644
index 0000000..537f5ac
--- /dev/null
+++ b/go/variable-length-quantity/variable_length_quantity_test.go
@@ -0,0 +1,33 @@
+package variablelengthquantity
+
+import (
+ "bytes"
+ "reflect"
+ "testing"
+)
+
+func TestDecodeVarint(t *testing.T) {
+ for i, tc := range decodeTestCases {
+ o, err := DecodeVarint(tc.input)
+ if err != nil {
+ var _ error = err
+ if tc.output != nil {
+ t.Fatalf("FAIL: case %d | %s\nexpected %#v got error: %q\n", i, tc.description, tc.output, err)
+ }
+ } else if tc.output == nil {
+ t.Fatalf("FAIL: case %d | %s\nexpected error, got %#v\n", i, tc.description, o)
+ } else if !reflect.DeepEqual(o, tc.output) {
+ t.Fatalf("FAIL: case %d | %s\nexpected\t%#v\ngot\t\t%#v\n", i, tc.description, tc.output, o)
+ }
+ t.Logf("PASS: case %d | %s\n", i, tc.description)
+ }
+}
+
+func TestEncodeVarint(t *testing.T) {
+ for i, tc := range encodeTestCases {
+ if encoded := EncodeVarint(tc.input); bytes.Compare(encoded, tc.output) != 0 {
+ t.Fatalf("FAIL: case %d | %s\nexpected\t%#v\ngot\t\t%#v\n", i, tc.description, tc.output, encoded)
+ }
+ t.Logf("PASS: case %d | %s\n", i, tc.description)
+ }
+}