Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step1 #5604

Open
wants to merge 3 commits into
base: sweet-info
Choose a base branch
from
Open

Step1 #5604

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/test/java/study/SetTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package study;

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.assertThat;

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 Case 구현
@Test
@DisplayName("Set의 크기 확인")
void setSizeTest() {
assertThat(numbers.size()).isEqualTo(3);
}

@DisplayName("Set에 포함된 값 확인")
@ParameterizedTest
@ValueSource(ints = {1, 2, 3})
void containsTest(int number) {
assertThat(numbers.contains(number)).isTrue();
}

@DisplayName("Set에 포함되지 않은 값 확인")
@ParameterizedTest
@CsvSource(value = {"1:true", "2:true", "3:true", "4:false", "5:false"}, delimiter = ':')
void expectedValueTest(int number, boolean expected) {
assertThat(numbers.contains(number)).isEqualTo(expected);
}
}
42 changes: 42 additions & 0 deletions src/test/java/study/StringTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package study;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class StringTest {
@Test
@DisplayName("split 테스트")
void splitTest() {
String num = "1,2";
String[] splitExactlyStr = num.split(",");
assertThat(splitExactlyStr).containsExactly("1","2");
}

@Test
@DisplayName("substring 테스트")
void substringTest() {
String num = "(1,2)";
String substringStr = num.substring(1, 4);
assertThat(substringStr).isEqualTo("1,2");
}

@Test
@DisplayName("charAt 테스트")
void charAtTest() {
String charStr = "abc";
assertThat(charStr.charAt(1)).isEqualTo('b');
}

@Test
@DisplayName("charAt Exception 테스트")
void charAtExceptionTest() {
String charStr = "abc";
assertThatThrownBy(() -> {
charStr.charAt(4);
}).isInstanceOf(StringIndexOutOfBoundsException.class)
.hasMessageContaining("String index out of range: 4");
}
}
47 changes: 47 additions & 0 deletions src/test/java/study/study/SetTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package study.study;

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.assertThat;

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 Case 구현
@Test
@DisplayName("Set의 크기 확인")
void setSizeTest() {
assertThat(numbers.size()).isEqualTo(3);
}

@DisplayName("Set에 포함된 값 확인")
@ParameterizedTest
@ValueSource(ints = {1, 2, 3})
void containsTest(int number) {
assertThat(numbers.contains(number)).isTrue();
}

@DisplayName("Set에 포함되지 않은 값 확인")
@ParameterizedTest
@CsvSource(value = {"1:true", "2:true", "3:true", "4:false", "5:false"}, delimiter = ':')
void expectedValueTest(int number, boolean expected) {
assertThat(numbers.contains(number)).isEqualTo(expected);
}
}
42 changes: 42 additions & 0 deletions src/test/java/study/study/StringTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package study.study;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class StringTest {
@Test
@DisplayName("split 테스트")
void splitTest() {
String num = "1,2";
String[] splitExactlyStr = num.split(",");
assertThat(splitExactlyStr).containsExactly("1","2");
}

@Test
@DisplayName("substring 테스트")
void substringTest() {
String num = "(1,2)";
String substringStr = num.substring(1, 4);
assertThat(substringStr).isEqualTo("1,2");
}

@Test
@DisplayName("charAt 테스트")
void charAtTest() {
String charStr = "abc";
assertThat(charStr.charAt(1)).isEqualTo('b');
}

@Test
@DisplayName("charAt Exception 테스트")
void charAtExceptionTest() {
String charStr = "abc";
assertThatThrownBy(() -> {
charStr.charAt(4);
}).isInstanceOf(StringIndexOutOfBoundsException.class)
.hasMessageContaining("String index out of range: 4");
}
}