-
Notifications
You must be signed in to change notification settings - Fork 5
チュートリアル Javaコーディング問題(JUnit版) #41
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
Open
Syogo-Suganoya
wants to merge
11
commits into
master
Choose a base branch
from
contents/coding-java-junit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
155995d
create 作成完了
Syogo-Suganoya 744ef14
Merge branch 'master' into contents/coding-java-junit
Syogo-Suganoya a5e600c
add テスト実行段階のAppTest.java追加
Syogo-Suganoya 6c515c4
fix オプショナルな内容を削除
Syogo-Suganoya 11844fc
fix Main.java削除
Syogo-Suganoya 2a7ad5b
fix レビュー修正
Syogo-Suganoya 5f580d2
use gradle in tutorial/coding-java-junit
snakazawa 4b3a352
delete pom.xml
Syogo-Suganoya 9608ada
Merge pull request #49 from givery-technology/contents/coding-java-ju…
Syogo-Suganoya 3becfd1
fix simpleName 対応
Syogo-Suganoya 74675be
Remove javac and add solution.md
shunjikonishi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,10 @@ | ||
| 整数 `x` と `y` を引数で受け取り、足し算した値を戻り値として返す `add(int x, int y)` メソッドを実装してください。 | ||
|
|
||
|
|
||
| ## 例 | ||
|
|
||
| ``` java | ||
| add(2, 3) // 5 | ||
| add(15, 8) // 23 | ||
| add(65, 94) // 159 | ||
| ``` |
This file contains hidden or 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,26 @@ | ||
| apply plugin: 'java' | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| testImplementation 'org.junit.jupiter:junit-jupiter:5.7.0' | ||
| testImplementation 'org.hamcrest:hamcrest:2.1' | ||
| } | ||
|
|
||
| test { | ||
| useJUnitPlatform() | ||
|
|
||
| testLogging { | ||
| showStandardStreams true | ||
| events 'failed' | ||
| exceptionFormat 'full' | ||
| } | ||
|
|
||
| def index = 1 | ||
| afterTest { desc, result -> | ||
| def str = result.resultType == org.gradle.api.tasks.testing.TestResult.ResultType.SUCCESS ? "ok" : "not ok" | ||
| logger.quiet "${str} ${index++} ${desc.displayName}" | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| `x + y`を返すように修正します |
This file contains hidden or 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,5 @@ | ||
| public class App { | ||
| public static int add(int x, int y) { | ||
| return x + y; | ||
| } | ||
| } |
This file contains hidden or 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,5 @@ | ||
| public class App { | ||
| public static int add(int x, int y) { | ||
| return -1; | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
contents/tutorial/coding-java-junit/src/test/java/AppTest.java
This file contains hidden or 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,38 @@ | ||
| import org.junit.jupiter.api.Timeout; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.DisplayName; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.CoreMatchers.is; | ||
|
|
||
| @Timeout(5) | ||
| public class AppTest { | ||
| @Test | ||
| @DisplayName("[基本実装] 入力が 2 と 3 のとき、期待された出力結果が得られる") | ||
| public void test_2_3() { | ||
| int[] input = {2, 3}; | ||
| __testOutput(input, 5); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("[基本実装] 入力が 15 と 8 のとき、期待された出力結果が得られる") | ||
| public void test_15_8() { | ||
| int[] input = {15, 8}; | ||
| __testOutput(input, 23); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("[基本実装] 入力が 65 と 94 のとき、期待された出力結果が得られる") | ||
| public void test_65_94() { | ||
| int[] input = {65, 94}; | ||
| __testOutput(input, 159); | ||
| } | ||
|
|
||
| private void __testOutput(int[] input, int expected) { | ||
| int x = input[0]; | ||
| int y = input[1]; | ||
| int result = Util.runApp(x, y); | ||
|
|
||
| assertThat(result, is(expected)); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
contents/tutorial/coding-java-junit/src/test/java/Util.java
This file contains hidden or 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,35 @@ | ||
| import static org.junit.jupiter.api.Assertions.fail; | ||
|
|
||
| public class Util { | ||
| private static long TIMEOUT = 5_000; | ||
|
|
||
| public static int runApp(int x, int y) { | ||
| AppThread th = new AppThread(x, y); | ||
| try { | ||
| th.start(); | ||
| th.join(TIMEOUT); | ||
| } catch (InterruptedException e) { | ||
| fail("Timeout " + TIMEOUT + "ms"); | ||
| } | ||
| return th.getResult(); | ||
| } | ||
|
|
||
| private static class AppThread extends Thread { | ||
| private final int x; | ||
| private final int y; | ||
| private int result = -1; | ||
|
|
||
| AppThread(int x, int y) { | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
|
|
||
| int getResult() { | ||
| return this.result; | ||
| } | ||
|
|
||
| public void run() { | ||
| this.result = App.add(x, y); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,22 @@ | ||
| type: coding | ||
| main: src/main/java/App.java | ||
| editable: | ||
| - src/main/java/App.java | ||
| readonly: | ||
| - src/test/java/AppTest.java | ||
| - src/test/java/Util.java | ||
| - build.gradle | ||
| build: gradle compileTest -q | ||
| test: gradle test --warning-mode=none | ||
| envConf: | ||
| imageName: java | ||
| cacheDirs: | ||
| - /root/.m2 | ||
| - /root/.gradle | ||
| solutions: | ||
| - src/main/java/App.java:solution/App.java | ||
| testcases: | ||
| open: 3 | ||
| secret: 0 | ||
| evaluationPoint: | ||
| 基本実装: 基本的なテストケースにおいて、正答が出力できる |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.