encoder_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. package code39
  2. import (
  3. "image/color"
  4. "testing"
  5. )
  6. func doTest(t *testing.T, addCS, fullASCII bool, data, testResult string) {
  7. code, err := Encode(data, addCS, fullASCII)
  8. if err != nil {
  9. t.Error(err)
  10. }
  11. if len(testResult) != code.Bounds().Max.X {
  12. t.Errorf("Invalid code size. Expected %d got %d", len(testResult), code.Bounds().Max.X)
  13. }
  14. for i, r := range testResult {
  15. if (code.At(i, 0) == color.Black) != (r == '1') {
  16. t.Errorf("Failed at position %d", i)
  17. }
  18. }
  19. }
  20. func Test_Encode(t *testing.T) {
  21. doTest(t, false, false, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
  22. "1001011011010110101001011010110100101101101101001010101011001011011010110010101"+
  23. "011011001010101010011011011010100110101011010011010101011001101011010101001101011010"+
  24. "100110110110101001010101101001101101011010010101101101001010101011001101101010110010"+
  25. "101101011001010101101100101100101010110100110101011011001101010101001011010110110010"+
  26. "110101010011011010101010011011010110100101011010110010101101101100101010101001101011"+
  27. "011010011010101011001101010101001011011011010010110101011001011010100101101101")
  28. }