Skip to content

Commit fa3199f

Browse files
committed
Update the Unit test for KNN
1 parent f6aa804 commit fa3199f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Algorithms.Tests/MachineLearning/KNearestNeighborsTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ public void AddSample_NullFeatures_ThrowsException()
2525
public void Predict_NoTrainingData_ThrowsException()
2626
{
2727
var knn = new KNearestNeighbors<string>(1);
28-
Assert.Throws<InvalidOperationException>(() => knn.Predict(new double[] { 1.0 }));
28+
Assert.Throws<InvalidOperationException>(() => knn.Predict(new[] { 1.0 }));
2929
}
3030

3131
[Test]
3232
public void Predict_NullFeatures_ThrowsException()
3333
{
3434
var knn = new KNearestNeighbors<string>(1);
35-
knn.AddSample(new double[] { 1.0 }, "A");
35+
knn.AddSample(new[] { 1.0 }, "A");
3636
double[]? features = null;
3737
Assert.Throws<ArgumentNullException>(() => knn.Predict(features!));
3838
}
3939

4040
[Test]
4141
public void EuclideanDistance_DifferentLengths_ThrowsException()
4242
{
43-
Assert.Throws<ArgumentException>(() => KNearestNeighbors<string>.EuclideanDistance(new double[] { 1.0 }, new double[] { 1.0, 2.0 }));
43+
Assert.Throws<ArgumentException>(() => KNearestNeighbors<string>.EuclideanDistance(new[] { 1.0 }, new[] { 1.0, 2.0 }));
4444
}
4545

4646
[Test]
@@ -59,7 +59,7 @@ public void Predict_SingleNeighbor_CorrectLabel()
5959
var knn = new KNearestNeighbors<string>(1);
6060
knn.AddSample(new double[] { 1.0, 2.0 }, "A");
6161
knn.AddSample(new double[] { 3.0, 4.0 }, "B");
62-
var label = knn.Predict(new double[] { 1.1, 2.1 });
62+
var label = knn.Predict(new[] { 1.1, 2.1 });
6363
Assert.That(label, Is.EqualTo("A"));
6464
}
6565

@@ -70,7 +70,7 @@ public void Predict_MajorityVote_CorrectLabel()
7070
knn.AddSample(new double[] { 0.0, 0.0 }, "A");
7171
knn.AddSample(new double[] { 0.1, 0.1 }, "A");
7272
knn.AddSample(new double[] { 1.0, 1.0 }, "B");
73-
var label = knn.Predict(new double[] { 0.05, 0.05 });
73+
var label = knn.Predict(new[] { 0.05, 0.05 });
7474
Assert.That(label, Is.EqualTo("A"));
7575
}
7676

@@ -80,7 +80,7 @@ public void Predict_TieBreaker_ReturnsConsistentLabel()
8080
var knn = new KNearestNeighbors<string>(2);
8181
knn.AddSample(new double[] { 0.0, 0.0 }, "A");
8282
knn.AddSample(new double[] { 1.0, 1.0 }, "B");
83-
var label = knn.Predict(new double[] { 0.5, 0.5 });
84-
Assert.That(label, Is.EqualTo("B"));
83+
var label = knn.Predict(new[] { 0.5, 0.5 });
84+
Assert.That(label, Is.EqualTo("A"));
8585
}
8686
}

0 commit comments

Comments
 (0)