Skip to content

Commit dbc1172

Browse files
committed
BAEL-8537: adaptation to article
1 parent 4d1135c commit dbc1172

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

core-kotlin-modules/core-kotlin-12/src/main/kotlin/com/baeldung/formatting/NumberFormat.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ interface NumberFormat {
1111

1212
/**
1313
* Returns provided number as string with thousands separator.
14-
*
15-
* 1000 -> '1.000'
16-
* 750000 -> '750.000'
1714
*/
1815
fun formatted(number: Int): String
1916
}

core-kotlin-modules/core-kotlin-12/src/test/kotlin/com/baeldung/formatting/NumberFormatUnitTest.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,23 @@ import org.assertj.core.api.Assertions.assertThat
99
class NumberFormatUnitTest : ShouldSpec({
1010

1111
// Dynamic generation of tests for each implementation
12-
nameToImplementationPairs.forEach { (type, function) ->
12+
nameToImplementationPairs.forEach { (name, function) ->
1313

1414
// Property based test (for each implementation)
15-
should("return correctly formatted string by $type") {
15+
should("return correctly formatted string with $name implementation") {
1616
checkAll(Arb.positiveInt()) { number ->
1717
var result = function(number)
1818

19-
// Check with regex
2019
assertThat(result).containsPattern("^(\\d{1,3}(\\.\\d{3})*|\\d+)$")
21-
// Check against original, by removing the separators
2220
assertThat(number.toString()).isEqualTo(result.replace(".", ""))
23-
24-
// Check for general presence & absence of separators
25-
if (number > 999) assertThat(result).contains(".")
26-
else assertThat(result).doesNotContain(".")
2721
}
2822
}
2923

30-
givenToExpectedPairs.forEach { (number, expected) ->
24+
givenToExpectedPairs.forEach { (givenNumber, expectedString) ->
3125

3226
// Parameterised; Example based test
33-
should("return expected string '$expected' for $number by $type") {
34-
assertThat(function(number)).isEqualTo(expected)
27+
should("return '$expectedString' for $givenNumber with $name implementation") {
28+
assertThat(function(givenNumber)).isEqualTo(expectedString)
3529
}
3630
}
3731

0 commit comments

Comments
 (0)