< Summary

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

Metrics

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

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]
 110  public void TestEmpty() {
 111    KDTree<Vector2> tree = new KDTree<Vector2>(new List<Vector2>(), (Vector2 point) => point);
 112    Assert.AreEqual(tree.NearestNeighbor(Vector2.zero), Vector2.zero);
 113    Assert.AreEqual(tree.NearestNeighbor(new Vector2(1, 1)), Vector2.zero);
 114  }
 15
 16  [Test]
 117  public void TestSingle() {
 118    KDTree<Vector2> tree =
 1319        new KDTree<Vector2>(new List<Vector2> { new Vector2(1, 1) }, (Vector2 point) => point);
 120    Assert.AreEqual(tree.NearestNeighbor(Vector2.zero), new Vector2(1, 1));
 121    Assert.AreEqual(tree.NearestNeighbor(new Vector2(1, 6)), new Vector2(1, 1));
 122    Assert.AreEqual(tree.NearestNeighbor(new Vector2(3, 2)), new Vector2(1, 1));
 123    Assert.AreEqual(tree.NearestNeighbor(new Vector2(9, 9)), new Vector2(1, 1));
 124  }
 25
 26  [Test]
 127  public void TestNearestNeighborWithinPoints() {
 128    List<Vector2> points = new List<Vector2>();
 3529    for (int i = 0; i <= 10; ++i) {
 38530      for (int j = 0; j <= 10; ++j) {
 12131        points.Add(new Vector2(i, j));
 12132      }
 1133    }
 116034    KDTree<Vector2> tree = new KDTree<Vector2>(points, (Vector2 point) => point);
 135    Assert.AreEqual(tree.NearestNeighbor(Vector2.zero), Vector2.zero);
 136    Assert.AreEqual(tree.NearestNeighbor(new Vector2(1, 6)), new Vector2(1, 6));
 137    Assert.AreEqual(tree.NearestNeighbor(new Vector2(3, 2)), new Vector2(3, 2));
 138    Assert.AreEqual(tree.NearestNeighbor(new Vector2(9, 9)), new Vector2(9, 9));
 139  }
 40
 41  [Test]
 142  public void TestNearestNeighborAroundPoints() {
 143    List<Vector2> points = new List<Vector2>();
 3544    for (int i = 0; i <= 10; ++i) {
 38545      for (int j = 0; j <= 10; ++j) {
 12146        points.Add(new Vector2(i, j));
 12147      }
 1148    }
 124049    KDTree<Vector2> tree = new KDTree<Vector2>(points, (Vector2 point) => point);
 150    Assert.AreEqual(tree.NearestNeighbor(Vector2.zero), Vector2.zero);
 151    Assert.AreEqual(tree.NearestNeighbor(new Vector2(1.4f, 1.2f)), new Vector2(1, 1));
 152    Assert.AreEqual(tree.NearestNeighbor(new Vector2(2.7f, 2.2f)), new Vector2(3, 2));
 153    Assert.AreEqual(tree.NearestNeighbor(new Vector2(9.05f, 8.61f)), new Vector2(9, 9));
 154  }
 55}