< Summary

Class:KDTreeTest
Assembly:bamlab.test.editmode
File(s):/github/workspace/Assets/Tests/EditMode/KDTreeTest.cs
Covered lines:0
Uncovered lines:39
Coverable lines:39
Total lines:55
Line coverage:0% (0 of 39)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:4
Method coverage:0% (0 of 4)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TestEmpty()0%6200%
TestSingle()0%6200%
TestNearestNeighborWithinPoints()0%20400%
TestNearestNeighborAroundPoints()0%20400%

File(s)

/github/workspace/Assets/Tests/EditMode/KDTreeTest.cs

#LineLine coverage
 1using NUnit.Framework;
 2using System;
 3using System.Collections.Generic;
 4using System.Linq;
 5using UnityEngine;
 6using UnityEngine.TestTools;
 7
 8public class KDTreeTest {
 9  [Test]
 010  public void TestEmpty() {
 011    KDTree<Vector2> tree = new KDTree<Vector2>(new List<Vector2>(), (Vector2 point) => point);
 012    Assert.AreEqual(tree.NearestNeighbor(Vector2.zero), Vector2.zero);
 013    Assert.AreEqual(tree.NearestNeighbor(new Vector2(1, 1)), Vector2.zero);
 014  }
 15
 16  [Test]
 017  public void TestSingle() {
 018    KDTree<Vector2> tree =
 019        new KDTree<Vector2>(new List<Vector2> { new Vector2(1, 1) }, (Vector2 point) => point);
 020    Assert.AreEqual(tree.NearestNeighbor(Vector2.zero), new Vector2(1, 1));
 021    Assert.AreEqual(tree.NearestNeighbor(new Vector2(1, 6)), new Vector2(1, 1));
 022    Assert.AreEqual(tree.NearestNeighbor(new Vector2(3, 2)), new Vector2(1, 1));
 023    Assert.AreEqual(tree.NearestNeighbor(new Vector2(9, 9)), new Vector2(1, 1));
 024  }
 25
 26  [Test]
 027  public void TestNearestNeighborWithinPoints() {
 028    List<Vector2> points = new List<Vector2>();
 029    for (int i = 0; i <= 10; ++i) {
 030      for (int j = 0; j <= 10; ++j) {
 031        points.Add(new Vector2(i, j));
 032      }
 033    }
 034    KDTree<Vector2> tree = new KDTree<Vector2>(points, (Vector2 point) => point);
 035    Assert.AreEqual(tree.NearestNeighbor(Vector2.zero), Vector2.zero);
 036    Assert.AreEqual(tree.NearestNeighbor(new Vector2(1, 6)), new Vector2(1, 6));
 037    Assert.AreEqual(tree.NearestNeighbor(new Vector2(3, 2)), new Vector2(3, 2));
 038    Assert.AreEqual(tree.NearestNeighbor(new Vector2(9, 9)), new Vector2(9, 9));
 039  }
 40
 41  [Test]
 042  public void TestNearestNeighborAroundPoints() {
 043    List<Vector2> points = new List<Vector2>();
 044    for (int i = 0; i <= 10; ++i) {
 045      for (int j = 0; j <= 10; ++j) {
 046        points.Add(new Vector2(i, j));
 047      }
 048    }
 049    KDTree<Vector2> tree = new KDTree<Vector2>(points, (Vector2 point) => point);
 050    Assert.AreEqual(tree.NearestNeighbor(Vector2.zero), Vector2.zero);
 051    Assert.AreEqual(tree.NearestNeighbor(new Vector2(1.4f, 1.2f)), new Vector2(1, 1));
 052    Assert.AreEqual(tree.NearestNeighbor(new Vector2(2.7f, 2.2f)), new Vector2(3, 2));
 053    Assert.AreEqual(tree.NearestNeighbor(new Vector2(9.05f, 8.61f)), new Vector2(9, 9));
 054  }
 55}