-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #141 | extract base logic from _ValuesTests * #141 | adjust EnglishValuesTest to new solution * example of changed tests (#1) * poc refactor to handle removed values and added * remove unused check from tests * fix tests * move converters into field * change types * fix types * #141 | cleanup code * #141 | changes after CR --------- Co-authored-by: Julia Glaszka <[email protected]>
- Loading branch information
Showing
2 changed files
with
213 additions
and
123 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
src/test/groovy/pl/allegro/finance/tradukisto/internal/languages/AbstractValuesTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package pl.allegro.finance.tradukisto.internal.languages | ||
|
||
import pl.allegro.finance.tradukisto.internal.IntegerToStringConverter | ||
import pl.allegro.finance.tradukisto.internal.LongToStringConverter | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
abstract class AbstractValuesTest extends Specification { | ||
abstract ValuesTestData testData | ||
abstract IntegerToStringConverter intConverter | ||
abstract LongToStringConverter longConverter | ||
|
||
private static final OBLIGATORY_INT_VALUES = [ | ||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, | ||
11, 12, 13, 14, 15, 16, 17, 18, 19, | ||
10, 20, 30, 40, 50, 60, 70, 80, 90, | ||
21, 37, 43, 58, 69, 76, 82, 95, | ||
100, 200, 300, 400, 500, 600, 700, 800, 900, | ||
111, 272, 387, 448, 569, 625, 782, 895, 999, | ||
1_000, 2_000, 3_000, 4_000, 5_000, 7_634, 11_000, | ||
15_000, 21_000, 24_190, 653_000, 123_454, 700_000, 999_999, | ||
1_000_000, 2_000_000, 5_000_000, 23_437_219, | ||
100_000_000, 123_456_789, 322_089_890, | ||
1_000_000_000, 2_147_483_647, | ||
] | ||
|
||
private static final OBLIGATORY_LONG_VALUES = [ | ||
5_000_000_000, | ||
1_000_000_000_000, | ||
2_000_000_000_000, | ||
5_000_000_000_000, | ||
1_000_000_000_000_000, | ||
2_000_000_000_000_000, | ||
5_000_000_000_000_000, | ||
1_000_000_000_000_000_000, | ||
2_000_000_000_000_000_000, | ||
Long.MAX_VALUE | ||
] | ||
|
||
@Unroll | ||
def "should convert integer #input to #output"() { | ||
expect: | ||
intConverter.asWords(input) == output | ||
|
||
where: | ||
input << getTestData().getIntegerTranslations().keySet() | ||
output << getTestData().getIntegerTranslations().values() | ||
} | ||
|
||
@Unroll | ||
def "should convert long #input to #output"() { | ||
expect: | ||
longConverter.asWords(input) == output | ||
|
||
where: | ||
input << getTestData().getLongTranslations().keySet() | ||
output << getTestData().getLongTranslations().values() | ||
} | ||
|
||
static class ValuesTestData { | ||
private final Map<Integer, String> integerTranslations | ||
private final Map<Long, String> longTranslations | ||
|
||
ValuesTestData(Map<Integer, String> integerTranslations, Map<Long, String> longTranslations) { | ||
this.integerTranslations = prepareIntegerInput(integerTranslations) | ||
this.longTranslations = prepareLongInput(longTranslations) | ||
} | ||
|
||
Map<Integer, String> getIntegerTranslations() { | ||
return integerTranslations | ||
} | ||
|
||
Map<Long, String> getLongTranslations() { | ||
return longTranslations | ||
} | ||
|
||
private static prepareIntegerInput(Map<Integer, String> intWords) { | ||
OBLIGATORY_INT_VALUES.stream() | ||
.forEach { | ||
intWords.putIfAbsent(it, "⚠️Please specify expected output") | ||
} | ||
return intWords.sort { it.key } | ||
} | ||
|
||
private static prepareLongInput(Map<Long, String> longWords) { | ||
OBLIGATORY_LONG_VALUES.stream() | ||
.forEach { | ||
longWords.putIfAbsent(it, "⚠️Please specify expected output") | ||
} | ||
return longWords.sort { it.key } | ||
} | ||
} | ||
} |
243 changes: 120 additions & 123 deletions
243
.../groovy/pl/allegro/finance/tradukisto/internal/languages/english/EnglishValuesTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,129 @@ | ||
package pl.allegro.finance.tradukisto.internal.languages.english | ||
|
||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
import pl.allegro.finance.tradukisto.internal.languages.AbstractValuesTest | ||
|
||
import static pl.allegro.finance.tradukisto.internal.Container.englishContainer | ||
|
||
class EnglishValuesTest extends Specification { | ||
|
||
static intConverter = englishContainer().getIntegerConverter() | ||
static longConverter = englishContainer().getLongConverter() | ||
|
||
@Unroll | ||
def "should convert #value to '#words' in English"() { | ||
expect: | ||
intConverter.asWords(value) == words | ||
|
||
where: | ||
value | words | ||
0 | "zero" | ||
1 | "one" | ||
2 | "two" | ||
3 | "three" | ||
4 | "four" | ||
5 | "five" | ||
6 | "six" | ||
7 | "seven" | ||
8 | "eight" | ||
9 | "nine" | ||
|
||
11 | "eleven" | ||
12 | "twelve" | ||
13 | "thirteen" | ||
14 | "fourteen" | ||
15 | "fifteen" | ||
16 | "sixteen" | ||
17 | "seventeen" | ||
18 | "eighteen" | ||
19 | "nineteen" | ||
|
||
10 | "ten" | ||
20 | "twenty" | ||
30 | "thirty" | ||
40 | "forty" | ||
50 | "fifty" | ||
60 | "sixty" | ||
70 | "seventy" | ||
80 | "eighty" | ||
90 | "ninety" | ||
|
||
21 | "twenty-one" | ||
37 | "thirty-seven" | ||
43 | "forty-three" | ||
58 | "fifty-eight" | ||
69 | "sixty-nine" | ||
76 | "seventy-six" | ||
82 | "eighty-two" | ||
95 | "ninety-five" | ||
|
||
100 | "one hundred" | ||
200 | "two hundred" | ||
300 | "three hundred" | ||
400 | "four hundred" | ||
500 | "five hundred" | ||
600 | "six hundred" | ||
700 | "seven hundred" | ||
800 | "eight hundred" | ||
900 | "nine hundred" | ||
|
||
111 | "one hundred eleven" | ||
272 | "two hundred seventy-two" | ||
387 | "three hundred eighty-seven" | ||
448 | "four hundred forty-eight" | ||
569 | "five hundred sixty-nine" | ||
625 | "six hundred twenty-five" | ||
782 | "seven hundred eighty-two" | ||
895 | "eight hundred ninety-five" | ||
999 | "nine hundred ninety-nine" | ||
|
||
1_000 | "one thousand" | ||
2_000 | "two thousand" | ||
3_000 | "three thousand" | ||
4_000 | "four thousand" | ||
5_000 | "five thousand" | ||
7_634 | "seven thousand six hundred thirty-four" | ||
11_000 | "eleven thousand" | ||
15_000 | "fifteen thousand" | ||
21_000 | "twenty-one thousand" | ||
24_190 | "twenty-four thousand one hundred ninety" | ||
653_000 | "six hundred fifty-three thousand" | ||
123_454 | "one hundred twenty-three thousand four hundred fifty-four" | ||
700_000 | "seven hundred thousand" | ||
999_999 | "nine hundred ninety-nine thousand nine hundred ninety-nine" | ||
|
||
1_000_000 | "one million" | ||
2_000_000 | "two million" | ||
5_000_000 | "five million" | ||
23_437_219 | "twenty-three million four hundred thirty-seven thousand two hundred nineteen" | ||
100_000_000 | "one hundred million" | ||
123_456_789 | "one hundred twenty-three million four hundred fifty-six thousand seven hundred eighty-nine" | ||
322_089_890 | "three hundred twenty-two million eighty-nine thousand eight hundred ninety" | ||
|
||
1_000_000_000 | "one billion" | ||
2_147_483_647 | "two billion one hundred forty-seven million four hundred eighty-three thousand six hundred " + | ||
"forty-seven" | ||
class EnglishValuesTest extends AbstractValuesTest { | ||
|
||
def setup() { | ||
intConverter = englishContainer().integerConverter | ||
longConverter = englishContainer().longConverter | ||
} | ||
|
||
@Unroll | ||
def "should convert long #value to '#words' in English"() { | ||
expect: | ||
longConverter.asWords(value) == words | ||
|
||
where: | ||
value | words | ||
5_000_000_000 | "five billion" | ||
|
||
1_000_000_000_000 | "one trillion" | ||
2_000_000_000_000 | "two trillion" | ||
5_000_000_000_000 | "five trillion" | ||
|
||
1_000_000_000_000_000 | "one quadrillion" | ||
2_000_000_000_000_000 | "two quadrillion" | ||
5_000_000_000_000_000 | "five quadrillion" | ||
|
||
1_000_000_000_000_000_000 | "one quintillion" | ||
2_000_000_000_000_000_000 | "two quintillion" | ||
Long.MAX_VALUE | "nine quintillion two hundred twenty-three quadrillion " + | ||
"three hundred seventy-two trillion thirty-six billion " + | ||
"eight hundred fifty-four million seven hundred seventy-five thousand " + | ||
"eight hundred seven" | ||
@Override | ||
ValuesTestData getTestData() { | ||
testData = new ValuesTestData( | ||
integerTranslations, | ||
longTranslations | ||
) | ||
} | ||
|
||
private static integerTranslations = [ | ||
0 : "zero", | ||
1 : "one", | ||
2 : "two", | ||
3 : "three", | ||
4 : "four", | ||
5 : "five", | ||
6 : "six", | ||
7 : "seven", | ||
8 : "eight", | ||
9 : "nine", | ||
|
||
11 : "eleven", | ||
12 : "twelve", | ||
13 : "thirteen", | ||
14 : "fourteen", | ||
15 : "fifteen", | ||
16 : "sixteen", | ||
17 : "seventeen", | ||
18 : "eighteen", | ||
19 : "nineteen", | ||
|
||
10 : "ten", | ||
20 : "twenty", | ||
30 : "thirty", | ||
40 : "forty", | ||
50 : "fifty", | ||
60 : "sixty", | ||
70 : "seventy", | ||
80 : "eighty", | ||
90 : "ninety", | ||
|
||
21 : "twenty-one", | ||
37 : "thirty-seven", | ||
43 : "forty-three", | ||
58 : "fifty-eight", | ||
69 : "sixty-nine", | ||
76 : "seventy-six", | ||
82 : "eighty-two", | ||
95 : "ninety-five", | ||
|
||
100 : "one hundred", | ||
200 : "two hundred", | ||
300 : "three hundred", | ||
400 : "four hundred", | ||
500 : "five hundred", | ||
600 : "six hundred", | ||
700 : "seven hundred", | ||
800 : "eight hundred", | ||
900 : "nine hundred", | ||
|
||
111 : "one hundred eleven", | ||
272 : "two hundred seventy-two", | ||
387 : "three hundred eighty-seven", | ||
448 : "four hundred forty-eight", | ||
569 : "five hundred sixty-nine", | ||
625 : "six hundred twenty-five", | ||
782 : "seven hundred eighty-two", | ||
895 : "eight hundred ninety-five", | ||
999 : "nine hundred ninety-nine", | ||
|
||
1_000 : "one thousand", | ||
2_000 : "two thousand", | ||
3_000 : "three thousand", | ||
4_000 : "four thousand", | ||
5_000 : "five thousand", | ||
7_634 : "seven thousand six hundred thirty-four", | ||
11_000 : "eleven thousand", | ||
15_000 : "fifteen thousand", | ||
21_000 : "twenty-one thousand", | ||
24_190 : "twenty-four thousand one hundred ninety", | ||
653_000 : "six hundred fifty-three thousand", | ||
123_454 : "one hundred twenty-three thousand four hundred fifty-four", | ||
700_000 : "seven hundred thousand", | ||
999_999 : "nine hundred ninety-nine thousand nine hundred ninety-nine", | ||
|
||
1_000_000 : "one million", | ||
2_000_000 : "two million", | ||
5_000_000 : "five million", | ||
23_437_219 : "twenty-three million four hundred thirty-seven thousand two hundred nineteen", | ||
100_000_000 : "one hundred million", | ||
123_456_789 : "one hundred twenty-three million four hundred fifty-six thousand seven hundred eighty-nine", | ||
322_089_890 : "three hundred twenty-two million eighty-nine thousand eight hundred ninety", | ||
|
||
1_000_000_000: "one billion", | ||
2_147_483_647: "two billion one hundred forty-seven million four hundred eighty-three thousand six hundred " + | ||
"forty-seven" | ||
] | ||
|
||
private static longTranslations = [ | ||
5_000_000_000 : "five billion", | ||
|
||
1_000_000_000_000 : "one trillion", | ||
2_000_000_000_000 : "two trillion", | ||
5_000_000_000_000 : "five trillion", | ||
|
||
1_000_000_000_000_000 : "one quadrillion", | ||
2_000_000_000_000_000 : "two quadrillion", | ||
5_000_000_000_000_000 : "five quadrillion", | ||
|
||
1_000_000_000_000_000_000: "one quintillion", | ||
2_000_000_000_000_000_000: "two quintillion", | ||
(Long.MAX_VALUE) : "nine quintillion two hundred twenty-three quadrillion " + | ||
"three hundred seventy-two trillion thirty-six billion " + | ||
"eight hundred fifty-four million seven hundred seventy-five thousand " + | ||
"eight hundred seven" | ||
] | ||
} |