Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bastie committed Sep 3, 2024
1 parent caa8425 commit 21de2fd
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Swift
.build
.swiftpm
Package.resolved

#eof
15 changes: 0 additions & 15 deletions Package.resolved

This file was deleted.

72 changes: 43 additions & 29 deletions Sources/iban4j2JavApi/org/iban4j/bban/BbanStructure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,35 +297,12 @@ extension org.iban4j.bban {
structures[org.iban4j.CountryCode.LU()] =
BbanStructure(
BbanStructureEntry.bankCode(3, "n"), BbanStructureEntry.accountNumber(13, "c"))

structures[org.iban4j.CountryCode.MK()] =
BbanStructure(
BbanStructureEntry.bankCode(3, "n"),
BbanStructureEntry.accountNumber(10, "c"),
BbanStructureEntry.nationalCheckDigit(2, "n"))

structures[org.iban4j.CountryCode.MT()] =
BbanStructure(
BbanStructureEntry.bankCode(4, "a"),
BbanStructureEntry.branchCode(5, "n"),
BbanStructureEntry.accountNumber(18, "c"))

structures[org.iban4j.CountryCode.MR()] =
BbanStructure(
BbanStructureEntry.bankCode(5, "n"),
BbanStructureEntry.branchCode(5, "n"),
BbanStructureEntry.accountNumber(11, "n"),
BbanStructureEntry.nationalCheckDigit(2, "n"))

structures[org.iban4j.CountryCode.MU()] =
BbanStructure(
BbanStructureEntry.bankCode(6, "c"),
BbanStructureEntry.branchCode(2, "n"),
BbanStructureEntry.accountNumber(18, "c"))

structures[org.iban4j.CountryCode.MD()] =
BbanStructure(
BbanStructureEntry.bankCode(2, "c"), BbanStructureEntry.accountNumber(18, "c"))

structures[org.iban4j.CountryCode.MA()] =
BbanStructure(
BbanStructureEntry.bankCode(3, "n"),
BbanStructureEntry.branchCode(5, "n"),
BbanStructureEntry.accountNumber(16, "n"))

structures[org.iban4j.CountryCode.MC()] =
BbanStructure(
Expand All @@ -334,12 +311,49 @@ extension org.iban4j.bban {
BbanStructureEntry.accountNumber(11, "c"),
BbanStructureEntry.nationalCheckDigit(2, "n"))

structures[org.iban4j.CountryCode.MD()] =
BbanStructure(
BbanStructureEntry.bankCode(2, "c"), BbanStructureEntry.accountNumber(18, "c"))

structures[org.iban4j.CountryCode.ME()] =
BbanStructure(
BbanStructureEntry.bankCode(3, "n"),
BbanStructureEntry.accountNumber(13, "n"),
BbanStructureEntry.nationalCheckDigit(2, "n"))

structures[org.iban4j.CountryCode.MK()] =
BbanStructure(
BbanStructureEntry.bankCode(3, "n"),
BbanStructureEntry.accountNumber(10, "c"),
BbanStructureEntry.nationalCheckDigit(2, "n"))

structures[org.iban4j.CountryCode.MR()] =
BbanStructure(
BbanStructureEntry.bankCode(5, "n"),
BbanStructureEntry.branchCode(5, "n"),
BbanStructureEntry.accountNumber(11, "n"),
BbanStructureEntry.nationalCheckDigit(2, "n"))

structures[org.iban4j.CountryCode.MT()] =
BbanStructure(
BbanStructureEntry.bankCode(4, "a"),
BbanStructureEntry.branchCode(5, "n"),
BbanStructureEntry.accountNumber(18, "c"))

structures[org.iban4j.CountryCode.MU()] =
BbanStructure(
BbanStructureEntry.bankCode(6, "c"),
BbanStructureEntry.branchCode(2, "n"),
BbanStructureEntry.accountNumber(18, "c"))

structures[org.iban4j.CountryCode.MZ()] =
BbanStructure(
BbanStructureEntry.bankCode(4, "n"),
BbanStructureEntry.branchCode(4, "n"),
BbanStructureEntry.accountNumber(11, "n"),
BbanStructureEntry.nationalCheckDigit(2, "n"))


structures[org.iban4j.CountryCode.NL()] =
BbanStructure(
BbanStructureEntry.bankCode(4, "a"), BbanStructureEntry.accountNumber(10, "n"))
Expand Down
56 changes: 29 additions & 27 deletions Tests/iban4j2JavApiTests/IbanTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,40 @@ extension org.iban4j {
)
}
}

private func assertIbanUtilRandomWithSeedEquals(_ expected : String, _ seed : Int) {
let generated : Iban = try! Iban.random(java.util.Random(seed));
XCTAssertEqual(expected, generated.toFormattedString(),
"expect that creating an IBAN with seed '\(seed)' is deterministic"
)
}

public func testIbanConstructionSeeded() {
assertIbanUtilRandomWithSeedEquals("FR46 1918 2083 691H JENI SJS3 364", 1)
assertIbanUtilRandomWithSeedEquals("LC94 QKBB C1OY WHST MPQA 7GVB 4WBX VTP0", 2)
assertIbanUtilRandomWithSeedEquals("DK23 0882 2804 1804 23", 3)
}
private static func assertIbanBuilderRandomWithSeedEquals(_ expected : String, _ seed : Int) {
let generated : Iban = try! Builder(java.util.Random(seed)).buildRandom()
let actual : String = generated.toFormattedString()
XCTAssertEqual(expected, actual, "expect that creating an IBAN with seed '\(seed)' is deterministic")
}


public func testIbanBuilderConstructionSeeded() {
org.iban4j.assertIbanBuilderRandomWithSeedEquals("FR46 1918 2083 691H JENI SJS3 364", 1)
org.iban4j.assertIbanBuilderRandomWithSeedEquals("LC94 QKBB C1OY WHST MPQA 7GVB 4WBX VTP0", 2)
org.iban4j.assertIbanBuilderRandomWithSeedEquals("DK23 0882 2804 1804 23", 3)
org.iban4j.assertIbanBuilderRandomWithSeedEquals("BY38 LPL2 0836 1HJE NISJ S339 QZGT", 1)
org.iban4j.assertIbanBuilderRandomWithSeedEquals("IE70 QKBB 0988 8722 1186 81", 2)
org.iban4j.assertIbanBuilderRandomWithSeedEquals("MC38 0882 8280 41ER G8WO UQNL Y52", 3)
}


/*
@DisplayName("Iban general test")
final class IbanTest {

private static void assertIbanBuilderRandomWithSeedEquals(final String expected, final int seed) {
final Iban generated = new Iban.Builder(new Random(seed)).buildRandom();
final String actual = generated.toFormattedString();
assertEquals(
expected, actual, "expect that creating an IBAN with seed '" + seed + "' is deterministic");
}

@Test
@DisplayName("IBANs With Same Data Should Be Equal")
public void ibansWithSameDataShouldBeEqual() {
Expand Down Expand Up @@ -372,26 +394,6 @@ extension org.iban4j {
}
}

@Test
public void ibanConstructionSeeded() {
assertAll(
() -> assertIbanUtilRandomWithSeedEquals("FR46 1918 2083 691H JENI SJS3 364", 1),
() -> assertIbanUtilRandomWithSeedEquals("LC94 QKBB C1OY WHST MPQA 7GVB 4WBX VTP0", 2),
() -> assertIbanUtilRandomWithSeedEquals("DK23 0882 2804 1804 23", 3));
}

private void assertIbanUtilRandomWithSeedEquals(
final String expected,
final int seed
) {
final Iban generated = Iban.random(new Random(seed));
assertEquals(
expected,
generated.toFormattedString(),
"expect that creating an IBAN with seed '" + seed + "' is deterministic"
);
}

@Test
public void ibanBuilderConstructionSeeded() {
assertAll(
Expand Down
28 changes: 28 additions & 0 deletions Tests/iban4j2JavApiTests/TestDataHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,20 @@ extension org.iban4j {
result.insert(elem, at: result.count)
}

do {
var elem : (Iban, String)
elem.0 =
try! Builder()
.setCountryCode(CountryCode.MA())
.setBankCode("011")
.setBranchCode("51900")
.setAccountNumber("0001205000534921")
.build()
elem.1 =
"MA64011519000001205000534921"
result.insert(elem, at: result.count)
}

do {
var elem : (Iban, String)
elem.0 =
Expand Down Expand Up @@ -781,6 +795,20 @@ extension org.iban4j {
result.insert(elem, at: result.count)
}

do {
var elem : (Iban, String)
elem.0 = try! Builder()
.setCountryCode(CountryCode.MZ())
.setBankCode("0003")
.setBranchCode("0108")
.setAccountNumber("00163671023")
.setNationalCheckDigit("71")
.build()
elem.1 =
"MZ59000301080016367102371"
result.insert(elem, at: result.count)
}

do {
var elem : (Iban, String)
elem.0 =
Expand Down

0 comments on commit 21de2fd

Please sign in to comment.