ocadotechnology / test-arranger

Arranges test data as fully populated objects
Apache License 2.0
23 stars 2 forks source link

somePriceLikeBigDecimal not always generates numbers with scale equals 2 #42

Closed mjureczko closed 2 years ago

mjureczko commented 2 years ago

Can be detected with the following test case:

        for (int i = 0; i < 99999; i++) {
            //given
            final BigDecimal min = new BigDecimal("64");
            final BigDecimal max = new BigDecimal("65");

            //when
            final BigDecimal actual = Arranger.somePriceLikeBigDecimal(min, max);

            //then
            assertThat(actual).isGreaterThanOrEqualTo(min);
            assertThat(actual).isLessThanOrEqualTo(max);
            System.out.println(actual);
            assertEquals(2, actual.scale());
        }
MaciejTrojniarz commented 2 years ago

The tricky part with it is that some of the currencies don't follow 2 decimal places so maybe it should be decorated/configured somehow. (f.e. JP yen)

mjureczko commented 2 years ago

Test-arranger is not very advanced with regard to internationalization, there is only the possibility to customize someText()... @MaciejTrojniarz consider reporting a feature request and explain how you would like to use the internationalization. Alternatively, maybe what you need is someBigDecimal() with a scale parameter, which, by the way, also deserves a dedicated issue.