highlevel_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package pdf417
  2. import "testing"
  3. func compareIntSlice(t *testing.T, expected, actual []int, testStr string) {
  4. if len(actual) != len(expected) {
  5. t.Errorf("Invalid slice size. Expected %d got %d while encoding %q", len(expected), len(actual), testStr)
  6. return
  7. }
  8. for i, a := range actual {
  9. if e := expected[i]; e != a {
  10. t.Errorf("Unexpected value at position %d. Expected %d got %d while encoding %q", i, e, a, testStr)
  11. }
  12. }
  13. }
  14. func TestHighlevelEncode(t *testing.T) {
  15. runTest := func(msg string, expected ...int) {
  16. if codes, err := highlevelEncode(msg); err != nil {
  17. t.Error(err)
  18. } else {
  19. compareIntSlice(t, expected, codes, msg)
  20. }
  21. }
  22. runTest("01234", 902, 112, 434)
  23. runTest("Super !", 567, 615, 137, 809, 329)
  24. runTest("Super ", 567, 615, 137, 809)
  25. runTest("ABC123", 1, 88, 32, 119)
  26. runTest("123ABC", 841, 63, 840, 32)
  27. }
  28. func TestBinaryEncoder(t *testing.T) {
  29. runTest := func(msg string, expected ...int) {
  30. codes := encodeBinary([]byte(msg), encText)
  31. compareIntSlice(t, expected, codes, msg)
  32. }
  33. runTest("alcool", 924, 163, 238, 432, 766, 244)
  34. runTest("alcoolique", 901, 163, 238, 432, 766, 244, 105, 113, 117, 101)
  35. }