< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GenerateObject(...)0%2100%
GenerateCluster(...)0%2100%
TestSize()0%6200%
TestIsEmpty()0%2100%
TestRadius()0%2100%
TestCentroid()0%12300%
TestRecenter()0%12300%
TestMerge()0%6200%

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 {
 08  public static GameObject GenerateObject(in Vector3 position) {
 09    GameObject obj = new GameObject();
 010    Agent agent = obj.AddComponent<DummyAgent>();
 011    obj.transform.position = position;
 012    return obj;
 013  }
 14
 015  public static Cluster GenerateCluster(in IReadOnlyList<GameObject> objects) {
 016    Cluster cluster = new Cluster();
 017    cluster.AddObjects(objects);
 018    cluster.Recenter();
 019    return cluster;
 020  }
 21
 22  [Test]
 023  public void TestSize() {
 24    const int size = 10;
 025    List<GameObject> objects = new List<GameObject>();
 026    for (int i = 0; i < size; ++i) {
 027      objects.Add(GenerateObject(new Vector3(0, i, 0)));
 028    }
 029    Cluster cluster = GenerateCluster(objects);
 030    Assert.AreEqual(size, cluster.Size());
 031  }
 32
 33  [Test]
 034  public void TestIsEmpty() {
 035    Cluster emptyCluster = new Cluster();
 036    Assert.IsTrue(emptyCluster.IsEmpty());
 37
 038    Cluster cluster = new Cluster();
 039    cluster.AddObject(new GameObject());
 040    Assert.IsFalse(cluster.IsEmpty());
 041  }
 42
 43  [Test]
 044  public void TestRadius() {
 45    const float radius = 5;
 046    List<GameObject> objects = new List<GameObject>();
 047    objects.Add(GenerateObject(new Vector3(0, radius, 0)));
 048    objects.Add(GenerateObject(new Vector3(0, -radius, 0)));
 049    Cluster cluster = GenerateCluster(objects);
 050    Assert.AreEqual(radius, cluster.Radius());
 051  }
 52
 53  [Test]
 054  public void TestCentroid() {
 055    List<GameObject> objects = new List<GameObject>();
 056    for (int i = -1; i <= 1; ++i) {
 057      for (int j = -1; j <= 1; ++j) {
 058        objects.Add(GenerateObject(new Vector3(i, j, 0)));
 059      }
 060    }
 061    Cluster cluster = GenerateCluster(objects);
 062    Assert.AreEqual(Vector3.zero, cluster.Centroid());
 063  }
 64
 65  [Test]
 066  public void TestRecenter() {
 067    List<GameObject> objects = new List<GameObject>();
 068    for (int i = -1; i <= 1; ++i) {
 069      for (int j = -1; j <= 1; ++j) {
 070        objects.Add(GenerateObject(new Vector3(i, j, 0)));
 071      }
 072    }
 073    Cluster cluster = GenerateCluster(objects);
 074    cluster.AddObject(GenerateObject(new Vector3(10, -10, 0)));
 075    Assert.AreNotEqual(new Vector3(1, -1, 0), cluster.Coordinates);
 076    cluster.Recenter();
 077    Assert.AreEqual(new Vector3(1, -1, 0), cluster.Coordinates);
 078  }
 79
 80  [Test]
 081  public void TestMerge() {
 82    const int size = 10;
 083    List<GameObject> objects1 = new List<GameObject>();
 084    List<GameObject> objects2 = new List<GameObject>();
 085    for (int i = 0; i < size; ++i) {
 086      objects1.Add(GenerateObject(new Vector3(0, i, 0)));
 087      objects2.Add(GenerateObject(new Vector3(i, 0, 0)));
 088    }
 089    Cluster cluster1 = GenerateCluster(objects1);
 090    Cluster cluster2 = GenerateCluster(objects2);
 091    int size1 = cluster1.Size();
 092    int size2 = cluster2.Size();
 093    Vector3 centroid1 = cluster1.Centroid();
 094    Vector3 centroid2 = cluster2.Centroid();
 095    cluster1.Merge(cluster2);
 096    cluster1.Recenter();
 097    Assert.AreEqual(size1 + size2, cluster1.Size());
 098    Assert.AreEqual((centroid1 + centroid2) / 2, cluster1.Coordinates);
 099  }
 100}