Skip to content

Commit

Permalink
Removed fluentassertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Hanea committed Feb 15, 2025
1 parent a56fcf4 commit 6d741fb
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 55 deletions.
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<PackageVersion Include="System.Memory" Version="4.6.0" />
<PackageVersion Include="System.IO.Compression" Version="4.3.0" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="FluentAssertions" Version="7.0.0" />
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<!-- Tests -->
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
Expand Down
13 changes: 6 additions & 7 deletions tests/Whisper.net.Tests/FactoryTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,7 +33,7 @@ public void GetSupportedLanguages_ShouldReturnAll()
{
var languages = WhisperFactory.GetSupportedLanguages().ToList();

languages.Should().HaveCount(99);
Assert.Equal(99, languages.Count);
}

[Fact]
Expand All @@ -46,7 +45,7 @@ public void CreateBuilder_WithNoModel_ShouldThrow()
.CreateBuilder();
};

loadingMethod.Should().Throw<WhisperModelLoadException>();
Assert.Throws<WhisperModelLoadException>(() => loadingMethod());
}

[Fact]
Expand All @@ -58,15 +57,15 @@ public void CreateBuilder_WithCorruptedModel_ShouldThrow()
.CreateBuilder();
};

loadingMethod.Should().Throw<WhisperModelLoadException>();
Assert.Throws<WhisperModelLoadException>(loadingMethod);
}

[Fact]
public void CreateBuilder_WithFileModel_ShouldReturnBuilder()
{
using var factory = WhisperFactory.FromPath(model.ModelFile);
var builder = factory.CreateBuilder();
builder.Should().NotBeNull();
Assert.NotNull(builder);
}

[Fact]
Expand All @@ -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]
Expand All @@ -89,7 +88,7 @@ public void CreateBuilder_WithDisposedFactory_ShouldThrow()
factory.CreateBuilder();
};

loadingMethod.Should().Throw<ObjectDisposedException>();
Assert.Throws<ObjectDisposedException>(loadingMethod);
}

private void OnLog(WhisperLogLevel logLevel, string? message)
Expand Down
39 changes: 18 additions & 21 deletions tests/Whisper.net.Tests/ProcessAsyncFunctionalTests.cs
Original file line number Diff line number Diff line change
@@ -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<TinyModelFixture>
public partial class ProcessAsyncFunctionalTests(TinyModelFixture model) : IClassFixture<TinyModelFixture>
{
[Fact]
public async Task TestHappyFlowAsync()
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -105,7 +101,7 @@ public async Task ProcessAsync_WhenJunkChunkExists_ProcessCorrectly()
segments.Add(segment);
}

segments.Should().HaveCountGreaterThanOrEqualTo(1);
Assert.True(segments.Count >= 1);
}

[Fact]
Expand All @@ -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<SegmentData>();
var segments2 = new List<SegmentData>();
var segments3 = new List<SegmentData>();
Expand Down Expand Up @@ -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()));

}

}
41 changes: 22 additions & 19 deletions tests/Whisper.net.Tests/ProcessFunctionalTests.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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")]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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"));
}
}
11 changes: 5 additions & 6 deletions tests/Whisper.net.Tests/ProcessQuantizedTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Licensed under the MIT license: https://opensource.org/licenses/MIT

using FluentAssertions;
using Xunit;

namespace Whisper.net.Tests;
Expand Down Expand Up @@ -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"));
}
}
23 changes: 23 additions & 0 deletions tests/Whisper.net.Tests/SegmentDataComparer.cs
Original file line number Diff line number Diff line change
@@ -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<SegmentData>
{
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();
}
}

}
1 change: 0 additions & 1 deletion tests/Whisper.net.Tests/Whisper.net.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
Expand Down

0 comments on commit 6d741fb

Please sign in to comment.