Skip to content

Commit

Permalink
Use ion token on CI, add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Sep 23, 2024
1 parent ddffb0c commit d40bdff
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions Tests/TestCesium3DTileset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public IEnumerator SampleHeightMostDetailedWorksWithAnEmptyArrayOfPositions()
GameObject go = new GameObject();
go.name = "Cesium World Terrain";
Cesium3DTileset tileset = go.AddComponent<Cesium3DTileset>();
tileset.ionAccessToken = Environment.GetEnvironmentVariable("CESIUM_ION_TOKEN_FOR_TESTS") ?? "";
tileset.ionAssetID = 1;

// TODO: remove this
Expand Down Expand Up @@ -43,6 +44,7 @@ public IEnumerator SampleHeightMostDetailedWorksWithASinglePosition()
GameObject go = new GameObject();
go.name = "Cesium World Terrain";
Cesium3DTileset tileset = go.AddComponent<Cesium3DTileset>();
tileset.ionAccessToken = Environment.GetEnvironmentVariable("CESIUM_ION_TOKEN_FOR_TESTS") ?? "";
tileset.ionAssetID = 1;

// TODO: remove this
Expand Down Expand Up @@ -70,4 +72,82 @@ public IEnumerator SampleHeightMostDetailedWorksWithASinglePosition()
// Returned height should be different from the original height (1.0) by at least one meter.
Assert.IsTrue(math.abs(result.longitudeLatitudeHeightPositions[0].z - 1.0) > 1.0);
}

[UnityTest]
public IEnumerator SampleHeightMostDetailedWorksWithMultiplePositions()
{
GameObject go = new GameObject();
go.name = "Cesium World Terrain";
Cesium3DTileset tileset = go.AddComponent<Cesium3DTileset>();
tileset.ionAccessToken = Environment.GetEnvironmentVariable("CESIUM_ION_TOKEN_FOR_TESTS") ?? "";
tileset.ionAssetID = 1;

// TODO: remove this
yield return null;

Task<SampleHeightResult> task = tileset.SampleHeightMostDetailed(
new double3(-105.1, 40.1, 1.0),
new double3(105.1, -40.1, 1.0));

while (!task.IsCompleted)
{
yield return null;
}

SampleHeightResult result = task.Result;
Assert.IsNotNull(result);
Assert.IsNotNull(result.longitudeLatitudeHeightPositions);
Assert.IsNotNull(result.heightSampled);
Assert.IsNotNull(result.warnings);
Assert.AreEqual(result.longitudeLatitudeHeightPositions.Length, 2);
Assert.AreEqual(result.heightSampled.Length, 2);
Assert.AreEqual(result.warnings.Length, 0);

Assert.AreEqual(result.heightSampled[0], true);
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].x, -105.1, 1e-12);
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].y, 40.1, 1e-12);
// Returned height should be different from the original height (1.0) by at least one meter.
Assert.IsTrue(math.abs(result.longitudeLatitudeHeightPositions[0].z - 1.0) > 1.0);

Assert.AreEqual(result.heightSampled[1], true);
Assert.AreEqual(result.longitudeLatitudeHeightPositions[1].x, 105.1, 1e-12);
Assert.AreEqual(result.longitudeLatitudeHeightPositions[1].y, -40.1, 1e-12);
// Returned height should be different from the original height (1.0) by at least one meter.
Assert.IsTrue(math.abs(result.longitudeLatitudeHeightPositions[1].z - 1.0) > 1.0);
}

[UnityTest]
public IEnumerator SampleHeightMostDetailedIndicatesNotSampledForPositionOutsideTileset()
{
GameObject go = new GameObject();
go.name = "Melbourne Photogrammetry";
Cesium3DTileset tileset = go.AddComponent<Cesium3DTileset>();
tileset.ionAccessToken = Environment.GetEnvironmentVariable("CESIUM_ION_TOKEN_FOR_TESTS") ?? "";
tileset.ionAssetID = 69380;

// TODO: remove this
yield return null;

// Somewhere in Sydney, not Melbourne
Task<SampleHeightResult> task = tileset.SampleHeightMostDetailed(new double3(151.20972, -33.87100, 1.0));

while (!task.IsCompleted)
{
yield return null;
}

SampleHeightResult result = task.Result;
Assert.IsNotNull(result);
Assert.IsNotNull(result.longitudeLatitudeHeightPositions);
Assert.IsNotNull(result.heightSampled);
Assert.IsNotNull(result.warnings);
Assert.AreEqual(result.longitudeLatitudeHeightPositions.Length, 1);
Assert.AreEqual(result.heightSampled.Length, 1);
Assert.AreEqual(result.warnings.Length, 0);

Assert.AreEqual(result.heightSampled[0], false);
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].x, 151.20972, 1e-12);
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].y, -33.87100, 1e-12);
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].z, 1.0, 1e-12);
}
}

0 comments on commit d40bdff

Please sign in to comment.