1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
# -------------------------------------------------------------------------
# luhn5.test -*- tcl -*-
# (C) 2011 Andreas Kupries. BSD licensed.
# -------------------------------------------------------------------------
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.5
testsNeedTcltest 2.0
support {
use snit/snit2.tcl snit ;# snit v2 fixed, due Tcl 8.5
useLocal valtype.tcl valtype::common
}
testing {
useLocal luhn5.tcl valtype::luhn5
}
# -------------------------------------------------------------------------
test valtype-luhn5-1.0 {luhn5 validation wrong\#args} -body {
valtype::luhn5 validate
} -returnCodes error \
-result {wrong # args: should be "valtype::luhn5 validate value ?code?"}
test valtype-luhn5-1.1 {luhn5 validation wrong\#args} -body {
valtype::luhn5 validate A B C
} -returnCodes error \
-result {wrong # args: should be "valtype::luhn5 validate value ?code?"}
# -------------------------------------------------------------------------
test valtype-luhn5-2.0 {luhn5 validation failure, bad char} -body {
valtype::luhn5 validate A
} -returnCodes error \
-result {Not a LUHN5 number, expected only digits}
foreach {n in} {
1 49999999
2 37
3 49927398717
4 1234567812345678
} {
test valtype-luhn5-2.1.$n {luhn5 validation failure, bad check} -body {
valtype::luhn5 validate $in
} -returnCodes error \
-result {Not a LUHN5 number, the check digit is incorrect}
}
test valtype-luhn5-3.0 {luhn5 checkdigit wrong\#args} -body {
valtype::luhn5 checkdigit0
} -returnCodes error \
-result {wrong # args: should be "valtype::luhn5 checkdigit0 value ?code?"}
test valtype-luhn5-3.1 {luhn5 checkdigit wrong\#args} -body {
valtype::luhn5 checkdigit0 A B C
} -returnCodes error \
-result {wrong # args: should be "valtype::luhn5 checkdigit0 value ?code?"}
test valtype-luhn5-3.2 {luhn5 checkdigit wrong\#args} -body {
valtype::luhn5 checkdigit5
} -returnCodes error \
-result {wrong # args: should be "valtype::luhn5 checkdigit5 value ?code?"}
test valtype-luhn5-3.3 {luhn5 checkdigit wrong\#args} -body {
valtype::luhn5 checkdigit5 A B C
} -returnCodes error \
-result {wrong # args: should be "valtype::luhn5 checkdigit5 value ?code?"}
# -------------------------------------------------------------------------
test valtype-luhn5-5.0 {luhn5 checkdigit calculation failure, bad char} -body {
valtype::luhn5 checkdigit0 A
} -returnCodes error \
-result {Not a LUHN5 number, expected only digits}
test valtype-luhn5-5.1 {luhn5 checkdigit calculation failure, bad char} -body {
valtype::luhn5 checkdigit5 A
} -returnCodes error \
-result {Not a LUHN5 number, expected only digits}
foreach {n in check0 check5} {
1 4999999 8 3
2 3 4 9
3 35 6 1
4 4992739871 6 1
5 123456781234567 0 5
} {
test valtype-luhn5-4.$n.10 {luhn5 validation 0 % 10} -body {
valtype::luhn5 validate $in$check0
} -result $in$check0
test valtype-luhn5-4.$n.5 {luhn5 validation 5 % 10} -body {
valtype::luhn5 validate $in$check5
} -result $in$check5
test valtype-luhn5-6.$n.10 {luhn5 checkdigit 0 % 10} -body {
valtype::luhn5 checkdigit0 $in
} -result $check0
test valtype-luhn5-6.$n.5 {luhn5 checkdigit 5 % 10} -body {
valtype::luhn5 checkdigit5 $in
} -result $check5
}
# -------------------------------------------------------------------------
testsuiteCleanup
return
# Local Variables:
# mode: tcl
# indent-tabs-mode: nil
# End:
|