-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathStringCalculatorTest.kt
57 lines (51 loc) · 1.96 KB
/
StringCalculatorTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import calculator.StringCalculator
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatRuntimeException
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.CsvSource
import org.junit.jupiter.params.provider.NullAndEmptySource
import org.junit.jupiter.params.provider.ValueSource
class StringCalculatorTest {
@ParameterizedTest
@DisplayName(value = "쉼표, 콜론을 구분자로 분리한다.")
@CsvSource(value = ["'1,2',3", "'1:3',4"])
fun stringSplitTest(
inputString: String,
expacted: Int,
) {
assertThat(StringCalculator.calculate(inputString)).isEqualTo(expacted)
}
@ParameterizedTest
@DisplayName(value = "커스텀 구분자가 있으면 그 구분자로 분리한다.")
@CsvSource(value = ["'//;\n1;2',3", "'//_\n1_3',4"])
fun customSplitTest(
inputString: String,
expacted: Int,
) {
assertThat(StringCalculator.calculate(inputString)).isEqualTo(expacted)
}
@ParameterizedTest
@DisplayName(value = "음수 및 숫자 아닌값은 에러처리한다.")
@CsvSource(value = ["'-1:2',3", "'//_\n1@3',4"])
fun SplitfailTest(
inputString: String,
expacted: Int,
) {
assertThatRuntimeException().isThrownBy {
StringCalculator.calculate(inputString)
}
}
@DisplayName(value = "숫자 하나를 문자열로 입력할 경우 해당 숫자를 반환한다.")
@ParameterizedTest
@ValueSource(strings = ["1"])
fun oneNumber(text: String) {
assertThat(StringCalculator.calculate(text)).isSameAs(Integer.parseInt(text));
}
@DisplayName(value = "빈 문자열 또는 null 값을 입력할 경우 0을 반환해야 한다.")
@ParameterizedTest
@NullAndEmptySource
fun emptyOrNull(text: String?) {
assertThat(StringCalculator.calculate(text)).isZero();
}
}