53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace EvoCalculator.Core.Tests
|
|
{
|
|
public class DoubleArrayComparer : IEqualityComparer<double>
|
|
{
|
|
private readonly double _tolerance = 0.001;
|
|
|
|
public DoubleArrayComparer(double tolerance)
|
|
{
|
|
_tolerance = tolerance;
|
|
}
|
|
|
|
public DoubleArrayComparer()
|
|
{
|
|
}
|
|
|
|
public bool Equals(double x, double y)
|
|
{
|
|
return Math.Abs(x - y) < _tolerance;
|
|
}
|
|
|
|
public int GetHashCode(double obj)
|
|
{
|
|
return obj.GetHashCode();
|
|
}
|
|
}
|
|
|
|
public class DecimalArrayComparer : IEqualityComparer<decimal>
|
|
{
|
|
private readonly double _tolerance = 0.001;
|
|
|
|
public DecimalArrayComparer(double tolerance)
|
|
{
|
|
_tolerance = tolerance;
|
|
}
|
|
|
|
public DecimalArrayComparer()
|
|
{
|
|
}
|
|
|
|
public bool Equals(decimal x, decimal y)
|
|
{
|
|
return Math.Abs(x - y) < (decimal)_tolerance;
|
|
}
|
|
|
|
public int GetHashCode(decimal obj)
|
|
{
|
|
return obj.GetHashCode();
|
|
}
|
|
}
|
|
} |