git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/barcode/code93/encoder_test.go (about) 1 package code93 2 3 import ( 4 "image/color" 5 "testing" 6 ) 7 8 func doTest(t *testing.T, data, testResult string) { 9 code, err := Encode(data, true, false) 10 if err != nil { 11 t.Error(err) 12 } 13 if len(testResult) != code.Bounds().Max.X { 14 t.Errorf("Invalid code size. Expected %d got %d", len(testResult), code.Bounds().Max.X) 15 } 16 for i, r := range testResult { 17 if (code.At(i, 0) == color.Black) != (r == '1') { 18 t.Errorf("Failed at position %d", i) 19 } 20 } 21 } 22 23 func Test_CheckSum(t *testing.T) { 24 if r := getChecksum("TEST93", 20); r != '+' { 25 t.Errorf("Checksum C-Failed. Got %s", string(r)) 26 } 27 if r := getChecksum("TEST93+", 15); r != '6' { 28 t.Errorf("Checksum K-Failed. Got %s", string(r)) 29 } 30 } 31 32 func Test_Encode(t *testing.T) { 33 doTest(t, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 34 "1010111101101010001101001001101000101100101001100100101100010101011010001011001"+ 35 "001011000101001101001000110101010110001010011001010001101001011001000101101101101001"+ 36 "101100101101011001101001101100101101100110101011011001011001101001101101001110101000"+ 37 "101001010010001010001001010000101001010001001001001001000101010100001000100101000010"+ 38 "101001110101010000101010111101") 39 }