You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core-kotlin-modules/core-kotlin-strings-5/src/test/kotlin/com/baeldung/extractnumber/NumberExtractUnitTest.kt
+27Lines changed: 27 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
packagecom.baeldung.extractnumber
2
2
3
3
importorg.junit.jupiter.api.Assertions
4
+
importorg.junit.jupiter.api.Test
4
5
importorg.junit.jupiter.params.ParameterizedTest
5
6
importorg.junit.jupiter.params.provider.CsvSource
6
7
@@ -47,6 +48,8 @@ class NumberExtractUnitTest {
47
48
"another string with 456 and 789, 456",
48
49
"string 123-234, 123",
49
50
"no numbers,",
51
+
"3 4 50 numbers6, 3",
52
+
"123456789large numbers0, 123456789"
50
53
)
51
54
fun`extract first occurrence of number from string using regex`(str:String, expected:String?) {
52
55
val number = extractUsingRegex(str)
@@ -59,6 +62,8 @@ class NumberExtractUnitTest {
59
62
"another string with 456 and 789, 456:789",
60
63
"string 123-234, 123:234",
61
64
"no numbers,",
65
+
"3 4 50 numbers6, 3:4:50:6",
66
+
"123456789large numbers0, 123456789:0"
62
67
)
63
68
fun`extract all occurrences of numbers from string using regex`(str:String, expected:String?) {
64
69
val numbers = extractMultipleUsingRegex(str)
@@ -72,6 +77,8 @@ class NumberExtractUnitTest {
72
77
"another string with 456 and 789, 456:789",
73
78
"string 123-234, 123:234",
74
79
"no numbers,",
80
+
"3 4 50 numbers6, 3:4:50:6",
81
+
"123456789large numbers0, 123456789:0"
75
82
)
76
83
fun`extract all occurrences of numbers from string using split and regex`(str:String, expected:String?) {
77
84
val numbers = extractNumbersUsingSplitAndRegex(str)
@@ -85,11 +92,31 @@ class NumberExtractUnitTest {
85
92
"another string with 456 and 789, 456:789",
86
93
"string 123-234, 123:234",
87
94
"no numbers,",
95
+
"3 4 50 numbers6, 3:4:50:6",
96
+
"123456789large numbers0, 123456789:0"
88
97
)
89
98
fun`extract all occurrences of numbers from string using loop`(str:String, expected:String?) {
90
99
val numbers = extractNumbersUsingLoop(str)
91
100
val expectedList = expected?.split(":")?.map { it.toLong() } ?: emptyList()
0 commit comments