From c067dca4a86c638add29d0ca920b6697d593c814 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 29 Jun 2015 17:33:16 +0200 Subject: Adjust int test --- ber/int_test.go | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'ber') diff --git a/ber/int_test.go b/ber/int_test.go index 9a015c5..c7f4ee2 100644 --- a/ber/int_test.go +++ b/ber/int_test.go @@ -5,28 +5,32 @@ import ( "testing" ) -func testInt(t *testing.T, i int64, b []byte) { - a := marshalInt(i) - if !bytes.Equal(a, b) { - t.Error("BER", i, "expected", b, "got", a) - } - - n := unmarshalInt(b) - if n != i { - t.Error("UnBER", b, "expected", i, "got", n) - } +type intTest struct { + in int64 + out []byte +} +var intTestData = []intTest{ + {0, []byte{0x00}}, + {127, []byte{0x7F}}, + {128, []byte{0x00, 0x80}}, + {256, []byte{0x01, 0x00}}, + {-128, []byte{0x80}}, + {-129, []byte{0xFF, 0x7F}}, + {8388607, []byte{0x7f, 0xFF, 0xFF}}, + {-136, []byte{0xFF, 0x78}}, + {-8388607, []byte{0x80, 0x00, 0x01}}, } func TestInt(t *testing.T) { - testInt(t, 0, []byte{0x00}) - testInt(t, 127, []byte{0x7F}) - testInt(t, 128, []byte{0x00, 0x80}) - testInt(t, 256, []byte{0x01, 0x00}) - testInt(t, -128, []byte{0x80}) - testInt(t, -129, []byte{0xFF, 0x7F}) - - testInt(t, 8388607, []byte{0x7f, 0xFF, 0xFF}) - testInt(t, -136, []byte{0xFF, 0x78}) - testInt(t, -8388607, []byte{0x80, 0x00, 0x01}) + for _, test := range intTestData { + a := marshalInt(test.in) + if !bytes.Equal(a, test.out) { + t.Error(test.in, "expected", test.out, "got", a) + } + n := unmarshalInt(test.out) + if n != test.in { + t.Error(test.out, "expected", test.in, "got", n) + } + } } -- cgit v1.2.3