Skip to content

Commit

Permalink
학습 테스트 실습 추가 (#1843)
Browse files Browse the repository at this point in the history
  • Loading branch information
loop-study committed Mar 2, 2021
1 parent 76daa0f commit e7fe337
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/test/java/study/SetTest.java
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);
}
}
51 changes: 51 additions & 0 deletions src/test/java/study/StringTest.java
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");
}
}

0 comments on commit e7fe337

Please sign in to comment.