< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GenerateObject(...)0%110100%
GenerateCluster(...)0%110100%
TestSize()0%220100%
TestIsEmpty()0%110100%
TestRadius()0%110100%
TestCentroid()0%330100%
TestRecenter()0%330100%
TestMerge()0%220100%

File(s)

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

#LineLine coverage
 1using NUnit.Framework;
 2using System.Collections;
 3using System.Collections.Generic;
 4using UnityEngine;
 5using UnityEngine.TestTools;
 6
 7public class ClusterTests {
 518  public static GameObject GenerateObject(in Vector3 position) {
 519    GameObject obj = new GameObject();
 5110    Agent agent = obj.AddComponent<DummyAgent>();
 5111    obj.transform.position = position;
 5112    return obj;
 5113  }
 14
 615  public static Cluster GenerateCluster(in IReadOnlyList<GameObject> objects) {
 616    Cluster cluster = new Cluster();
 617    cluster.AddObjects(objects);
 618    cluster.Recenter();
 619    return cluster;
 620  }
 21
 22  [Test]
 123  public void TestSize() {
 24    const int size = 10;
 125    List<GameObject> objects = new List<GameObject>();
 3226    for (int i = 0; i < size; ++i) {
 1027      objects.Add(GenerateObject(new Vector3(0, i, 0)));
 1028    }
 129    Cluster cluster = GenerateCluster(objects);
 130    Assert.AreEqual(size, cluster.Size());
 131  }
 32
 33  [Test]
 134  public void TestIsEmpty() {
 135    Cluster emptyCluster = new Cluster();
 136    Assert.IsTrue(emptyCluster.IsEmpty());
 37
 138    Cluster cluster = new Cluster();
 139    cluster.AddObject(new GameObject());
 140    Assert.IsFalse(cluster.IsEmpty());
 141  }
 42
 43  [Test]
 144  public void TestRadius() {
 45    const float radius = 5;
 146    List<GameObject> objects = new List<GameObject>();
 147    objects.Add(GenerateObject(new Vector3(0, radius, 0)));
 148    objects.Add(GenerateObject(new Vector3(0, -radius, 0)));
 149    Cluster cluster = GenerateCluster(objects);
 150    Assert.AreEqual(radius, cluster.Radius());
 151  }
 52
 53  [Test]
 154  public void TestCentroid() {
 155    List<GameObject> objects = new List<GameObject>();
 1156    for (int i = -1; i <= 1; ++i) {
 3357      for (int j = -1; j <= 1; ++j) {
 958        objects.Add(GenerateObject(new Vector3(i, j, 0)));
 959      }
 360    }
 161    Cluster cluster = GenerateCluster(objects);
 162    Assert.AreEqual(Vector3.zero, cluster.Centroid());
 163  }
 64
 65  [Test]
 166  public void TestRecenter() {
 167    List<GameObject> objects = new List<GameObject>();
 1168    for (int i = -1; i <= 1; ++i) {
 3369      for (int j = -1; j <= 1; ++j) {
 970        objects.Add(GenerateObject(new Vector3(i, j, 0)));
 971      }
 372    }
 173    Cluster cluster = GenerateCluster(objects);
 174    cluster.AddObject(GenerateObject(new Vector3(10, -10, 0)));
 175    Assert.AreNotEqual(new Vector3(1, -1, 0), cluster.Coordinates);
 176    cluster.Recenter();
 177    Assert.AreEqual(new Vector3(1, -1, 0), cluster.Coordinates);
 178  }
 79
 80  [Test]
 181  public void TestMerge() {
 82    const int size = 10;
 183    List<GameObject> objects1 = new List<GameObject>();
 184    List<GameObject> objects2 = new List<GameObject>();
 3285    for (int i = 0; i < size; ++i) {
 1086      objects1.Add(GenerateObject(new Vector3(0, i, 0)));
 1087      objects2.Add(GenerateObject(new Vector3(i, 0, 0)));
 1088    }
 189    Cluster cluster1 = GenerateCluster(objects1);
 190    Cluster cluster2 = GenerateCluster(objects2);
 191    int size1 = cluster1.Size();
 192    int size2 = cluster2.Size();
 193    Vector3 centroid1 = cluster1.Centroid();
 194    Vector3 centroid2 = cluster2.Centroid();
 195    cluster1.Merge(cluster2);
 196    cluster1.Recenter();
 197    Assert.AreEqual(size1 + size2, cluster1.Size());
 198    Assert.AreEqual((centroid1 + centroid2) / 2, cluster1.Coordinates);
 199  }
 100}