Anonymous user
IBAN: Difference between revisions
→{{header|Go}}: Fix Go program to be of acceptable style. The previous code was inacceptably structured and didn't even produce the given output.
(→{{header|C++}}: format the code in a more common way) |
(→{{header|Go}}: Fix Go program to be of acceptable style. The previous code was inacceptably structured and didn't even produce the given output.) |
||
Line 1,808:
=={{header|Go}}==
<lang Go>package main
import (
"
"strings"
"
)
var
"AL": 28, "AD": 24, "AT": 20, "AZ": 28, "BE": 16, "BH": 22
}
if len(iban) < 4 {
return false
}▼
▲ "H": 17, "I": 18, "J": 19, "K": 20, "L": 21, "M": 22, "N": 23,
iban = regexp.MustCompile(`\s+`).ReplaceAllString(iban, "")
▲ "O": 24, "P": 25, "Q": 26, "R": 27, "S": 28, "T": 29, "U": 30,
▲ "V": 31, "W": 32, "X": 33, "Y": 34, "Z": 35,
▲}
ibanLen := lengthByCountryCode[iban[0:2]]
if ibanLen == 0 {
return false
var iban string ▼
iban = "GB82 TEST 1234 5698 7654 32"▼
▲ r = strings.Split(iban, " ")
}
iban = iban[4:] + iban[:4]
result := 0
for _, ch := range iban {
var n int
if '0' <= ch && ch <= '9' {
n = int(ch) - '0'
} else if 'A' <= ch && ch <= 'Z' {
n = 10 + int(ch) - 'A'
return false
}
if n < 10 {
result = (10*result + n) % 97
} else {
result = (100*result + n) % 97
}
}
return result == 1
}
</lang>▼
func TestIsValidIBAN(t *testing.T) {
tests := []struct {
IBAN GB82 WEST 1234 5698 7654 32 looks good!▼
valid bool
}{
▲ }
for _, test := range tests {
if isValidIBAN(test.iban) == test.valid {
return
}
t.Errorf("Expected %q to be %v", test.iban, test.valid)
▲ }
}
▲</lang>
=={{header|Groovy}}==
|