Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
45
Task/IBAN/Scala/iban-1.scala
Normal file
45
Task/IBAN/Scala/iban-1.scala
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import scala.collection.immutable.SortedMap
|
||||
|
||||
class Iban(val iban: String) {
|
||||
// Isolated tests
|
||||
def isAllUpperCase = iban.toUpperCase == iban
|
||||
|
||||
def isValidpattern = (Iban.pattern findFirstIn iban).nonEmpty
|
||||
|
||||
def isNationalSize = {
|
||||
Iban.ccVsLength.getOrElse(iban.take(2), 0) == iban.size
|
||||
}
|
||||
|
||||
def isCheckNumberOK = {
|
||||
def rearrange = (iban.drop(4) + iban.take(4)). // Move left country code part to end
|
||||
// continue with each char converted to Int
|
||||
map(ch => if (ch.isDigit) ch.toInt - '0' else ch - 'A' + 10).mkString
|
||||
|
||||
(BigInt(rearrange) mod 97) == 1
|
||||
}
|
||||
|
||||
def isValidIban = {
|
||||
isAllUpperCase &&
|
||||
isValidpattern &&
|
||||
isNationalSize &&
|
||||
isCheckNumberOK
|
||||
}
|
||||
}
|
||||
|
||||
object Iban {
|
||||
// IBAN length database
|
||||
lazy val ccVsLength: SortedMap[String, Int] = SortedMap[String, Int]() ++
|
||||
"""AD24 AE23 AL28 AO25 AT20 AZ28 BA20 BE16 BF27 BG22 BH22 BI16
|
||||
|BJ28 BR29 CG27 CH21 CI28 CM27 CR21 CV25 CY28 CZ24 DE22 DK18
|
||||
|DO28 DZ24 EE20 EG27 ES24 FI18 FO18 FR27 GA27 GB22 GE22 GI23
|
||||
|GL18 GR27 GT28 HR21 HU28 IE22 IL23 IR26 IS26 IT27 JO30 KW30
|
||||
|KZ20 LB28 LI21 LT20 LU20 LV21 MC27 MD24 ME22 MG27 MK19 ML28
|
||||
|MR27 MT31 MU30 MZ25 NL18 NO15 PK24 PL28 PS29 PT25 QA29 RO24
|
||||
|RS22 SA24 SE24 SI19 SK24 SM27 SN28 TN24 TR26 UA29 VG24""".
|
||||
stripMargin.replaceAll( """\s""", " ").split(' ').
|
||||
map(v => (v.take(2), if (v.isEmpty) 0 else v.slice(2, 4).toInt))
|
||||
|
||||
lazy val pattern = "([A-Z]{2})([0-9]{2})([A-Z0-9]{4})([A-Z0-9]{0,2})([0-9]{7})(([A-Z0-9]?){0,16})".r
|
||||
|
||||
def apply(s: String) = new Iban(s.replaceAll( """\s""", ""))
|
||||
}
|
||||
98
Task/IBAN/Scala/iban-2.scala
Normal file
98
Task/IBAN/Scala/iban-2.scala
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
object IbanTest extends App {
|
||||
def blackCases = """AT611904300235473201
|
||||
|GB82TEST12345698765432
|
||||
|GB81WEST12345698765432""".stripMargin
|
||||
|
||||
def whiteCases = """AD1200012030200359100100
|
||||
|AE26 0211 0000 0023 0064 016
|
||||
|AL47 2121 1009 0000 0002 3569 8741
|
||||
|AO06000600000100037131174
|
||||
|AZ21NABZ00000000137010001944
|
||||
|BA391290079401028494
|
||||
|BE68539007547034
|
||||
|BF1030134020015400945000643
|
||||
|BG80BNBG96611020345678
|
||||
|BH29BMAG1299123456BH00
|
||||
|BI43201011067444
|
||||
|BJ11B00610100400271101192591
|
||||
|BR9700360305000010009795493P1
|
||||
|CG5230011000202151234567890
|
||||
|CH9300762011623852957
|
||||
|CI05A00060174100178530011852
|
||||
|CM2110003001000500000605306
|
||||
|CR0515202001026284066
|
||||
|CV64000300004547069110176
|
||||
|CY17002001280000001200527600
|
||||
|CZ6508000000192000145399
|
||||
|DE89370400440532013000
|
||||
|DK5000400440116243
|
||||
|DO28BAGR00000001212453611324
|
||||
|DZ4000400174401001050486
|
||||
|EE382200221020145685
|
||||
|EG1100006001880800100014553
|
||||
|ES9121000418450200051332
|
||||
|FI2112345600000785
|
||||
|FO1464600009692713
|
||||
|FR1420041010050500013M02606
|
||||
|FR7630007000110009970004942
|
||||
|GA2140002000055602673300064
|
||||
|GB29NWBK60161331926819
|
||||
|GE29NB0000000101904917
|
||||
|GI75NWBK000000007099453
|
||||
|GL8964710001000206
|
||||
|GR1601101250000000012300695
|
||||
|GT82TRAJ01020000001210029690
|
||||
|HR1210010051863000160
|
||||
|HU42117730161111101800000000
|
||||
|IE29AIBK93115212345678
|
||||
|IL620108000000099999999
|
||||
|IR580540105180021273113007
|
||||
|IS140159260076545510730339
|
||||
|IT60X0542811101000000123456
|
||||
|JO94CBJO0010000000000131000302
|
||||
|KW74NBOK0000000000001000372151
|
||||
|KZ176010251000042993
|
||||
|LB30099900000001001925579115
|
||||
|LI21088100002324013AA
|
||||
|LT121000011101001000
|
||||
|LU280019400644750000
|
||||
|LV80BANK0000435195001
|
||||
|MC5813488000010051108001292
|
||||
|MD24AG000225100013104168
|
||||
|ME25505000012345678951
|
||||
|MG4600005030010101914016056
|
||||
|MK07300000000042425
|
||||
|ML03D00890170001002120000447
|
||||
|MR1300012000010000002037372
|
||||
|MT84MALT011000012345MTLCAST001S
|
||||
|MU17BOMM0101101030300200000MUR
|
||||
|MZ59000100000011834194157
|
||||
|NL91ABNA0417164300
|
||||
|NL81 TRIO 0212 4710 66
|
||||
|NO9386011117947
|
||||
|PK24SCBL0000001171495101
|
||||
|PL27114020040000300201355387
|
||||
|PS92PALS000000000400123456702
|
||||
|PT50000200000163099310355
|
||||
|PT50000201231234567890154
|
||||
|QA58 DOHB 0000 1234 5678 90AB CDEF G
|
||||
|RO49 AAAA 1B31 0075 9384 0000
|
||||
|RS35260005601001611379
|
||||
|SA0380000000608010167519
|
||||
|SE3550000000054910000003
|
||||
|SI56191000000123438
|
||||
|SK3112000000198742637541
|
||||
|SM86U0322509800000000270100
|
||||
|SN12K00100152000025690007542
|
||||
|TN5914207207100707129648
|
||||
|TR330006100519786457841326
|
||||
|UA57 3543 4700 0676 2462 0549 2502 6
|
||||
|VG96 VPVG 0000 0123 4567 8901
|
||||
|GB82 WEST 1234 5698 7654 32
|
||||
|SA03 8000 0000 6080 1016 7519
|
||||
|CH93 0076 2011 6238 5295 7""".stripMargin
|
||||
|
||||
whiteCases.lines.foreach(l => assert(Iban(l).isValidIban))
|
||||
blackCases.lines.foreach(l => assert(!Iban(l).isValidIban))
|
||||
println(s"Successfully completed; ${whiteCases.lines.size + blackCases.lines.size} cases tested, no errors.")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue