From b1ca18cc4c07b9a7315f3a974ab21a8f19a87bbe Mon Sep 17 00:00:00 2001 From: Florian Sundermann Date: Tue, 12 Aug 2014 13:53:36 +0200 Subject: [PATCH] test cleanup --- codabar/encoder_test.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/codabar/encoder_test.go b/codabar/encoder_test.go index 24c2aaa..5f13009 100644 --- a/codabar/encoder_test.go +++ b/codabar/encoder_test.go @@ -11,19 +11,22 @@ func Test_Encode(t *testing.T) { t.Error("\"FOOBAR\" should not be encodable") } - code, err := Encode("A40156B") - if err != nil || code == nil { - t.Fail() - } else { - testResult := "10110010010101101001010101001101010110010110101001010010101101010010011" - if code.Bounds().Max.X != len(testResult) { - t.Error("length missmatch") + testEncode := func(txt, testResult string) { + code, err := Encode(txt) + if err != nil || code == nil { + t.Fail() } else { - for i, r := range testResult { - if (code.At(i, 0) == color.Black) != (r == '1') { - t.Errorf("code missmatch on position %d", i) + if code.Bounds().Max.X != len(testResult) { + t.Errorf("%v: length missmatch", txt) + } else { + for i, r := range testResult { + if (code.At(i, 0) == color.Black) != (r == '1') { + t.Errorf("%v: code missmatch on position %d", txt, i) + } } } } } + + testEncode("A40156B", "10110010010101101001010101001101010110010110101001010010101101010010011") }