diff --git a/Directory.Packages.props b/Directory.Packages.props index 169d68f8..00afc240 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,7 +6,6 @@ - diff --git a/tests/Whisper.net.Tests/FactoryTests.cs b/tests/Whisper.net.Tests/FactoryTests.cs index 854ca6da..c604a192 100644 --- a/tests/Whisper.net.Tests/FactoryTests.cs +++ b/tests/Whisper.net.Tests/FactoryTests.cs @@ -1,5 +1,4 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT -using FluentAssertions; using Whisper.net.Logger; using Xunit; using Xunit.Abstractions; @@ -34,7 +33,7 @@ public void GetSupportedLanguages_ShouldReturnAll() { var languages = WhisperFactory.GetSupportedLanguages().ToList(); - languages.Should().HaveCount(99); + Assert.Equal(99, languages.Count); } [Fact] @@ -46,7 +45,7 @@ public void CreateBuilder_WithNoModel_ShouldThrow() .CreateBuilder(); }; - loadingMethod.Should().Throw(); + Assert.Throws(() => loadingMethod()); } [Fact] @@ -58,7 +57,7 @@ public void CreateBuilder_WithCorruptedModel_ShouldThrow() .CreateBuilder(); }; - loadingMethod.Should().Throw(); + Assert.Throws(loadingMethod); } [Fact] @@ -66,7 +65,7 @@ public void CreateBuilder_WithFileModel_ShouldReturnBuilder() { using var factory = WhisperFactory.FromPath(model.ModelFile); var builder = factory.CreateBuilder(); - builder.Should().NotBeNull(); + Assert.NotNull(builder); } [Fact] @@ -75,7 +74,7 @@ public void CreateBuilder_WithMemoryModel_ShouldReturnBuilder() var memoryBuffer = File.ReadAllBytes(model.ModelFile); using var factory = WhisperFactory.FromBuffer(memoryBuffer); var builder = factory.CreateBuilder(); - builder.Should().NotBeNull(); + Assert.NotNull(builder); } [Fact] @@ -89,7 +88,7 @@ public void CreateBuilder_WithDisposedFactory_ShouldThrow() factory.CreateBuilder(); }; - loadingMethod.Should().Throw(); + Assert.Throws(loadingMethod); } private void OnLog(WhisperLogLevel logLevel, string? message) diff --git a/tests/Whisper.net.Tests/ProcessAsyncFunctionalTests.cs b/tests/Whisper.net.Tests/ProcessAsyncFunctionalTests.cs index e0b38fea..8080d4a0 100644 --- a/tests/Whisper.net.Tests/ProcessAsyncFunctionalTests.cs +++ b/tests/Whisper.net.Tests/ProcessAsyncFunctionalTests.cs @@ -1,10 +1,9 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT -using FluentAssertions; using Xunit; namespace Whisper.net.Tests; -public class ProcessAsyncFunctionalTests(TinyModelFixture model) : IClassFixture +public partial class ProcessAsyncFunctionalTests(TinyModelFixture model) : IClassFixture { [Fact] public async Task TestHappyFlowAsync() @@ -32,13 +31,12 @@ public async Task TestHappyFlowAsync() segmentsEnumerated.Add(data); } - segmentsEnumerated.Should().BeEquivalentTo(segments); - - segments.Should().HaveCountGreaterThan(0); - progress.Should().BeInAscendingOrder().And.HaveCountGreaterThan(1); - encoderBegins.Should().HaveCount(1); - - segments.Should().Contain(segmentData => segmentData.Text.Contains("nation should commit")); + Assert.Equal(segments, segmentsEnumerated); + Assert.True(segments.Count > 0); + Assert.True(progress.SequenceEqual(progress.OrderBy(x => x))); + Assert.True(progress.Count > 1); + Assert.Single(encoderBegins); + Assert.Contains(segments, segmentData => segmentData.Text.Contains("nation should commit")); } [Fact] @@ -80,13 +78,11 @@ public async Task ProcessAsync_Cancelled_WillCancellTheProcessing_AndDispose_Wil await processor.DisposeAsync(); - segmentsEnumerated.Should().BeEmpty(); - - segments.Should().HaveCount(1); - encoderBegins.Should().HaveCount(1); - taskCanceledException.Should().NotBeNull(); - - segments.Should().Contain(segmentData => segmentData.Text.Contains("nation should commit")); + Assert.Empty(segmentsEnumerated); + Assert.Single( segments); + Assert.Single( encoderBegins); + Assert.NotNull(taskCanceledException); + Assert.Contains(segments, segmentData => segmentData.Text.Contains("nation should commit")); } [Fact] @@ -105,7 +101,7 @@ public async Task ProcessAsync_WhenJunkChunkExists_ProcessCorrectly() segments.Add(segment); } - segments.Should().HaveCountGreaterThanOrEqualTo(1); + Assert.True(segments.Count >= 1); } [Fact] @@ -124,13 +120,12 @@ public async Task ProcessAsync_WhenMultichannel_ProcessCorrectly() segments.Add(segment); } - segments.Should().HaveCountGreaterThanOrEqualTo(1); + Assert.True(segments.Count >= 1); } [Fact] public async Task ProcessAsync_CalledMultipleTimes_Serially_WillCompleteEverytime() { - var segments1 = new List(); var segments2 = new List(); var segments3 = new List(); @@ -158,7 +153,9 @@ public async Task ProcessAsync_CalledMultipleTimes_Serially_WillCompleteEverytim segments3.Add(segment); } - segments1.Should().BeEquivalentTo(segments2); - segments2.Should().BeEquivalentTo(segments3); + Assert.True(segments1.SequenceEqual(segments2, new SegmentDataComparer())); + Assert.True(segments2.SequenceEqual(segments3, new SegmentDataComparer())); + } + } diff --git a/tests/Whisper.net.Tests/ProcessFunctionalTests.cs b/tests/Whisper.net.Tests/ProcessFunctionalTests.cs index 60ac813c..87b3b0b9 100644 --- a/tests/Whisper.net.Tests/ProcessFunctionalTests.cs +++ b/tests/Whisper.net.Tests/ProcessFunctionalTests.cs @@ -1,9 +1,8 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT -using System.ComponentModel; using System.Runtime.InteropServices; -using FluentAssertions; using Xunit; +using static Whisper.net.Tests.ProcessAsyncFunctionalTests; namespace Whisper.net.Tests; @@ -31,11 +30,13 @@ public async Task TestHappyFlow() using var fileReader = await TestDataProvider.OpenFileStreamAsync("kennedy.wav"); processor.Process(fileReader); - segments.Should().HaveCountGreaterThan(0); - encoderBegins.Should().HaveCount(1); - progress.Should().BeInAscendingOrder().And.HaveCountGreaterThan(1); + Assert.True(segments.Count >= 1); + Assert.True(encoderBegins.Count >= 1); + Assert.True(progress.SequenceEqual(progress.OrderBy(s => s))); - segments.Should().Contain(segmentData => segmentData.Text.Contains("nation should commit")); + Assert.True(progress.Count >= 1); + + Assert.Contains(segments, s => s.Text.Contains("nation should commit")); } [Fact(Skip = "Skipping for now, for some reason not working on ios, see #308")] @@ -57,8 +58,8 @@ public async Task TestCancelEncoder() using var fileReader = await TestDataProvider.OpenFileStreamAsync("kennedy.wav"); processor.Process(fileReader); - segments.Should().HaveCount(0); - encoderBegins.Should().HaveCount(1); + Assert.True(segments.Count == 0); + Assert.Single(encoderBegins); } [Fact] @@ -80,10 +81,11 @@ public async Task TestAutoDetectLanguageWithRomanian() { segments.Add(segment); } - segments.Should().HaveCountGreaterThan(0); - encoderBegins.Should().HaveCountGreaterThanOrEqualTo(1); - segments.Should().AllSatisfy(s => s.Language.Should().Be("ro")); - segments.Should().Contain(segmentData => segmentData.Text.Contains("efectua")); + + Assert.True(segments.Count >= 1); + Assert.True(encoderBegins.Count >= 1); + Assert.True(segments.All(s => s.Language == "ro")); + Assert.Contains(segments, s => s.Text.Contains("efectua")); } [Fact] @@ -100,7 +102,7 @@ public async Task Process_WhenMultichannel_ProcessCorrectly() using var fileReader = await TestDataProvider.OpenFileStreamAsync("multichannel.wav"); processor.Process(fileReader); - segments.Should().HaveCountGreaterThanOrEqualTo(1); + Assert.True(segments.Count >= 1); } [Fact] @@ -132,8 +134,8 @@ public async Task Process_CalledMultipleTimes_Serially_WillCompleteEverytime() using var fileReader3 = await TestDataProvider.OpenFileStreamAsync("kennedy.wav"); processor.Process(fileReader3); - segments1.Should().BeEquivalentTo(segments2); - segments2.Should().BeEquivalentTo(segments3); + Assert.True(segments1.SequenceEqual(segments2, new SegmentDataComparer())); + Assert.True(segments2.SequenceEqual(segments3, new SegmentDataComparer())); } [Theory] @@ -200,10 +202,11 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", using var fileReader = await TestDataProvider.OpenFileStreamAsync("kennedy.wav"); processor.Process(fileReader); - segments.Should().HaveCountGreaterThan(0); - encoderBegins.Should().HaveCount(1); - progress.Should().BeInAscendingOrder().And.HaveCountGreaterThan(1); + Assert.True(segments.Count > 0); + Assert.Single(encoderBegins); - segments.Should().Contain(segmentData => segmentData.Text.Contains("nation should commit")); + Assert.Equal(progress, progress.OrderBy(p => p)); + Assert.True(progress.Count > 1); + Assert.Contains(segments, segmentData => segmentData.Text.Contains("nation should commit")); } } diff --git a/tests/Whisper.net.Tests/ProcessQuantizedTests.cs b/tests/Whisper.net.Tests/ProcessQuantizedTests.cs index 38597fc0..d43aeb50 100644 --- a/tests/Whisper.net.Tests/ProcessQuantizedTests.cs +++ b/tests/Whisper.net.Tests/ProcessQuantizedTests.cs @@ -1,6 +1,5 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT -using FluentAssertions; using Xunit; namespace Whisper.net.Tests; @@ -28,10 +27,10 @@ public async Task TestHappyFlowQuantized() using var fileReader = await TestDataProvider.OpenFileStreamAsync("bush.wav"); processor.Process(fileReader); - segments.Should().HaveCountGreaterThan(0); - encoderBegins.Should().HaveCountGreaterThanOrEqualTo(1); - progress.Should().BeInAscendingOrder().And.HaveCountGreaterThan(1); - - segments.Should().Contain(segmentData => segmentData.Text.Contains("My fellow Americans")); + Assert.True(segments.Count > 0); + Assert.True(encoderBegins.Count >= 1); + Assert.True(progress.Count >= 1); + Assert.Equal(progress, progress.OrderBy(s => s)); + Assert.Contains(segments, segmentData => segmentData.Text.Contains("My fellow Americans")); } } diff --git a/tests/Whisper.net.Tests/SegmentDataComparer.cs b/tests/Whisper.net.Tests/SegmentDataComparer.cs new file mode 100644 index 00000000..80ec38ff --- /dev/null +++ b/tests/Whisper.net.Tests/SegmentDataComparer.cs @@ -0,0 +1,23 @@ +// Licensed under the MIT license: https://opensource.org/licenses/MIT + +namespace Whisper.net.Tests; +public partial class ProcessAsyncFunctionalTests +{ + public class SegmentDataComparer : IEqualityComparer + { + public bool Equals(SegmentData? x, SegmentData? y) + { + if (x == null || y == null) + { + return false; + } + return x.Text == y.Text && x.MinProbability == y.MinProbability && x.Probability == y.Probability && x.Start == y.Start && x.End == y.End; // Compare by relevant properties + } + + public int GetHashCode(SegmentData obj) + { + return obj.Text.GetHashCode(); + } + } + +} diff --git a/tests/Whisper.net.Tests/Whisper.net.Tests.csproj b/tests/Whisper.net.Tests/Whisper.net.Tests.csproj index 6a58b281..63ab9665 100644 --- a/tests/Whisper.net.Tests/Whisper.net.Tests.csproj +++ b/tests/Whisper.net.Tests/Whisper.net.Tests.csproj @@ -10,7 +10,6 @@ -