Browse Source

Distance: fix bug in Hamming distance that skipped the head pair #220

pull/225/head
Christoph Ruegg 12 years ago
parent
commit
aa221977da
  1. 4
      src/Numerics/Distance.cs
  2. 19
      src/UnitTests/DistanceTests.cs
  3. 1
      src/UnitTests/UnitTests.csproj

4
src/Numerics/Distance.cs

@ -351,7 +351,7 @@ namespace MathNet.Numerics
{
if (a.Length != b.Length) throw new ArgumentOutOfRangeException("b");
int count = 0;
for (int i = 1; i < a.Length; i++)
for (int i = 0; i < a.Length; i++)
{
if (a[i] != b[i])
{
@ -368,7 +368,7 @@ namespace MathNet.Numerics
{
if (a.Length != b.Length) throw new ArgumentOutOfRangeException("b");
int count = 0;
for (int i = 1; i < a.Length; i++)
for (int i = 0; i < a.Length; i++)
{
if (a[i] != b[i])
{

19
src/UnitTests/DistanceTests.cs

@ -0,0 +1,19 @@
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests
{
[TestFixture]
public class DistanceTests
{
[Test]
public void Hamming()
{
Assert.That(Distance.Hamming(new[] { 0.0, 0.0 }, new[] { 0.0, 0.0 }), Is.EqualTo(0.0));
Assert.That(Distance.Hamming(new[] { 1.0, 0.0 }, new[] { 1.0, 0.0 }), Is.EqualTo(0.0));
Assert.That(Distance.Hamming(new[] { 0.0, 0.0 }, new[] { 1.0, 0.0 }), Is.EqualTo(1.0));
Assert.That(Distance.Hamming(new[] { 0.0, 0.0 }, new[] { 0.0, 1.0 }), Is.EqualTo(1.0));
Assert.That(Distance.Hamming(new[] { 0.0, 0.0 }, new[] { 1.0, 1.0 }), Is.EqualTo(2.0));
Assert.That(Distance.Hamming(new[] { 1.0, 0.0 }, new[] { 0.0, 1.0 }), Is.EqualTo(2.0));
}
}
}

1
src/UnitTests/UnitTests.csproj

@ -85,6 +85,7 @@
<Compile Include="ComplexTests\Complex32Test.TextHandling.cs" />
<Compile Include="ComplexTests\ComplexTest.cs" />
<Compile Include="ComplexTests\ComplexTest.TextHandling.cs" />
<Compile Include="DistanceTests.cs" />
<Compile Include="DistributionTests\CommonDistributionTests.cs" />
<Compile Include="DistributionTests\Continuous\BetaTests.cs" />
<Compile Include="DistributionTests\Continuous\CauchyTests.cs" />

Loading…
Cancel
Save