iban4j icon indicating copy to clipboard operation
iban4j copied to clipboard

Allow setting a seed for Random

Open aSemy opened this issue 2 years ago • 1 comments

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 aRandom` parameter.

I can try making a PR for this, if you agree. Thanks!

aSemy avatar Aug 18 '22 10:08 aSemy

Yes, of course, you can do it.

hajk1 avatar Aug 18 '22 21:08 hajk1

@aSemy There are two failing tests regarding this issue. I disabled them for now. Can you take a look?

hajk1 avatar Oct 02 '23 09:10 hajk1

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 avatar Jan 06 '24 18:01 MR-Os1

@MR-Os1 we might have different test cases for both(using random generation or not). Can you handle this one?

hajk1 avatar Jan 08 '24 16:01 hajk1

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?

aSemy avatar Jan 08 '24 19:01 aSemy

this is still going to have side effect on adding new BbanStructure

MR-Os1 avatar Jan 10 '24 21:01 MR-Os1

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

hajk1 avatar Jan 11 '24 07:01 hajk1