Skip to content

Commit

Permalink
fix(Tests): ensure all quaternion and vectors use comparators
Browse files Browse the repository at this point in the history
All of the tests that compare vectors or quaternions have now been
updated so they no longer use ToString to compare in the
Assert.AreEqual as this is not robust enough to always work. Instead
they all now use equality comparators.

All of the gameobjects created by the tests now also are named so it
is easier to see which test is running and where any cleanup issues
may be occurring.

The `UnityEngine.Assertions.Assert` has also been removed from the
tests as it is not required.

Any test that destroys the `subject` object on teardown has also been
updated to not do this as the subject gets destroyed automatically
when the `containingObject` GameObject gets destroyed.
  • Loading branch information
thestonefox committed Feb 8, 2023
1 parent a1f5204 commit cbafc35
Show file tree
Hide file tree
Showing 224 changed files with 2,661 additions and 2,280 deletions.
4 changes: 2 additions & 2 deletions Runtime/Data/Operation/Mutation/RigidbodyPropertyMutator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ protected virtual void OnAfterIsKinematicChange()
/// </summary>
protected virtual void OnAfterVelocityChange()
{
if (Target == null)
if (Target == null || Target.isKinematic)
{
return;
}
Expand All @@ -369,7 +369,7 @@ protected virtual void OnAfterVelocityChange()
/// </summary>
protected virtual void OnAfterAngularVelocityChange()
{
if (Target == null)
if (Target == null || Target.isKinematic)
{
return;
}
Expand Down
33 changes: 16 additions & 17 deletions Tests/Editor/Action/ActionRegistrarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Test.Zinnia.Action
using Test.Zinnia.Utility.Mock;
using UnityEngine;
using UnityEngine.TestTools;
using Assert = UnityEngine.Assertions.Assert;

public class ActionRegistrarTest
{
Expand All @@ -19,7 +18,7 @@ public class ActionRegistrarTest
[SetUp]
public void SetUp()
{
containingObject = new GameObject();
containingObject = new GameObject("ActionRegistrarTest");
containingObject.SetActive(false);

ActionRegistrarSourceObservableList sources = containingObject.AddComponent<ActionRegistrarSourceObservableList>();
Expand All @@ -42,13 +41,13 @@ public void TearDown()
[UnityTest]
public IEnumerator RegisterOnEnable()
{
GameObject targetActionObject = new GameObject();
GameObject targetActionObject = new GameObject("ActionRegistrarTest");
BooleanAction targetAction = targetActionObject.AddComponent<BooleanAction>();

GameObject oneSourceActionObject = new GameObject();
GameObject oneSourceActionObject = new GameObject("ActionRegistrarTest");
BooleanAction oneSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

GameObject twoSourceActionObject = new GameObject();
GameObject twoSourceActionObject = new GameObject("ActionRegistrarTest");
BooleanAction twoSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
Expand Down Expand Up @@ -90,13 +89,13 @@ public IEnumerator RegisterSpecific()
subject.enabled = true;
yield return null;

GameObject targetActionObject = new GameObject();
GameObject targetActionObject = new GameObject("ActionRegistrarTest");
BooleanAction targetAction = targetActionObject.AddComponent<BooleanAction>();

GameObject oneSourceActionObject = new GameObject();
GameObject oneSourceActionObject = new GameObject("ActionRegistrarTest");
BooleanAction oneSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

GameObject twoSourceActionObject = new GameObject();
GameObject twoSourceActionObject = new GameObject("ActionRegistrarTest");
BooleanAction twoSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
Expand Down Expand Up @@ -133,13 +132,13 @@ public IEnumerator RegisterSpecific()
[UnityTest]
public IEnumerator RegisterOnlyEnabled()
{
GameObject targetActionObject = new GameObject();
GameObject targetActionObject = new GameObject("ActionRegistrarTest");
BooleanAction targetAction = targetActionObject.AddComponent<BooleanAction>();

GameObject oneSourceActionObject = new GameObject();
GameObject oneSourceActionObject = new GameObject("ActionRegistrarTest");
BooleanAction oneSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

GameObject twoSourceActionObject = new GameObject();
GameObject twoSourceActionObject = new GameObject("ActionRegistrarTest");
BooleanAction twoSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
Expand Down Expand Up @@ -191,13 +190,13 @@ public IEnumerator Unregister()
subject.enabled = true;
yield return null;

GameObject targetActionObject = new GameObject();
GameObject targetActionObject = new GameObject("ActionRegistrarTest");
BooleanAction targetAction = targetActionObject.AddComponent<BooleanAction>();

GameObject oneSourceActionObject = new GameObject();
GameObject oneSourceActionObject = new GameObject("ActionRegistrarTest");
BooleanAction oneSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

GameObject twoSourceActionObject = new GameObject();
GameObject twoSourceActionObject = new GameObject("ActionRegistrarTest");
BooleanAction twoSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
Expand Down Expand Up @@ -259,13 +258,13 @@ public IEnumerator UnregisterEvenIfDisabled()
subject.enabled = true;
yield return null;

GameObject targetActionObject = new GameObject();
GameObject targetActionObject = new GameObject("ActionRegistrarTest");
BooleanAction targetAction = targetActionObject.AddComponent<BooleanAction>();

GameObject oneSourceActionObject = new GameObject();
GameObject oneSourceActionObject = new GameObject("ActionRegistrarTest");
BooleanAction oneSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

GameObject twoSourceActionObject = new GameObject();
GameObject twoSourceActionObject = new GameObject("ActionRegistrarTest");
BooleanAction twoSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
Expand Down
5 changes: 2 additions & 3 deletions Tests/Editor/Action/AllActionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Test.Zinnia.Action
using Test.Zinnia.Utility.Mock;
using UnityEngine;
using UnityEngine.TestTools;
using Assert = UnityEngine.Assertions.Assert;

public class AllActionTest
{
Expand All @@ -18,7 +17,7 @@ public class AllActionTest
[UnitySetUp]
public IEnumerator SetUp()
{
containingObject = new GameObject();
containingObject = new GameObject("AllActionTest");
ActionObservableList actions = containingObject.AddComponent<ActionObservableList>();

subject = containingObject.AddComponent<AllActionMock>();
Expand Down Expand Up @@ -251,7 +250,7 @@ public void RemoveActionListenersCorrectly()
{
subject.enabled = false;

GameObject otherObject = new GameObject();
GameObject otherObject = new GameObject("AllActionTest");
MockAction actionA = otherObject.AddComponent<MockAction>();
MockAction actionB = otherObject.AddComponent<MockAction>();

Expand Down
5 changes: 2 additions & 3 deletions Tests/Editor/Action/AnyActionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Test.Zinnia.Action
using Test.Zinnia.Utility.Mock;
using UnityEngine;
using UnityEngine.TestTools;
using Assert = UnityEngine.Assertions.Assert;

public class AnyActionTest
{
Expand All @@ -18,7 +17,7 @@ public class AnyActionTest
[UnitySetUp]
public IEnumerator SetUp()
{
containingObject = new GameObject();
containingObject = new GameObject("AnyActionTest");
ActionObservableList actions = containingObject.AddComponent<ActionObservableList>();

subject = containingObject.AddComponent<AnyActionMock>();
Expand Down Expand Up @@ -251,7 +250,7 @@ public void RemoveActionListenersCorrectly()
{
subject.enabled = false;

GameObject otherObject = new GameObject();
GameObject otherObject = new GameObject("AnyActionTest");
MockAction actionA = otherObject.AddComponent<MockAction>();
MockAction actionB = otherObject.AddComponent<MockAction>();

Expand Down
11 changes: 5 additions & 6 deletions Tests/Editor/Action/BooleanActionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Test.Zinnia.Action
using Test.Zinnia.Utility.Mock;
using UnityEngine;
using UnityEngine.TestTools;
using Assert = UnityEngine.Assertions.Assert;

public class BooleanActionTest
{
Expand All @@ -17,7 +16,7 @@ public class BooleanActionTest
[SetUp]
public void SetUp()
{
containingObject = new GameObject();
containingObject = new GameObject("BooleanActionTest");
subject = containingObject.AddComponent<BooleanActionMock>();
}

Expand Down Expand Up @@ -361,7 +360,7 @@ public void AddSource()
subject.ValueChanged.AddListener(changedListenerMock.Listen);
subject.ValueUnchanged.AddListener(unchangedListenerMock.Listen);

GameObject sourceObject = new GameObject();
GameObject sourceObject = new GameObject("BooleanActionTest");
BooleanActionMock sourceMock = sourceObject.AddComponent<BooleanActionMock>();

Assert.AreEqual(0, subject.ReadOnlySources.Count);
Expand Down Expand Up @@ -403,7 +402,7 @@ public void RemoveSource()
subject.ValueChanged.AddListener(changedListenerMock.Listen);
subject.ValueUnchanged.AddListener(unchangedListenerMock.Listen);

GameObject sourceObject = new GameObject();
GameObject sourceObject = new GameObject("BooleanActionTest");
BooleanActionMock sourceMock = sourceObject.AddComponent<BooleanActionMock>();

subject.AddSource(sourceMock);
Expand Down Expand Up @@ -453,7 +452,7 @@ public void ClearSources()
subject.ValueChanged.AddListener(changedListenerMock.Listen);
subject.ValueUnchanged.AddListener(unchangedListenerMock.Listen);

GameObject sourceObject = new GameObject();
GameObject sourceObject = new GameObject("BooleanActionTest");
BooleanActionMock sourceMock = sourceObject.AddComponent<BooleanActionMock>();

subject.AddSource(sourceMock);
Expand Down Expand Up @@ -491,7 +490,7 @@ public void ClearSources()
[Test]
public void SourcesContains()
{
GameObject sourceObject = new GameObject();
GameObject sourceObject = new GameObject("BooleanActionTest");
BooleanActionMock sourceMock = sourceObject.AddComponent<BooleanActionMock>();

Assert.IsFalse(subject.SourcesContains(sourceMock));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Test.Zinnia.Action.Collection
using System.Collections;
using UnityEngine;
using UnityEngine.TestTools;
using Assert = UnityEngine.Assertions.Assert;

public class ActionRegistrarSourceObservableListTest
{
Expand All @@ -17,7 +16,7 @@ public class ActionRegistrarSourceObservableListTest
[UnitySetUp]
public IEnumerator SetUp()
{
containingObject = new GameObject();
containingObject = new GameObject("ActionRegistrarSourceObservableListTest");
subject = containingObject.AddComponent<ActionRegistrarSourceObservableList>();
yield return null;
}
Expand All @@ -31,9 +30,9 @@ public void TearDown()
[Test]
public void EnableSource()
{
GameObject oneSourceActionObject = new GameObject();
GameObject oneSourceActionObject = new GameObject("ActionRegistrarSourceObservableListTest");
BooleanAction oneSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();
GameObject twoSourceActionObject = new GameObject();
GameObject twoSourceActionObject = new GameObject("ActionRegistrarSourceObservableListTest");
BooleanAction twoSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
Expand Down Expand Up @@ -68,9 +67,9 @@ public void EnableSource()
[Test]
public void DisableSource()
{
GameObject oneSourceActionObject = new GameObject();
GameObject oneSourceActionObject = new GameObject("ActionRegistrarSourceObservableListTest");
BooleanAction oneSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();
GameObject twoSourceActionObject = new GameObject();
GameObject twoSourceActionObject = new GameObject("ActionRegistrarSourceObservableListTest");
BooleanAction twoSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
Expand Down Expand Up @@ -105,9 +104,9 @@ public void DisableSource()
[Test]
public void EnableAllSource()
{
GameObject oneSourceActionObject = new GameObject();
GameObject oneSourceActionObject = new GameObject("ActionRegistrarSourceObservableListTest");
BooleanAction oneSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();
GameObject twoSourceActionObject = new GameObject();
GameObject twoSourceActionObject = new GameObject("ActionRegistrarSourceObservableListTest");
BooleanAction twoSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
Expand Down Expand Up @@ -142,9 +141,9 @@ public void EnableAllSource()
[Test]
public void DisableAllSource()
{
GameObject oneSourceActionObject = new GameObject();
GameObject oneSourceActionObject = new GameObject("ActionRegistrarSourceObservableListTest");
BooleanAction oneSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();
GameObject twoSourceActionObject = new GameObject();
GameObject twoSourceActionObject = new GameObject("ActionRegistrarSourceObservableListTest");
BooleanAction twoSourceAction = oneSourceActionObject.AddComponent<BooleanAction>();

ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
Expand Down
3 changes: 1 addition & 2 deletions Tests/Editor/Action/FloatActionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Test.Zinnia.Action
using Test.Zinnia.Utility.Mock;
using UnityEngine;
using UnityEngine.TestTools;
using Assert = UnityEngine.Assertions.Assert;

public class FloatActionTest
{
Expand All @@ -17,7 +16,7 @@ public class FloatActionTest
[SetUp]
public void SetUp()
{
containingObject = new GameObject();
containingObject = new GameObject("FloatActionTest");
subject = containingObject.AddComponent<FloatActionMock>();
}

Expand Down
5 changes: 2 additions & 3 deletions Tests/Editor/Action/StateEmitterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace Test.Zinnia.Action
using NUnit.Framework;
using Test.Zinnia.Utility.Mock;
using UnityEngine;
using Assert = UnityEngine.Assertions.Assert;

public class StateEmitterTest
{
Expand All @@ -17,9 +16,9 @@ public class StateEmitterTest
[SetUp]
public void SetUp()
{
containingObject = new GameObject();
containingObject = new GameObject("StateEmitterTest");
subject = containingObject.AddComponent<StateEmitter>();
actionObject = new GameObject();
actionObject = new GameObject("StateEmitterTest");
action = actionObject.AddComponent<BooleanAction>();
}

Expand Down
3 changes: 1 addition & 2 deletions Tests/Editor/Action/SurfaceChangeActionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Test.Zinnia.Action
using NUnit.Framework;
using Test.Zinnia.Utility.Mock;
using UnityEngine;
using Assert = UnityEngine.Assertions.Assert;

public class SurfaceChangeActionTest
{
Expand All @@ -16,7 +15,7 @@ public class SurfaceChangeActionTest
[SetUp]
public void SetUp()
{
containingObject = new GameObject();
containingObject = new GameObject("SurfaceChangeActionTest");
subject = containingObject.AddComponent<SurfaceChangeActionMock>();
}

Expand Down
3 changes: 1 addition & 2 deletions Tests/Editor/Action/ToggleActionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace Test.Zinnia.Action
using NUnit.Framework;
using Test.Zinnia.Utility.Mock;
using UnityEngine;
using Assert = UnityEngine.Assertions.Assert;

public class ToggleActionTest
{
Expand All @@ -15,7 +14,7 @@ public class ToggleActionTest
[SetUp]
public void SetUp()
{
containingObject = new GameObject();
containingObject = new GameObject("ToggleActionTest");
subject = containingObject.AddComponent<ToggleActionMock>();
}

Expand Down
3 changes: 1 addition & 2 deletions Tests/Editor/Action/Vector2ActionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace Test.Zinnia.Action
using NUnit.Framework;
using Test.Zinnia.Utility.Mock;
using UnityEngine;
using Assert = UnityEngine.Assertions.Assert;

public class Vector2ActionTest
{
Expand All @@ -15,7 +14,7 @@ public class Vector2ActionTest
[SetUp]
public void SetUp()
{
containingObject = new GameObject();
containingObject = new GameObject("Vector2ActionTest");
subject = containingObject.AddComponent<Vector2ActionMock>();
}

Expand Down
3 changes: 1 addition & 2 deletions Tests/Editor/Action/Vector3ActionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace Test.Zinnia.Action
using NUnit.Framework;
using Test.Zinnia.Utility.Mock;
using UnityEngine;
using Assert = UnityEngine.Assertions.Assert;

public class Vector3ActionTest
{
Expand All @@ -15,7 +14,7 @@ public class Vector3ActionTest
[SetUp]
public void SetUp()
{
containingObject = new GameObject();
containingObject = new GameObject("Vector3ActionTest");
subject = containingObject.AddComponent<Vector3ActionMock>();
}

Expand Down
Loading

0 comments on commit cbafc35

Please sign in to comment.