-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MessageQueue unit tests & fix a few things
- Loading branch information
1 parent
5e9355c
commit b0fbfbb
Showing
5 changed files
with
153 additions
and
3 deletions.
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,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CSharpier.MsBuild" Version="0.27.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.2.0" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.2.0" /> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="xunit" Version="2.6.6" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ButterSTT\ButterSTT.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,112 @@ | ||
using ButterSTT.TextProcessing; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace ButterSTT.MessageSystem.Tests | ||
{ | ||
public class MessageQueueTests | ||
{ | ||
private readonly ITestOutputHelper output; | ||
|
||
public MessageQueueTests(ITestOutputHelper output) | ||
{ | ||
this.output = output; | ||
} | ||
|
||
[Fact()] | ||
public void TimeoutTest() | ||
{ | ||
var queue = new MessageQueue { WordTime = TimeSpan.Zero }; | ||
|
||
var firstMessage = "Testing the queue system."; | ||
queue.CurParagraph = EnglishTextParser.ParseParagraph(firstMessage); | ||
queue.FinishCurrentParagraph(); | ||
var curMessage = queue.GetCurrentMessage(); | ||
output.WriteLine($"First message: \"{curMessage}\""); | ||
Assert.Equal(firstMessage, curMessage); | ||
|
||
var secondMessage = "Second test message."; | ||
queue.CurParagraph = EnglishTextParser.ParseParagraph(secondMessage); | ||
queue.FinishCurrentParagraph(); | ||
curMessage = queue.GetCurrentMessage(); | ||
output.WriteLine($"Second message: \"{curMessage}\""); | ||
Assert.Equal(secondMessage, curMessage); | ||
} | ||
|
||
[Fact()] | ||
public void CombineTest() | ||
{ | ||
var queue = new MessageQueue { WordTime = TimeSpan.Zero }; | ||
|
||
var firstMessage = "Testing the queue system."; | ||
queue.CurParagraph = EnglishTextParser.ParseParagraph(firstMessage); | ||
queue.FinishCurrentParagraph(); | ||
var secondMessage = "Second test message."; | ||
queue.CurParagraph = EnglishTextParser.ParseParagraph(secondMessage); | ||
queue.FinishCurrentParagraph(); | ||
|
||
var curMessage = queue.GetCurrentMessage(); | ||
output.WriteLine($"Combined message: \"{curMessage}\""); | ||
Assert.Equal($"{firstMessage} {secondMessage}", curMessage); | ||
} | ||
|
||
[Fact()] | ||
public void RealtimeTest() | ||
{ | ||
var queue = new MessageQueue { WordTime = TimeSpan.Zero }; | ||
|
||
// Likely incomplete word | ||
queue.CurParagraph = EnglishTextParser.ParseParagraph("Testing th"); | ||
var curMessage = queue.GetCurrentMessage(); | ||
output.WriteLine($"First message: \"{curMessage}\""); | ||
Assert.Equal("Testing", curMessage); | ||
|
||
// Complete sentence | ||
var secondMessage = "Testing the queue system."; | ||
queue.CurParagraph = EnglishTextParser.ParseParagraph(secondMessage); | ||
curMessage = queue.GetCurrentMessage(); | ||
output.WriteLine($"Second message: \"{curMessage}\""); | ||
Assert.Equal(secondMessage, curMessage); | ||
|
||
// Complete and partial sentence with one complete word | ||
var thirdMessage = "Testing the queue system. Second "; | ||
queue.CurParagraph = EnglishTextParser.ParseParagraph(thirdMessage); | ||
curMessage = queue.GetCurrentMessage(); | ||
output.WriteLine($"Third message: \"{curMessage}\""); | ||
Assert.Equal(thirdMessage.Trim(), curMessage); | ||
|
||
// Two complete sentences | ||
var fourthMessage = "Testing the queue system. Second test message."; | ||
queue.CurParagraph = EnglishTextParser.ParseParagraph(fourthMessage); | ||
curMessage = queue.GetCurrentMessage(); | ||
output.WriteLine($"Fourth message: \"{curMessage}\""); | ||
Assert.Equal(fourthMessage, curMessage); | ||
} | ||
|
||
// Not yet implemented, should fail | ||
[Fact()] | ||
public void RealtimeAppendingTest() | ||
{ | ||
var queue = new MessageQueue { WordTime = TimeSpan.MaxValue }; | ||
|
||
// Initial message, fully completed | ||
var firstMessage = "Testing the queue system."; | ||
queue.CurParagraph = EnglishTextParser.ParseParagraph(firstMessage); | ||
queue.FinishCurrentParagraph(); | ||
|
||
// Add a partial sentence to it | ||
var secondMessage = "Second test "; | ||
queue.CurParagraph = EnglishTextParser.ParseParagraph(secondMessage); | ||
var curMessage = queue.GetCurrentMessage(); | ||
output.WriteLine($"Appended message: \"{curMessage}\""); | ||
Assert.Equal($"{firstMessage} {secondMessage.Trim()}", curMessage); | ||
|
||
// Replace the partial message | ||
var thirdMessage = "Second test message."; | ||
queue.CurParagraph = EnglishTextParser.ParseParagraph(thirdMessage); | ||
curMessage = queue.GetCurrentMessage(); | ||
output.WriteLine($"Appended message: \"{curMessage}\""); | ||
Assert.Equal($"{firstMessage} {thirdMessage}", curMessage); | ||
} | ||
} | ||
} |
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
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
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