iban4j
iban4j copied to clipboard
Allow setting a seed for Random
I'm using Kotest property based testing, and this needs a deterministic way of generating random data based on a seed, or existing Random
instance.
iban4j can generate random IBANs, but I can't set a seed or pass in a Random
instance.
I would like to add an overload for the 'Iban.random()method that will accept a
Random` parameter.
I can try making a PR for this, if you agree. Thanks!
Yes, of course, you can do it.
@aSemy There are two failing tests regarding this issue. I disabled them for now. Can you take a look?
The testcases for this issue is bad because the random generation depends on the BbanStructure and what order the objects added to our EnumMap. the random mechanism should change if we don't want to change this testcase every time we add new BbanStructure or we have to let go of the testcases for this feature. we can make a random method with country input if the other part of the iban require to be random and this will not get affected by new BbanStructure.
@MR-Os1 we might have different test cases for both(using random generation or not). Can you handle this one?
The point of tests was to verify that the random generation of a single IBAN didn't affect subsequent ones. It's the code that's bad, not the tests 😅.
I've opened a PR #126 that should fix the generation, so that each IBAN is generated using an independent Random. Even if multiple IBANs are generated, a seeded IBAN should only change if the structure of its randomly selected country changes, and subsequently generated IBANs shouldn't change.
#126 is just one option, maybe there's a way to improve the tests too?
this is still going to have side effect on adding new BbanStructure
this is still going to have side effect on adding new BbanStructure
So maybe it is worth to create a new ticket regarding some improvement to the procedure