Skip to content

Commit

Permalink
Add a simple test to ensure spline cart is working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineCharton committed May 29, 2024
1 parent 6828a18 commit 7b566da
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
51 changes: 51 additions & 0 deletions com.unity.cinemachine/Tests/Runtime/SplineCartTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.Splines;
using Unity.Mathematics;

namespace Unity.Cinemachine.Tests
{
[TestFixture]
public class CinemachineSplineCartTest : CinemachineRuntimeFixtureBase
{
CinemachineSplineCart m_CmSplineCart;
SplineContainer m_SplineContainer;

[SetUp]
public void Setup()
{
base.SetUp();

m_SplineContainer = CreateGameObject("Dolly Track", typeof(SplineContainer)).GetComponent<SplineContainer>();
m_SplineContainer.Spline = SplineFactory.CreateLinear(
new List<float3> { new(7, 1, -6), new(13, 1, -6), new(13, 1, 1), new(7, 1, 1) }, true);
m_CmSplineCart = CreateGameObject("CM cart", typeof(CinemachineSplineCart)).GetComponent<CinemachineSplineCart>();
m_CmSplineCart.Spline = m_SplineContainer;
}

[TearDown]
public override void TearDown()
{
base.TearDown();
}

[UnityTest]
public IEnumerator CartPositionIsCorrect()
{
m_CmSplineCart.PositionUnits = PathIndexUnit.Distance;
m_CmSplineCart.SplinePosition = 0;
yield return null;
UnityEngine.Assertions.Assert.AreApproximatelyEqual(
Vector3.Distance(m_CmSplineCart.transform.position, new Vector3(7, 1, -6)), 0, 0.1f);

m_CmSplineCart.PositionUnits = PathIndexUnit.Normalized;
m_CmSplineCart.SplinePosition = 1;
yield return null;
UnityEngine.Assertions.Assert.AreApproximatelyEqual(
Vector3.Distance(m_CmSplineCart.transform.position, new Vector3(7, 1, -6)), 0, 0.1f);
}
}
}
11 changes: 11 additions & 0 deletions com.unity.cinemachine/Tests/Runtime/SplineCartTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b566da

Please sign in to comment.