encoder_test.go 545 B

1234567891011121314151617181920212223
  1. package ean
  2. import (
  3. "image/color"
  4. "testing"
  5. )
  6. func Test_EncodeEAN13(t *testing.T) {
  7. testResult := "10100010110100111011001100100110111101001110101010110011011011001000010101110010011101000100101"
  8. testCode := "5901234123457"
  9. code, err := Encode(testCode)
  10. if err != nil {
  11. t.Error(err)
  12. }
  13. if code.Metadata().Dimensions != 1 || code.Content() != testCode || code.Metadata().CodeKind != "EAN 13" {
  14. t.Error("Metadata missmatch")
  15. }
  16. for i, r := range testResult {
  17. if (code.At(i, 0) == color.Black) != (r == '1') {
  18. t.Fail()
  19. }
  20. }
  21. }