-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76daa0f
commit e7fe337
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
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,49 @@ | ||
package study; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
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.*; | ||
|
||
@DisplayName("Set Collection에 대한 학습 테스트") | ||
public class SetTest { | ||
private Set<Integer> numbers; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
numbers = new HashSet<>(); | ||
numbers.add(1); | ||
numbers.add(1); | ||
numbers.add(2); | ||
numbers.add(3); | ||
} | ||
|
||
@Test | ||
@DisplayName("Set size 확인") | ||
public void setTest01() throws Exception { | ||
assertThat(numbers.size()).isEqualTo(3); | ||
} | ||
|
||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {1, 2, 3}) | ||
@DisplayName("Set 값 존재여부 확인") | ||
public void setTest02(int inputNumber) throws Exception { | ||
assertThat(numbers.contains(inputNumber)).isTrue(); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = {"0:false","1:true","2:true","3:true","4:false"}, delimiter = ':') | ||
@DisplayName("Set 값 존재 확인") | ||
public void setTest03(int inputNumber, boolean isFree) throws Exception { | ||
assertThat(numbers.contains(inputNumber)).isEqualTo(isFree); | ||
} | ||
} |
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,51 @@ | ||
package study; | ||
|
||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
// String 클래스에 대한 학습 테스트 | ||
@DisplayName("String 클래스에 대한 학습 테스트") | ||
public class StringTest { | ||
|
||
@Test | ||
@DisplayName("문자열 1,2 나누기") | ||
public void stringTest01() throws Exception { | ||
String[] result = "1,2".split(","); | ||
// assertThat(result).contains("1", "2"); | ||
assertThat(result).containsExactly("1", "2"); | ||
} | ||
|
||
@Test | ||
@DisplayName("문자열 1, 나누기") | ||
public void stringTest02() throws Exception { | ||
String[] result = "1,".split(","); | ||
assertThat(result).containsExactly("1"); | ||
} | ||
|
||
@Test | ||
@DisplayName("문자열 (1,2) substring 으로 ()제거하기") | ||
public void stringTest03() throws Exception { | ||
String data = "(1,2)"; | ||
String result = data.substring(1, data.length()-1); | ||
assertThat(result).isEqualTo("1,2"); | ||
} | ||
|
||
@Test | ||
@DisplayName("문자열 abc 뽑아내기") | ||
public void stringTest04() throws Exception { | ||
String data = "abc"; | ||
|
||
assertEquals(data.charAt(0), 'a'); | ||
assertEquals(data.charAt(1), 'b'); | ||
assertEquals(data.charAt(2), 'c'); | ||
|
||
assertThatThrownBy(() -> { | ||
data.charAt(3); | ||
}).isInstanceOf(IndexOutOfBoundsException.class) | ||
.hasMessageContaining("String index out of range: 3"); | ||
} | ||
} |