Explorar el Código

added testscase for ean encoding

boombuler hace 12 años
padre
commit
b63e15f7ff
Se han modificado 1 ficheros con 23 adiciones y 0 borrados
  1. 23 0
      ean/encoder_test.go

+ 23 - 0
ean/encoder_test.go

@@ -0,0 +1,23 @@
+package ean
+
+import (
+	"image/color"
+	"testing"
+)
+
+func Test_EncodeEAN13(t *testing.T) {
+	testResult := "10100010110100111011001100100110111101001110101010110011011011001000010101110010011101000100101"
+	testCode := "5901234123457"
+	code, err := Encode(testCode)
+	if err != nil {
+		t.Error(err)
+	}
+	if code.Metadata().Dimensions != 1 || code.Content() != testCode || code.Metadata().CodeKind != "EAN 13" {
+		t.Error("Metadata missmatch")
+	}
+	for i, r := range testResult {
+		if (code.At(i, 0) == color.Black) != (r == '1') {
+			t.Fail()
+		}
+	}
+}