Skip to content

Commit

Permalink
Merge branch 'release/1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ashblue committed Dec 29, 2017
2 parents 2d6839e + 77d645c commit 62d0bd6
Show file tree
Hide file tree
Showing 54 changed files with 1,270 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Adnc.AnimatorHelpers.Conditions;
using Adnc.AnimatorHelpers.Variables;
using Adnc.Utility.Testing;
using Adnc.AnimatorHelpers.Editors.Testing.Utilities;
using NUnit.Framework;
using UnityEngine;
using Object = UnityEngine.Object;
Expand All @@ -10,35 +11,41 @@ public class TestAnimatorPlayback : TestBase {
private const string ANIMATOR_STUB_LOC = "AnimatorTesting/AnimatorStub";

private AnimatorPlayback _playback;
private Animator _anim;
private AnimatorStub _stub;

[SetUp]
public void SetupAnimatorPlayback () {
_playback = ScriptableObject.CreateInstance<AnimatorPlayback>();
var stub = Resources.Load<GameObject>(ANIMATOR_STUB_LOC);
_anim = Object.Instantiate(stub).GetComponent<Animator>();

_stub = new AnimatorStub(new GameObject("AnimatorStub"));
_stub.AnimatorCtrl.AddParameter("bool", AnimatorControllerParameterType.Bool);
_stub.AnimatorCtrl.AddParameter("float", AnimatorControllerParameterType.Float);
_stub.AnimatorCtrl.AddParameter("int", AnimatorControllerParameterType.Int);
_stub.AnimatorCtrl.AddParameter("trigger", AnimatorControllerParameterType.Trigger);

_stub.InjectCtrl();
}

[TearDown]
public void TeardownAnimatorPlayback () {
Object.DestroyImmediate(_anim.gameObject);
Object.DestroyImmediate(_stub.Animator.gameObject);
_playback = null;
_anim = null;
_stub = null;
}

[Test]
public void StubBoolIsFalse () {
Assert.IsFalse(_anim.GetBool("bool"));
Assert.IsFalse(_stub.Animator.GetBool("bool"));
}

[Test]
public void StubFloatIsZero () {
Assert.IsTrue(Mathf.Abs(_anim.GetFloat("float")) < 0.1f);
Assert.IsTrue(Mathf.Abs(_stub.Animator.GetFloat("float")) < 0.1f);
}

[Test]
public void StubIntIsZero () {
Assert.IsTrue(_anim.GetInteger("int") == 0);
Assert.IsTrue(_stub.Animator.GetInteger("int") == 0);
}

[Test]
Expand All @@ -48,9 +55,9 @@ public void PlaySetsAnimatorBool () {
value = true
});

_playback.Play(_anim);
_playback.Play(_stub.Animator);

Assert.IsTrue(_anim.GetBool("bool"));
Assert.IsTrue(_stub.Animator.GetBool("bool"));
}

[Test]
Expand All @@ -60,9 +67,9 @@ public void PlaySetsAnimatorFloat () {
value = 1
});

_playback.Play(_anim);
_playback.Play(_stub.Animator);

Assert.AreEqual(_anim.GetFloat("float"), 1);
Assert.AreEqual(_stub.Animator.GetFloat("float"), 1);
}

[Test]
Expand All @@ -72,9 +79,9 @@ public void PlaySetsAnimatorInt () {
value = 1
});

_playback.Play(_anim);
_playback.Play(_stub.Animator);

Assert.AreEqual(_anim.GetInteger("int"), 1);
Assert.AreEqual(_stub.Animator.GetInteger("int"), 1);
}

[Test]
Expand All @@ -85,7 +92,7 @@ public void IsConditionMetTrueWithNoAnimatorNull () {
[Test]
public void IsConditionMetIsTrueWithNoConditions () {
_playback.conditions.RemoveAt(0);
Assert.IsTrue(_playback.IsConditionsMet(_anim));
Assert.IsTrue(_playback.IsConditionsMet(_stub.Animator));
}

[Test]
Expand All @@ -100,7 +107,7 @@ public void IsConditionMetFalseWhenConditionsNotMet () {
variableType = ConditionVarType.Bool
});

Assert.IsFalse(_playback.IsConditionsMet(_anim));
Assert.IsFalse(_playback.IsConditionsMet(_stub.Animator));
}

[Test]
Expand All @@ -115,9 +122,11 @@ public void IsConditionMetTrueWhenConditionsAreMet () {
variableType = ConditionVarType.Bool
});

_anim.SetBool("bool", true);
_stub.Animator.SetBool("bool", true);

Assert.IsTrue(_playback.IsConditionsMet(_anim));
Assert.IsTrue(_playback.IsConditionsMet(_stub.Animator));
}


}
}
3 changes: 3 additions & 0 deletions Assets/AdncAnimatorHelpers/Editor/Testing/AnimatorStub.meta

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using Adnc.Utility.Testing;
using Adnc.AnimatorHelpers.Editors.Testing.Utilities;
using NUnit.Framework;
using UnityEngine;

namespace Adnc.AnimatorHelpers.Editors.Testing {
public class TestAnimatorStub : TestBase {
private GameObject _go;
private AnimatorStub _animStub;

[SetUp]
public void Setup () {
_go = new GameObject("AnimatorStub");
}

[TearDown]
public void Teardown () {
Object.DestroyImmediate(_go);
}

[Test]
public void DoesNotFailCreationIfNoGameObject () {
var stub = new AnimatorStub(null);

Assert.IsTrue(stub.IsValid);
}

[Test]
public void CreatesIfGameObjectPassedIn () {
var stub = new AnimatorStub(_go);

Assert.IsTrue(stub.IsValid);
}

[Test]
public void AttachRuntimeController () {
var stub = new AnimatorStub(_go);

stub.InjectCtrl();

Assert.AreSame(stub.Animator.runtimeAnimatorController, stub.AnimatorCtrl);
}

[Test]
public void GetAnimatorParameter () {
var stub = new AnimatorStub(_go);
const string param = "test";

stub.AnimatorCtrl.AddParameter(param, AnimatorControllerParameterType.Bool);
stub.InjectCtrl();
var result = stub.Animator.GetBool(param);

Assert.IsFalse(result);
}

[Test]
public void SetAnimatorParameter () {
var stub = new AnimatorStub(_go);
const string param = "test";

stub.AnimatorCtrl.AddParameter(param, AnimatorControllerParameterType.Bool);
stub.InjectCtrl();
stub.Animator.SetBool(param, true);
var result = stub.Animator.GetBool(param);

Assert.IsTrue(result);
}

[Test]
public void CreateNewLayerReturnsLayer () {
var stub = new AnimatorStub(_go);
var layer = stub.AddLayer("Test");

Assert.IsNotNull(layer);
}

[Test]
public void CreateNewLayerAddsAnotherLayer () {
var stub = new AnimatorStub(_go);
stub.AddLayer("Test");

Assert.AreEqual(stub.AnimatorCtrl.layers.Length, 2);
}

[Test]
public void CreateNewLayerSetsName () {
var layerName = "Test";
var stub = new AnimatorStub(_go);
var layer = stub.AddLayer(layerName);

Assert.AreEqual(layerName, layer.name);
}

[Test]
public void CreateNewLayerSetsStateMachine () {
var stub = new AnimatorStub(_go);
var layer = stub.AddLayer("Test");

Assert.IsNotNull(layer.stateMachine);
}

[Test]
public void CreateNewLayerCreatesAtLeastOneState () {
var stub = new AnimatorStub(_go);
var layer = stub.AddLayer("Test");

Assert.IsTrue(layer.stateMachine.states.Length >= 1);
}

[Test]
public void CreateNewLayerSetsDefaultState () {
var stub = new AnimatorStub(_go);
var layer = stub.AddLayer("Test");

Assert.IsNotNull(layer.stateMachine.defaultState);
}

[Test]
public void PlayAdvancesToTheNextState () {
var stub = new AnimatorStub(_go);
var layer = stub.AnimatorCtrl.layers[0];
const string stateName = "New State";
var state = layer.stateMachine.AddState(stateName);
var trans = layer.stateMachine.defaultState.AddTransition(state);

layer.stateMachine.defaultState.AddTransition(state);
trans.hasExitTime = true;
stub.InjectCtrl();
stub.Animator.Update(10);

var stateInfo = stub.Animator.GetCurrentAnimatorStateInfo(0);
Assert.IsTrue(stateInfo.IsName(stateName));
}

[Test]
public void RuntimeControllerNameSameAsCreationName () {
var stub = new AnimatorStub(_go);

stub.AnimatorCtrl.name = "asdf";
stub.InjectCtrl();

Assert.AreEqual(stub.AnimatorCtrl.name, stub.Animator.runtimeAnimatorController.name);
Assert.AreNotEqual(stub.Animator.gameObject.name, stub.Animator.runtimeAnimatorController.name);
}
}
}

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

3 changes: 3 additions & 0 deletions Assets/AdncAnimatorHelpers/Editor/Testing/HasParameter.meta

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using Adnc.AnimatorHelpers.Editors.Testing.Utilities;
using Adnc.AnimatorHelpers.HasParameters;
using Adnc.Utility.Testing;
using NUnit.Framework;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Adnc.AnimatorHelpers.Editors.Testing.HasParameters {
[TestFixture(Category = "HasParameter")]
public class TestAnimatorParameters : TestBase {
private AnimatorStub _stub;

[SetUp]
public void Setup () {
_stub = new AnimatorStub();
}

[TearDown]
public void Teardown () {
Object.DestroyImmediate(_stub.Animator.gameObject);
_stub = null;
}

[Test]
public void ErrorsOnNullAnimatorConstructor () {
Assert.Throws<ArgumentNullException>(() => { new AnimatorParameters(null); });
}

[Test]
public void DoesNotCrashOnNullAnimatorParameters () {
_stub.InjectCtrl();
var par = new AnimatorParameters(_stub.Animator);
}

[Test]
public void StoresAllParameters () {
_stub.AnimatorCtrl.AddParameter(new AnimatorControllerParameter {
name = "a",
defaultBool = true,
type = AnimatorControllerParameterType.Bool
});

_stub.InjectCtrl();
var par = new AnimatorParameters(_stub.Animator);

Assert.IsTrue(par.parameters.dic.ContainsKey("a"));
}

[Test]
public void StoresAllBools () {
_stub.AnimatorCtrl.AddParameter(new AnimatorControllerParameter {
name = "a",
defaultBool = true,
type = AnimatorControllerParameterType.Bool
});

_stub.InjectCtrl();
var par = new AnimatorParameters(_stub.Animator);

Assert.IsTrue(par.bools.dic.ContainsKey("a"));
}

[Test]
public void StoresAllFloats () {
_stub.AnimatorCtrl.AddParameter(new AnimatorControllerParameter {
name = "a",
defaultFloat = 1,
type = AnimatorControllerParameterType.Float
});

_stub.InjectCtrl();
var par = new AnimatorParameters(_stub.Animator);

Assert.IsTrue(par.floats.dic.ContainsKey("a"));
}

[Test]
public void StoresAllInts () {
_stub.AnimatorCtrl.AddParameter(new AnimatorControllerParameter {
name = "a",
defaultInt = 1,
type = AnimatorControllerParameterType.Int
});

_stub.InjectCtrl();
var par = new AnimatorParameters(_stub.Animator);

Assert.IsTrue(par.ints.dic.ContainsKey("a"));
}

[Test]
public void StoresAllTriggers () {
_stub.AnimatorCtrl.AddParameter(new AnimatorControllerParameter {
name = "a",
type = AnimatorControllerParameterType.Trigger
});

_stub.InjectCtrl();
var par = new AnimatorParameters(_stub.Animator);

Assert.IsTrue(par.triggers.dic.ContainsKey("a"));
}
}
}
Loading

0 comments on commit 62d0bd6

Please sign in to comment.