rework to Azaion.Suite

This commit is contained in:
Alex Bezdieniezhnykh
2024-11-21 13:41:32 +02:00
parent 2cf69f4e4e
commit 5a592e9dbf
76 changed files with 1739 additions and 882 deletions
+21
View File
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>Azaion.Annotator.Test</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Azaion.Annotator\Azaion.Annotator.csproj" />
<ProjectReference Include="..\Azaion.Suite\Azaion.Suite.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.8.0" />
</ItemGroup>
</Project>
+21
View File
@@ -0,0 +1,21 @@
using Azaion.Annotator.DTO;
using Azaion.Common.DTO;
using Xunit;
namespace Azaion.Annotator.Test;
public class DictTest
{
public Dictionary<string, List<YoloLabel>> Annotations = new();
[Fact]
public void DictAddTest()
{
Annotations["sd"] = [new YoloLabel(1, 2, 2, 2, 2)];
Annotations["sd"] =
[
new YoloLabel(1, 2, 2, 2, 2),
new YoloLabel(0, 1, 3, 2, 1)
];
}
}
+16
View File
@@ -0,0 +1,16 @@
using Azaion.Suite;
using Azaion.Suite.Services;
using Xunit;
namespace Azaion.Annotator.Test;
public class HardwareServiceTest
{
[Fact]
public async Task GetHardware_Test()
{
var hardwareService = new HardwareService();
var hw = await hardwareService.GetHardware();
Console.WriteLine(hw);
}
}
+32
View File
@@ -0,0 +1,32 @@
using FluentAssertions;
using Xunit;
using IntervalTree;
namespace Azaion.Annotator.Test;
public class IntervalTreeTest
{
[Theory]
[MemberData(nameof(IntervalTreeTestQueryTestData))]
public void IntervalTreeTestQuery(int second, string[] expected)
{
var mainTree = new IntervalTree<TimeSpan, string>
{
{ TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), "res01" },
{ TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(4), "res02" },
{ TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(7), "res04" },
{ TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(8), "res05" },
};
var result = mainTree.Query(TimeSpan.FromSeconds(second)).ToArray();
result.Should().Equal(expected);
}
public static IEnumerable<object[]> IntervalTreeTestQueryTestData()
{
yield return [1, new[] {"res01"}];
yield return [5, new[] {"res04", "res05"}];
yield return [9, new string[] {}];
}
}
+46
View File
@@ -0,0 +1,46 @@
using System.Diagnostics;
using Azaion.Annotator.Extensions;
using FluentAssertions;
using Xunit;
using ParallelOptions = Azaion.Annotator.Extensions.ParallelOptions;
namespace Azaion.Annotator.Test;
public class ParallelExtTest
{
[Fact]
public async Task ParallelExtWorksOkTest()
{
var list = Enumerable.Range(0, 10).ToList();
var sw = Stopwatch.StartNew();
await ParallelExt.ForEachAsync(list, async (i, cancellationToken) =>
{
await Task.Delay(TimeSpan.FromSeconds(i), cancellationToken);
}, new ParallelOptions
{
CpuUtilPercent = 100,
ProgressUpdateInterval = 1
});
var elapsed = sw.Elapsed;
elapsed.Should().BeLessThan(TimeSpan.FromSeconds(11));
}
[Fact]
public async Task ParallelLibWorksOkTest()
{
var list = Enumerable.Range(0, 10).ToList();
var sw = Stopwatch.StartNew();
await Parallel.ForEachAsync(list, new System.Threading.Tasks.ParallelOptions
{
MaxDegreeOfParallelism = Environment.ProcessorCount,
}, async (i, cancellationToken) =>
{
await Task.Delay(TimeSpan.FromSeconds(i), cancellationToken);
});
var elapsed = sw.Elapsed;
elapsed.Should().BeLessThan(TimeSpan.FromSeconds(11));
}
}