Skip to content

Commit bd9a9b1

Browse files
committed
Added more tests
1 parent 727900f commit bd9a9b1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

core-kotlin-modules/core-kotlin-strings-5/src/test/kotlin/com/baeldung/extractnumber/NumberExtractUnitTest.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.baeldung.extractnumber
22

33
import org.junit.jupiter.api.Assertions
4+
import org.junit.jupiter.api.Test
45
import org.junit.jupiter.params.ParameterizedTest
56
import org.junit.jupiter.params.provider.CsvSource
67

@@ -47,6 +48,8 @@ class NumberExtractUnitTest {
4748
"another string with 456 and 789, 456",
4849
"string 123-234, 123",
4950
"no numbers,",
51+
"3 4 50 numbers6, 3",
52+
"123456789large numbers0, 123456789"
5053
)
5154
fun `extract first occurrence of number from string using regex`(str: String, expected: String?) {
5255
val number = extractUsingRegex(str)
@@ -59,6 +62,8 @@ class NumberExtractUnitTest {
5962
"another string with 456 and 789, 456:789",
6063
"string 123-234, 123:234",
6164
"no numbers,",
65+
"3 4 50 numbers6, 3:4:50:6",
66+
"123456789large numbers0, 123456789:0"
6267
)
6368
fun `extract all occurrences of numbers from string using regex`(str: String, expected: String?) {
6469
val numbers = extractMultipleUsingRegex(str)
@@ -72,6 +77,8 @@ class NumberExtractUnitTest {
7277
"another string with 456 and 789, 456:789",
7378
"string 123-234, 123:234",
7479
"no numbers,",
80+
"3 4 50 numbers6, 3:4:50:6",
81+
"123456789large numbers0, 123456789:0"
7582
)
7683
fun `extract all occurrences of numbers from string using split and regex`(str: String, expected: String?) {
7784
val numbers = extractNumbersUsingSplitAndRegex(str)
@@ -85,11 +92,31 @@ class NumberExtractUnitTest {
8592
"another string with 456 and 789, 456:789",
8693
"string 123-234, 123:234",
8794
"no numbers,",
95+
"3 4 50 numbers6, 3:4:50:6",
96+
"123456789large numbers0, 123456789:0"
8897
)
8998
fun `extract all occurrences of numbers from string using loop`(str: String, expected: String?) {
9099
val numbers = extractNumbersUsingLoop(str)
91100
val expectedList = expected?.split(":")?.map { it.toLong() } ?: emptyList()
92101
Assertions.assertEquals(expectedList, numbers)
93102
}
94103

104+
@Test
105+
fun `check empty string scenario for loop`() {
106+
val numbers = extractNumbersUsingLoop("")
107+
Assertions.assertIterableEquals(numbers, listOf<Long>())
108+
}
109+
110+
@Test
111+
fun `check empty string scenario for split`() {
112+
val numbers = extractNumbersUsingSplitAndRegex("")
113+
Assertions.assertIterableEquals(numbers, listOf<Long>())
114+
}
115+
116+
@Test
117+
fun `check empty string scenario for regex`() {
118+
val numbers = extractMultipleUsingRegex("")
119+
Assertions.assertIterableEquals(numbers, listOf<Long>())
120+
}
121+
95122
}

0 commit comments

Comments
 (0)