diff --git a/src/Numerics/Distance.cs b/src/Numerics/Distance.cs index 425c6152..05ddd6ff 100644 --- a/src/Numerics/Distance.cs +++ b/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]) { diff --git a/src/UnitTests/DistanceTests.cs b/src/UnitTests/DistanceTests.cs new file mode 100644 index 00000000..b18e80a6 --- /dev/null +++ b/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)); + } + } +} diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index cd1e2369..069ba696 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -85,6 +85,7 @@ +