Minor changes in names and extracted method, etc.
This commit is contained in:
@ -22,8 +22,9 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class KNearestNeighbourTest
|
||||
{
|
||||
List<Vector> positives;
|
||||
List<Vector> negatives;
|
||||
private List<Vector> positives;
|
||||
private List<Vector> negatives;
|
||||
private DistanceFunction distanceFunction;
|
||||
|
||||
@BeforeAll
|
||||
void initLearnData()
|
||||
@ -41,12 +42,14 @@ class KNearestNeighbourTest
|
||||
new Vector(8d, 2d),
|
||||
new Vector(9d, 0d))
|
||||
);
|
||||
|
||||
this.distanceFunction = (a, b) -> Math.abs(a.get(0) - b.get(0)) + Math.abs(a.get(1) - b.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCorrectClassForVectorWithKEquals3()
|
||||
{
|
||||
var kNearestNeighbour = new KNearestNeighbour((a ,b) -> Math.abs(a.get(0) - b.get(0)) + Math.abs(a.get(1) - b.get(1)), 3);
|
||||
var kNearestNeighbour = new KNearestNeighbour(this.distanceFunction, 3);
|
||||
kNearestNeighbour.learn(this.positives, this.negatives);
|
||||
var vector = new Vector(8, 3.5);
|
||||
|
||||
@ -59,7 +62,7 @@ class KNearestNeighbourTest
|
||||
@Test
|
||||
public void shouldReturnCorrectClassForVectorWithKEquals5()
|
||||
{
|
||||
var kNearestNeighbour = new KNearestNeighbour((a ,b) -> Math.abs(a.get(0) - b.get(0)) + Math.abs(a.get(1) - b.get(1)), 5);
|
||||
var kNearestNeighbour = new KNearestNeighbour(this.distanceFunction, 5);
|
||||
kNearestNeighbour.learn(this.positives, this.negatives);
|
||||
var vector = new Vector(8, 3.5);
|
||||
|
||||
|
Reference in New Issue
Block a user