Skip to content

Commit

Permalink
Add secondary Sample constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyAkinshin committed Nov 23, 2023
1 parent c3b6b21 commit d26bef9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Perfolizer/Perfolizer.Tests/Common/SampleTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Perfolizer.Common;

namespace Perfolizer.Tests.Common;

public class SampleTests
{
[Fact]
public void SampleCtorTest()
{
string expected = "1;2;3";
string Format(Sample s) => string.Join(";", s.Values);

Assert.Equal(expected, Format(new Sample(new[] { 1.0, 2.0, 3.0 })));
Assert.Equal(expected, Format(new Sample(new[] { 1, 2, 3 })));
Assert.Equal(expected, Format(new Sample(new[] { 1L, 2L, 3L })));
}
}
8 changes: 8 additions & 0 deletions src/Perfolizer/Perfolizer/Common/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ public Sample(IReadOnlyList<double> values, IReadOnlyList<double> weights)
});
}

public Sample(IEnumerable<int> values) : this(values.Select(x => (double)x).ToList())
{
}

public Sample(IEnumerable<long> values) : this(values.Select(x => (double)x).ToList())
{
}

private static bool IsSorted(IReadOnlyList<double> list)
{
for (int i = 0; i < list.Count - 1; i++)
Expand Down

0 comments on commit d26bef9

Please sign in to comment.