-
Notifications
You must be signed in to change notification settings - Fork 5
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
チュートリアル C#コーディング問題(xUnit版) #48
Draft
Syogo-Suganoya
wants to merge
5
commits into
master
Choose a base branch
from
contents/coding-csharp-xunit
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.
+190
−0
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 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)` メソッドを実装してください。 | ||
|
||
|
||
## 例 | ||
|
||
```cs | ||
Add(2, 3) // 5 | ||
Add(15, 8) // 23 | ||
Add(65, 94) // 159 | ||
``` |
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,5 @@ | ||
{ | ||
"dependencies": { | ||
"track-metatest-tools": "^0.2.0" | ||
} | ||
} |
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,3 @@ | ||
#!/usr/bin/bash | ||
cd /root/src/src/test | ||
dotnet build; |
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,4 @@ | ||
#!/usr/bin/bash | ||
cd /root/src/src/test | ||
dotnet test --logger:xunit; | ||
$(npm bin)/metatest do echo then expand xunit /root/src/src/test/TestResults/TestResults.xml; |
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,7 @@ | ||
public class App | ||
{ | ||
public static int Add(int x, int y) | ||
{ | ||
return x + y; | ||
} | ||
} |
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,7 @@ | ||
public class App | ||
{ | ||
public static int Add(int x, int y) | ||
{ | ||
return -1; | ||
} | ||
} |
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,11 @@ | ||
using System; | ||
|
||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
int x = int.Parse(args[0]); | ||
int y = int.Parse(args[1]); | ||
Console.WriteLine(App.Add(x, y)); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
contents/tutorial/coding-csharp-xunit/src/main/main.csproj
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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<DOTNET_FRAMEWORK_VERSION Condition=" '$(DOTNET_FRAMEWORK_VERSION)' == '' ">net6.0</DOTNET_FRAMEWORK_VERSION> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>$(DOTNET_FRAMEWORK_VERSION)</TargetFramework> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> | ||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,34 @@ | ||
using Xunit; | ||
|
||
public class AppTest | ||
{ | ||
[Fact(DisplayName = "[基本実装] 入力が 2 と 3 のとき、期待された出力結果が得られる")] | ||
public void test_2_3() | ||
{ | ||
int[] input = new int[2] {2, 3}; | ||
__testOutput(input, 5); | ||
} | ||
|
||
[Fact(DisplayName = "[基本実装] 入力が 15 と 8 のとき、期待された出力結果が得られる")] | ||
public void test_15_8() | ||
{ | ||
int[] input = new int[2] {15, 8}; | ||
__testOutput(input, 23); | ||
} | ||
|
||
[Fact(DisplayName = "[基本実装] 入力が 65 と 94 のとき、期待された出力結果が得られる")] | ||
public void test_65_94() | ||
{ | ||
int[] input = new int[2] {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); | ||
|
||
Assert.Equal(expected, result); | ||
} | ||
} |
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,45 @@ | ||
using System; | ||
using System.Threading; | ||
|
||
public class Util | ||
{ | ||
private static int TIMEOUT = 5000; | ||
public static int RunApp(int x, int y) | ||
{ | ||
AppThread appThread = new AppThread(x, y); | ||
Thread th = new Thread(new ThreadStart(appThread.Run)); | ||
try | ||
{ | ||
th.Start(); | ||
th.Join(TIMEOUT); | ||
} | ||
catch (ThreadInterruptedException) | ||
{ | ||
Console.WriteLine("Timeout " + TIMEOUT + "ms"); | ||
} | ||
return appThread.GetResult(); | ||
} | ||
|
||
private class AppThread | ||
{ | ||
private readonly int x; | ||
private readonly int y; | ||
private int result = -1; | ||
|
||
public AppThread(int x, int y) | ||
{ | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public int GetResult() | ||
{ | ||
return this.result; | ||
} | ||
|
||
public void Run() | ||
{ | ||
this.result = App.Add(x, y); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
contents/tutorial/coding-csharp-xunit/src/test/test.csproj
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,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<DOTNET_FRAMEWORK_VERSION Condition=" '$(DOTNET_FRAMEWORK_VERSION)' == '' ">net6.0</DOTNET_FRAMEWORK_VERSION> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>$(DOTNET_FRAMEWORK_VERSION)</TargetFramework> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> | ||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="xunit" Version="2.4.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
<PackageReference Include="XunitXml.TestLogger" Version="3.0.70" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\main\main.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,28 @@ | ||
type: coding | ||
main: src/main/App.cs | ||
editable: | ||
- src/main/App.cs | ||
readonly: | ||
- src/main/Program.cs | ||
- src/test/AppTest.cs | ||
- src/test/Util.cs | ||
- src/main/main.csproj | ||
- src/test/test.csproj | ||
- scripts/* | ||
- package.json | ||
build: sh scripts/build.sh | ||
test: sh scripts/test_run.sh | ||
envConf: | ||
imageName: dotnet | ||
cacheDirs: | ||
- /root/.dotnet | ||
initialize: | ||
commands: | ||
- npm install | ||
solutions: | ||
- src/main/App.cs:solution/App.cs | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memo
timeout制御はThreadで実装できました。