Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions test/Microsoft.ML.Functional.Tests/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.ML.Data;
using Microsoft.ML.Functional.Tests.Datasets;
using Xunit;
using Xunit.Sdk;

namespace Microsoft.ML.Functional.Tests
{
Expand Down Expand Up @@ -268,6 +269,33 @@ public static void AssertMetricsStatistics(RegressionMetricsStatistics metrics)
AssertMetricStatistics(metrics.LossFunction);
}

/// <summary>
/// Assert that two float arrays are not equal.
/// </summary>
/// <param name="array1">An array of floats.</param>
/// <param name="array2">An array of floats.</param>
public static void AssertNotEqual(float[] array1, float[] array2)
{
Assert.NotNull(array1);
Assert.NotNull(array2);
Assert.Equal(array1.Length, array2.Length);

bool mismatch = false;
for (int i = 0; i < array1.Length; i++)
try
{
// Use Assert to test for equality rather than
// to roll our own float equality checker.
Assert.Equal(array1[i], array2[i]);
}
catch(EqualException)
{
mismatch = true;
break;
}
Assert.True(mismatch);
}

/// <summary>
/// Verify that a float array has no NaNs or infinities.
/// </summary>
Expand Down
Loading