mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 10:56:31 +00:00
small fixes, renames
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Azaion.Common.DTO;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace Azaion.Annotator.Test;
|
||||
@@ -17,4 +18,25 @@ public class DictTest
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user