Skip to content

Instantly share code, notes, and snippets.

@raveneer
Created February 7, 2018 04:46
Show Gist options
  • Save raveneer/a408230903a47760eed4fddf3df0fa08 to your computer and use it in GitHub Desktop.
Save raveneer/a408230903a47760eed4fddf3df0fa08 to your computer and use it in GitHub Desktop.
example of Tribes.Tests
using System.Collections.Generic;
using NUnit.Framework;
using Zenject;
using Entitas;
namespace UnitTestProject.EntitasSystems
{
class Test_AgingSystem : ZenjectUnitTestFixture
{
[Inject] private Contexts _contexts;
[Inject] private AgingSystem _agingSystem;
[SetUp]
public void install()
{
Container.Bind<Contexts>().FromNew().AsSingle();
Container.Bind<AgingSystem>().AsSingle();
Container.Inject(this);
}
[Test]
public void Reactive_WithGameTime_Increse_AgeValue()
{
_contexts.game.SetIncresedHourCurrentTick(1);
//arrange
var entity = _contexts.game.CreateEntity();
entity.AddAge(0);
_agingSystem.IncreseAgePerhourRandomMin = 1;
_agingSystem.IncreseAgePerhourRandomMax = 1;
//action
_agingSystem.Initialize();
_agingSystem.Execute();
//assert
Assert.AreEqual(1, entity.age.Value);
//reactive
_contexts.game.ReplaceIncresedHourCurrentTick(1);
_agingSystem.Execute();
Assert.AreEqual(2, entity.age.Value);
}
//나이가 많아 죽음 상태인 엔티티는 성장시키지 않는다.
[Test]
public void Not_Ageing_If_Entity_HaveOldDeath()
{
_contexts.game.SetIncresedHourCurrentTick(1);
//arrange
var entity = _contexts.game.CreateEntity();
entity.AddAge(0);
entity.AddAgeState(AgeState.OldDeath);
//action
_contexts.game.ReplaceIncresedHourCurrentTick(1);
_agingSystem.Execute();
//assert
Assert.AreEqual(0, entity.age.Value);
}
//나이가 많은 엔티티는 Destroying 태그를 붙인다.
[Test]
public void AddDestroyingTag_oldDeathEntity()
{
_contexts.game.SetIncresedHourCurrentTick(1);
//arrange|
var oldEntity = _contexts.game.CreateEntity();
oldEntity.AddAge(0);
oldEntity.AddAgeState(AgeState.OldDeath);
//action
_contexts.game.ReplaceIncresedHourCurrentTick(1);
_agingSystem.Execute();
//assert
Assert.AreEqual(true, oldEntity.isDestroying);
}
[TestCase(0, 0)]
[TestCase(2.5f, 2.5f)]
[Test]
public void IncreseAge_ByGameSpeed(float hourpassed, float expectedAge)
{
_contexts.game.SetIncresedHourCurrentTick(1);
//arrange
var entity = _contexts.game.CreateEntity();
entity.AddAge(0);
_agingSystem.IncreseAgePerhourRandomMin = 1;
_agingSystem.IncreseAgePerhourRandomMax = 1;
//action
_contexts.game.ReplaceIncresedHourCurrentTick(hourpassed);
_agingSystem.Initialize();
_agingSystem.Execute();
//assert
Assert.AreEqual(expectedAge, entity.age.Value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment