Skip to content

Commit 51418df

Browse files
committed
最終成果
1 parent 072e1ec commit 51418df

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ version = '1.0-SNAPSHOT'
1313
ext.junitJupiterVersion = '5.12.2'
1414

1515
java {
16-
sourceCompatibility = '23'
16+
sourceCompatibility = '21'
1717
}
1818

1919
tasks.withType(AbstractCompile) each { it.options.encoding = 'UTF-8' }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package tddbc;
2+
3+
public class ClosedInterval {
4+
5+
public int minNum;
6+
public int maxNum;
7+
8+
public ClosedInterval(int minNum,int maxNum) throws Exception {
9+
if (minNum > maxNum) {
10+
throw new Exception("上端は下端より大きい必要があります");
11+
}
12+
this.minNum = minNum;
13+
this.maxNum = maxNum;
14+
}
15+
16+
public boolean isContainedNum(int num){
17+
return num >= this.minNum && num <= this.maxNum;
18+
}
19+
20+
public String returnFormattedString(){
21+
return String.format("[%d,%d]", this.minNum, this.maxNum);
22+
}
23+
}
24+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package tddbc;
2+
3+
import org.junit.jupiter.api.DisplayName;
4+
import org.junit.jupiter.api.Nested;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
public class ClosedIntervalTest {
10+
@Nested
11+
class _上端下端点を設定することができる {
12+
@Test
13+
@DisplayName("有効な値であるため設定できる")
14+
void _setValidNumber ()throws Exception {
15+
int minNum = 10;
16+
int maxNum = 100;
17+
ClosedInterval interval = new ClosedInterval(minNum, maxNum);
18+
assertEquals(minNum, interval.minNum);
19+
assertEquals(maxNum, interval.maxNum);
20+
}
21+
}
22+
23+
@Nested
24+
class _指定された整数が含まれるか判定する{
25+
@Test
26+
@DisplayName("有効な値だとtrueを返す")
27+
void _validValue()throws Exception {
28+
int minNum = 3;
29+
int maxNum = 7;
30+
ClosedInterval interval = new ClosedInterval(minNum,maxNum);
31+
assertTrue(interval.isContainedNum(5));
32+
}
33+
34+
@Test
35+
@DisplayName("無効な値だとfalseを返す")
36+
void _invalidValue()throws Exception {
37+
int minNum = 3;
38+
int maxNum = 7;
39+
ClosedInterval interval = new ClosedInterval(minNum,maxNum);
40+
assertFalse(interval.isContainedNum(0));
41+
assertFalse(interval.isContainedNum(10));
42+
}
43+
44+
@Test
45+
@DisplayName("境界値を正しく判定する")
46+
void _boundaryValue()throws Exception {
47+
int minNum = 3;
48+
int maxNum = 7;
49+
ClosedInterval interval = new ClosedInterval(minNum,maxNum);
50+
assertFalse(interval.isContainedNum(2));
51+
assertFalse(interval.isContainedNum(8));
52+
assertTrue(interval.isContainedNum(3));
53+
assertTrue(interval.isContainedNum(7));
54+
}
55+
}
56+
57+
@Nested
58+
class _整数閉区間を文字列表記で返す{
59+
60+
@Test
61+
@DisplayName("正しい区間を正しい形式の文字列で返すことができる")
62+
void _returnCorrectString() throws Exception{
63+
int minNum = 3;
64+
int maxNum = 7;
65+
ClosedInterval interval = new ClosedInterval(minNum,maxNum);
66+
assertEquals("[3,7]",interval.returnFormattedString());
67+
}
68+
}
69+
}

src/test/java/tddbc/SampleTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public void _should_return_Hello_TDD_BootCamp() throws Exception {
1515
String actual = sut.say();
1616
// Verify
1717
assertEquals("Hello TDD BootCamp!", actual);
18+
19+
1820
}
1921

2022
}

0 commit comments

Comments
 (0)