< Summary

Class:AgglomerativeClustererTest
Assembly:bamlab.test.editmode
File(s):/github/workspace/Assets/Tests/EditMode/AgglomerativeClustererTest.cs
Covered lines:0
Uncovered lines:42
Coverable lines:42
Total lines:69
Line coverage:0% (0 of 42)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:6
Method coverage:0% (0 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GenerateObject(...)0%2100%
AgglomerativeClustererTest()0%2100%
TestSingleCluster()0%2100%
TestMaxSizeOne()0%12300%
TestZeroRadius()0%12300%
TestSmallRadius()0%6200%

File(s)

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

#LineLine coverage
 1using NUnit.Framework;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Linq;
 5using UnityEngine;
 6using UnityEngine.TestTools;
 7
 8public class AgglomerativeClustererTest {
 09  public static GameObject GenerateObject(in Vector3 position) {
 010    GameObject obj = new GameObject();
 011    obj.transform.position = position;
 012    return obj;
 013  }
 14
 015  public static readonly List<GameObject> Objects = new List<GameObject> {
 16    GenerateObject(new Vector3(0, 0, 0)),
 17    GenerateObject(new Vector3(0, 1, 0)),
 18    GenerateObject(new Vector3(0, 1.5f, 0)),
 19    GenerateObject(new Vector3(0, 2.5f, 0)),
 20  };
 21
 22  [Test]
 023  public void TestSingleCluster() {
 024    AgglomerativeClusterer clusterer =
 25        new AgglomerativeClusterer(Objects, maxSize: Objects.Count, maxRadius: Mathf.Infinity);
 026    clusterer.Cluster();
 027    Assert.AreEqual(1, clusterer.Clusters.Count);
 028    Cluster cluster = clusterer.Clusters[0];
 029    Assert.AreEqual(Objects.Count, cluster.Size());
 030    Assert.AreEqual(new Vector3(0, 1.25f, 0), cluster.Centroid());
 031  }
 32
 33  [Test]
 034  public void TestMaxSizeOne() {
 035    AgglomerativeClusterer clusterer =
 36        new AgglomerativeClusterer(Objects, maxSize: 1, maxRadius: Mathf.Infinity);
 037    clusterer.Cluster();
 038    Assert.AreEqual(Objects.Count, clusterer.Clusters.Count);
 039    foreach (var cluster in clusterer.Clusters) {
 040      Assert.AreEqual(1, cluster.Size());
 041    }
 042  }
 43
 44  [Test]
 045  public void TestZeroRadius() {
 046    AgglomerativeClusterer clusterer =
 47        new AgglomerativeClusterer(Objects, maxSize: Objects.Count, maxRadius: 0);
 048    clusterer.Cluster();
 049    Assert.AreEqual(Objects.Count, clusterer.Clusters.Count);
 050    foreach (var cluster in clusterer.Clusters) {
 051      Assert.AreEqual(1, cluster.Size());
 052    }
 053  }
 54
 55  [Test]
 056  public void TestSmallRadius() {
 057    AgglomerativeClusterer clusterer =
 58        new AgglomerativeClusterer(Objects, maxSize: Objects.Count, maxRadius: 1);
 059    clusterer.Cluster();
 060    Assert.AreEqual(3, clusterer.Clusters.Count);
 061    List<Cluster> clusters = clusterer.Clusters.OrderBy(cluster => cluster.Coordinates[1]).ToList();
 062    Assert.AreEqual(1, clusters[0].Size());
 063    Assert.AreEqual(new Vector3(0, 0, 0), clusters[0].Coordinates);
 064    Assert.AreEqual(2, clusters[1].Size());
 065    Assert.AreEqual(new Vector3(0, 1.25f, 0), clusters[1].Coordinates);
 066    Assert.AreEqual(1, clusters[2].Size());
 067    Assert.AreEqual(new Vector3(0, 2.5f, 0), clusters[2].Coordinates);
 068  }
 69}