-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/gfoidl.Stochastics.Tests/VectorHelperTests/ReduceMinMax.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Numerics; | ||
using NUnit.Framework; | ||
|
||
namespace gfoidl.Stochastics.Tests.VectorHelperTests | ||
{ | ||
[TestFixture] | ||
public class ReduceMinMax | ||
{ | ||
[Test, Repeat(10)] | ||
public void Min_Max_Vectors_given___correct_Min_Max() | ||
{ | ||
var rnd = new Random(); | ||
var minArr = new double[Vector<double>.Count]; | ||
var maxArr = new double[Vector<double>.Count]; | ||
double min = double.MaxValue; | ||
double max = double.MinValue; | ||
|
||
for (int j = 0; j < Vector<double>.Count; ++j) | ||
{ | ||
minArr[j] = rnd.NextDouble(); | ||
maxArr[j] = rnd.NextDouble(); | ||
|
||
if (minArr[j] < min) min = minArr[j]; | ||
if (maxArr[j] > max) max = maxArr[j]; | ||
} | ||
|
||
double expectedMin = min; | ||
double expectedMax = max; | ||
|
||
var minVec = new Vector<double>(minArr); | ||
var maxVec = new Vector<double>(maxArr); | ||
|
||
VectorHelper.ReduceMinMax(minVec, maxVec, ref min, ref max); | ||
|
||
Assert.AreEqual(expectedMin, min, 1e-10); | ||
Assert.AreEqual(expectedMax, max, 1e-10); | ||
} | ||
} | ||
} |