Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import "regexp"
|
||||
|
||||
var r = regexp.MustCompile(`^[A-Z]{2}[A-Z0-9]{9}\d$`)
|
||||
|
||||
var inc = [2][10]int{
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
|
||||
{0, 2, 4, 6, 8, 1, 3, 5, 7, 9},
|
||||
}
|
||||
|
||||
func ValidISIN(n string) bool {
|
||||
if !r.MatchString(n) {
|
||||
return false
|
||||
}
|
||||
var sum, p int
|
||||
for i := 10; i >= 0; i-- {
|
||||
p = 1 - p
|
||||
if d := n[i]; d < 'A' {
|
||||
sum += inc[p][d-'0']
|
||||
} else {
|
||||
d -= 'A'
|
||||
sum += inc[p][d%10]
|
||||
p = 1 - p
|
||||
sum += inc[p][d/10+1]
|
||||
}
|
||||
}
|
||||
sum += int(n[11] - '0')
|
||||
return sum%10 == 0
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestValidISIN(t *testing.T) {
|
||||
testcases := []struct {
|
||||
isin string
|
||||
valid bool
|
||||
}{
|
||||
{"US0378331005", true},
|
||||
{"US0373831005", false},
|
||||
{"U50378331005", false},
|
||||
{"US03378331005", false},
|
||||
{"AU0000XVGZA3", true},
|
||||
{"AU0000VXGZA3", true},
|
||||
{"FR0000988040", true},
|
||||
}
|
||||
|
||||
for _, testcase := range testcases {
|
||||
actual := ValidISIN(testcase.isin)
|
||||
if actual != testcase.valid {
|
||||
t.Errorf("expected %v for %q, got %v",
|
||||
testcase.valid, testcase.isin, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue