encoder_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package code93
  2. import (
  3. "image/color"
  4. "testing"
  5. )
  6. func doTest(t *testing.T, data, testResult string) {
  7. code, err := Encode(data, true, false)
  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_CheckSum(t *testing.T) {
  21. if r := getChecksum("TEST93", 20); r != '+' {
  22. t.Errorf("Checksum C-Failed. Got %s", string(r))
  23. }
  24. if r := getChecksum("TEST93+", 15); r != '6' {
  25. t.Errorf("Checksum K-Failed. Got %s", string(r))
  26. }
  27. }
  28. func Test_Encode(t *testing.T) {
  29. doTest(t, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
  30. "1010111101101010001101001001101000101100101001100100101100010101011010001011001"+
  31. "001011000101001101001000110101010110001010011001010001101001011001000101101101101001"+
  32. "101100101101011001101001101100101101100110101011011001011001101001101101001110101000"+
  33. "101001010010001010001001010000101001010001001001001001000101010100001000100101000010"+
  34. "101001110101010000101010111101")
  35. }