gist トレーニング
Last active
February 4, 2018 11:21
-
-
Save f7q/6dde86b15aeafa0d422c299bbea954f8 to your computer and use it in GitHub Desktop.
git clone
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
.svn/ | |
.vs/ | |
bin/ | |
obj/ | |
*.xproj.user | |
*.lock.json | |
artifacts/ | |
tools/ | |
*.nupkg |
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
using System; | |
using System.Text; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using System.Collections.Generic; | |
using System.Collections.Concurrent; | |
namespace Message | |
{ | |
public class Stracture | |
{ | |
public string Message { get; set; } = string.Empty; | |
public DateTime CreateDateTime { get; set; } | |
public DateTime UpdateDateTime { get; set; } | |
/// <summary> | |
/// 分子 | |
/// </summary> | |
public int Molecule { get; set; } | |
/// <summary> | |
/// 分母 | |
/// </summary> | |
public int Denominator { get; set; } | |
public override string ToString() | |
{ | |
string builder = string.Format(@"{0:hh\:mm\:ss} {1}({2:#,#}/{3:#,#})", | |
((TimeSpan)(UpdateDateTime - CreateDateTime)), | |
Message, | |
Molecule, | |
Denominator | |
); | |
var per = Molecule / Denominator * (99); | |
if (per >= 99) | |
{ | |
builder = builder + "完了"; | |
} | |
else | |
{ | |
builder = builder + "処理中"; | |
} | |
return builder; | |
} | |
} | |
public class QueMessage | |
{ | |
private LinkedList<Stracture> queue { get; set; } | |
public QueMessage() | |
{ | |
this.queue = new LinkedList<Stracture>(); | |
} | |
public QueMessage Enqueue(Stracture stracture) | |
{ | |
stracture.CreateDateTime = new DateTime(2000, 8, 1, 13, 30, 0); ; | |
stracture.UpdateDateTime = new DateTime(2000, 8, 1, 13, 50, 10); ; | |
queue.AddFirst(stracture); | |
return this; | |
} | |
public QueMessage Update(int molecule) | |
{ | |
Stracture obj = queue.First.Value; | |
obj.UpdateDateTime = new DateTime(2000, 8, 1, 13, 59, 10); | |
obj.Molecule = molecule; | |
queue.First.Value = obj; | |
return this; | |
} | |
public override string ToString() | |
{ | |
StringBuilder builder = new StringBuilder(); | |
var obj = queue.Last; | |
while (obj != null) | |
{ | |
var val = obj.Value; | |
builder.AppendLine(obj.Value.ToString()); | |
obj = obj.Previous; | |
} | |
return builder.ToString(); | |
} | |
} | |
} |
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFramework>netstandard2.0</TargetFramework> | |
</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
Microsoft Visual Studio Solution File, Format Version 12.00 | |
# Visual Studio 15 | |
VisualStudioVersion = 15.0.27130.2024 | |
MinimumVisualStudioVersion = 15.0.26124.0 | |
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QueMessage", "src\QueMessage.csproj", "{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}" | |
EndProject | |
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QueMessageTest", "Test\QueMessageTest.csproj", "{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}" | |
ProjectSection(ProjectDependencies) = postProject | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96} = {99AF19D6-8C2F-49C0-8604-9B4E0327EB96} | |
EndProjectSection | |
EndProject | |
Global | |
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |
Debug|Any CPU = Debug|Any CPU | |
Debug|x64 = Debug|x64 | |
Debug|x86 = Debug|x86 | |
Release|Any CPU = Release|Any CPU | |
Release|x64 = Release|x64 | |
Release|x86 = Release|x86 | |
EndGlobalSection | |
GlobalSection(ProjectConfigurationPlatforms) = postSolution | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}.Debug|Any CPU.Build.0 = Debug|Any CPU | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}.Debug|x64.ActiveCfg = Debug|Any CPU | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}.Debug|x64.Build.0 = Debug|Any CPU | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}.Debug|x86.ActiveCfg = Debug|Any CPU | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}.Debug|x86.Build.0 = Debug|Any CPU | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}.Release|Any CPU.ActiveCfg = Release|Any CPU | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}.Release|Any CPU.Build.0 = Release|Any CPU | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}.Release|x64.ActiveCfg = Release|Any CPU | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}.Release|x64.Build.0 = Release|Any CPU | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}.Release|x86.ActiveCfg = Release|Any CPU | |
{99AF19D6-8C2F-49C0-8604-9B4E0327EB96}.Release|x86.Build.0 = Release|Any CPU | |
{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |
{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}.Debug|Any CPU.Build.0 = Debug|Any CPU | |
{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}.Debug|x64.ActiveCfg = Debug|Any CPU | |
{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}.Debug|x64.Build.0 = Debug|Any CPU | |
{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}.Debug|x86.ActiveCfg = Debug|Any CPU | |
{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}.Debug|x86.Build.0 = Debug|Any CPU | |
{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}.Release|Any CPU.ActiveCfg = Release|Any CPU | |
{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}.Release|Any CPU.Build.0 = Release|Any CPU | |
{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}.Release|x64.ActiveCfg = Release|Any CPU | |
{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}.Release|x64.Build.0 = Release|Any CPU | |
{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}.Release|x86.ActiveCfg = Release|Any CPU | |
{3E6BC01B-D529-40BE-9DE0-E7ACC819202B}.Release|x86.Build.0 = Release|Any CPU | |
EndGlobalSection | |
GlobalSection(SolutionProperties) = preSolution | |
HideSolutionNode = FALSE | |
EndGlobalSection | |
GlobalSection(ExtensibilityGlobals) = postSolution | |
SolutionGuid = {734057C7-D35A-4429-9A83-584FE3787560} | |
EndGlobalSection | |
EndGlobal |
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
using System; | |
using Xunit; | |
using Message; | |
using System.Collections.Generic; | |
namespace Message.Test | |
{ | |
public class QueMessageTest | |
{ | |
[Fact] | |
public void Test1() | |
{ | |
var obj = new QueMessage(); | |
var str = obj.Enqueue(new Stracture { Message = "処理中...", Molecule = 1, Denominator = 5000 }) | |
.Update(2) | |
.ToString(); | |
Assert.Equal(@"00:29:10 処理中...(2/5,000)処理中 | |
", str); | |
} | |
[Fact(DisplayName = "2行")] | |
[Trait("Category", "Arithmetic")] | |
[Trait("Priority", "2")] | |
public void Test2() | |
{ | |
var obj = new QueMessage(); | |
obj.Enqueue(new Stracture { Message = "完了", Molecule = 500, Denominator = 500 }); | |
obj.Update(500); | |
obj.Enqueue(new Stracture { Message = "処理中..", Molecule = 250, Denominator = 5000 }); | |
obj.Update(250); | |
var str = obj | |
.ToString(); | |
Assert.Equal(@"00:29:10 完了(500/500)完了 | |
00:29:10 処理中..(250/5,000)処理中 | |
", str); | |
} | |
[Fact(DisplayName = "3行")] | |
[Trait("Category", "Arithmetic")] | |
[Trait("Priority", "2")] | |
public void Test3() | |
{ | |
var obj = new QueMessage(); | |
obj.Enqueue(new Stracture { Message = "処理中...", Denominator = 500 }); | |
obj.Update(1); | |
//obj.Enqueue(new Stracture { Message = "処理中..", Denominator = 500 }); | |
obj.Update(500); | |
obj.Enqueue(new Stracture { Message = "処理中.", Denominator = 800 }); | |
obj.Update(400); | |
obj.Update(400); | |
obj.Update(600); | |
var str = obj | |
.ToString(); | |
Assert.Equal(@"00:29:10 処理中...(500/500)完了 | |
00:29:10 処理中.(600/800)処理中 | |
", str); | |
} | |
[Fact(DisplayName = "4行")] | |
[Trait("Category", "Arithmetic")] | |
[Trait("Priority", "2")] | |
public void Test4() | |
{ | |
var obj = new QueMessage(); | |
obj.Enqueue(new Stracture { Message = "処理中...", Denominator = 500 }); | |
obj.Update(1); | |
//obj.Enqueue(new Stracture { Message = "処理中..", Denominator = 500 }); | |
obj.Update(500); | |
obj.Enqueue(new Stracture { Message = "処理中.", Denominator = 800 }); | |
obj.Update(400); | |
obj.Update(400); | |
obj.Update(800); | |
obj.Enqueue(new Stracture { Message = "処理中..", Denominator = 800 }); | |
obj.Update(400); | |
obj.Update(400); | |
obj.Update(600); | |
var str = obj | |
.ToString(); | |
Assert.Equal(@"00:29:10 処理中...(500/500)完了 | |
00:29:10 処理中.(800/800)完了 | |
00:29:10 処理中..(600/800)処理中 | |
", str); | |
} | |
} | |
} |
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFramework>netcoreapp2.0</TargetFramework> | |
<IsPackable>false</IsPackable> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" /> | |
<PackageReference Include="xunit" Version="2.3.1" /> | |
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | |
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> | |
</ItemGroup> | |
<ItemGroup> | |
<ProjectReference Include="..\src\QueMessage.csproj" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment