mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:16:30 +00:00
42 lines
1.0 KiB
C#
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();
|
|
}
|
|
} |