Files
annotations/Azaion.Test/DictTest.cs
T
Alex Bezdieniezhnykh 1bc1d81fde small fixes, renames
2025-01-15 16:41:42 +02:00

42 lines
1.0 KiB
C#

using Azaion.Common.DTO;
using FluentAssertions;
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)
];
}
[Theory]
[InlineData(null, 0)]
[InlineData(new int[]{}, 0)]
[InlineData(new int[]{1, 2, 5}, 1)]
[InlineData(new int[]{3, -2, 5}, -2)]
[InlineData(new int[]{3, -2, 2, 4}, 2)]
[InlineData(new int[]{3, -2, -100, 2, 4}, 2)]
public void ComputeClosestToZeroTest(int[] ts, int expected) =>
ComputeClosestToZero(ts).Should().Be(expected);
private int ComputeClosestToZero(int[]? ts)
{
if (ts is null || ts.Length == 0)
return 0;
return ts
.OrderBy(Math.Abs)
.ThenByDescending(x => x) // 2 -2 3 4 -10
.FirstOrDefault();
}
}