-
Notifications
You must be signed in to change notification settings - Fork 905
Expand file tree
/
Copy pathStringTest.java
More file actions
99 lines (77 loc) · 2.09 KB
/
StringTest.java
File metadata and controls
99 lines (77 loc) · 2.09 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package study;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.HashSet;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
public class StringTest {
private Set<Integer> numbers;
@Test
void replace() {
String actual = "abc".replace("b", "d");
assertThat(actual).isEqualTo("adc");
}
@Test
void test1A() {
String actual = "1,2";
String[] actual1 = actual.split(",");
assertThat(actual1[0]).contains("1");
}
@Test
void test1B() {
String actual = "1";
String[] actual1 = actual.split(",");
assertThat(actual1).containsExactly("1");
}
@Test
void test2() {
String actual = "(1,2)";
String actual1 = actual.substring(1,4);
assertThat(actual1).isEqualTo("1,2");
}
@Test
void test3() {
String actual = "abc";
char a = actual.charAt(1);
assertThat(a).isEqualTo('b');
}
@Test
@BeforeEach
void test4A() {
numbers = new HashSet<>();
numbers.add(1);
numbers.add(1);
numbers.add(2);
numbers.add(3);
assertThat(numbers.size()).isEqualTo(3);
}
@ParameterizedTest
@ValueSource(ints = {1,2,3})
void test4B(int number) {
numbers = new HashSet<>();
numbers.add(1);
numbers.add(1);
numbers.add(2);
numbers.add(3);
// assertThat(numbers.contains(1)).isTrue();
// assertThat(numbers.contains(2)).isTrue();
// assertThat(numbers.contains(3)).isTrue();
assertThat(numbers.contains(number)).isTrue();
}
// TODO
// @ParameterizedTest
// @CsvSource(value = {"7", "4", "5"})
// void test4C(int number) {
//
// numbers = new HashSet<>();
// numbers.add(1);
// numbers.add(1);
// numbers.add(2);
// numbers.add(3);
//
// asser
// }
}