Created
February 7, 2018 04:48
-
-
Save raveneer/cbb032c2b3220a8d5086102c1b00f123 to your computer and use it in GitHub Desktop.
example of Tribes.Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using NUnit.Framework; | |
using Zenject; | |
namespace UnitTestProject | |
{ | |
[TestFixture] | |
[Category("")] | |
public class Test_MapSpec : ZenjectUnitTestFixture | |
{ | |
[SetUp] | |
public void Install() | |
{ | |
Container.Bind<EventManager>().AsSingle(); | |
Container.Inject(this); | |
} | |
[Test] | |
public void Test_GetRadiousCells() | |
{ | |
//맵을 만든다. | |
//□□□□□ | |
//□□□□□ | |
//□□□□□ | |
//□□□□□ | |
//□□□□□ | |
var mapSpec = new MapSpec(5, 5, 1, 1, false); | |
//□□□□□ | |
//□■■■□ | |
//□■■■□ | |
//□■■■□ | |
//□□□□□ | |
var result = mapSpec.GetRadiousCoordsWithSpiral(1, new Coord(2, 2)); | |
Assert.AreEqual(9, result.Count); | |
Assert.AreEqual(new Coord(2, 2), result[0]); | |
} | |
[Test] | |
public void Test_GetRadiousCells_CutOutOfMap() | |
{ | |
var mapSpec = new MapSpec(5, 5, 1, 1, false); | |
//□□□□□ | |
//□□□□□ | |
//□□□□□ | |
//■■□□□ | |
//■■□□□ | |
var result1 = mapSpec.GetRadiousCoordsWithSpiral(1, new Coord(0, 0)); | |
Assert.AreEqual(4, result1.Count); | |
Assert.AreEqual(new Coord(0, 0), result1[0]); | |
//□□□□□ | |
//■■■■□ | |
//■■■■□ | |
//■■■■□ | |
//■■■■□ | |
var result2 = mapSpec.GetRadiousCoordsWithSpiral(2, new Coord(1, 1)); | |
Assert.AreEqual(16, result2.Count); | |
Assert.AreEqual(new Coord(1, 1), result2[0]); | |
} | |
[Test] | |
public void GetRadiousCoordsWithSpiral_ExceptSelf() | |
{ | |
var mapSpec = new MapSpec(5, 5, 1, 1, false); | |
//□□□□□ | |
//□□□□□ | |
//□□□□□ | |
//■■□□□ | |
//□■□□□ | |
var result1 = mapSpec.GetRadiousCoordsWithSpiralExceptSelf(1, new Coord(0, 0)); | |
Assert.AreEqual(3, result1.Count()); | |
Assert.IsFalse(result1.Contains(new Coord(0,0))); | |
//□□□□□ | |
//■■■■□ | |
//■■■■□ | |
//■□■■□ | |
//■■■■□ | |
var result2 = mapSpec.GetRadiousCoordsWithSpiralExceptSelf(2, new Coord(1, 1)); | |
Assert.AreEqual(15, result2.Count()); | |
Assert.IsFalse(result2.Contains(new Coord(1, 1))); | |
} | |
[Test] | |
public void GetOutlineCoords_ReturnsOutline() | |
{ | |
var mapSpec = new MapSpec(5, 5, 1, 1, false); | |
//□□□□□ | |
//□□□□□ | |
//□□□□□ | |
//■■□□□ | |
//□■□□□ | |
var result1 = mapSpec.GetSquareOutlineCoords(1, new Coord(0, 0)); | |
Assert.AreEqual(3, result1.Count()); | |
Assert.IsFalse(result1.Contains(new Coord(0, 0))); | |
//□□□□□ | |
//■■■■□ | |
//□□□■□ | |
//□□□■□ | |
//□□□■□ | |
var result2 = mapSpec.GetSquareOutlineCoords(2, new Coord(1, 1)); | |
Assert.AreEqual(7, result2.Count()); | |
Assert.IsFalse(result2.Contains(new Coord(1, 1))); | |
} | |
[Test] | |
public void IsInOutline() | |
{ | |
var mapSpec = new MapSpec(5, 5, 1, 1, false); | |
//□□□□□ | |
//□□□□□ | |
//□□□□□ | |
//■■□□□ | |
//□■□□□ | |
Assert.AreEqual(true, mapSpec.IsInOutline(new Coord(1, 1), 1, Coord.zero )); | |
Assert.AreEqual(true, mapSpec.IsInOutline(new Coord(1, 0), 1, Coord.zero)); | |
Assert.AreEqual(true, mapSpec.IsInOutline(new Coord(0, 1), 1, Coord.zero)); | |
} | |
[Test] | |
public void Test_Init() | |
{ | |
var mapSpec = new MapSpec(1, 2, 3, 4, true); | |
Assert.AreEqual(1, mapSpec.TileCount_X); | |
Assert.AreEqual(2, mapSpec.TileCount_Y); | |
Assert.AreEqual(3, mapSpec.TileWidth); | |
Assert.AreEqual(4, mapSpec.GraphicDividen); | |
Assert.AreEqual(true, mapSpec.IsAutoGenMapEntity); | |
} | |
[Test] | |
public void ThrowException_MinusRange() | |
{ | |
var mapSpec = new MapSpec(5, 5, 1, 1, false); | |
Assert.That(() => mapSpec.GetRadiousCoordsWithSpiral(-1, new Coord(0, 0)), Throws.Exception); | |
} | |
[Test] | |
public void ThrowException_OutofMap() | |
{ | |
var mapSpec = new MapSpec(5, 5, 1, 1, false); | |
Assert.That(() => mapSpec.GetRadiousCoordsWithSpiral(0, new Coord(-1, -1)), Throws.Exception); | |
} | |
[Test] | |
public void GetCenter_ReturnRoundedCenterCoord() | |
{ | |
var mapSpec1 = new MapSpec(5, 5, 1, 1, false); | |
Assert.AreEqual(new Coord(2, 2), mapSpec1.Center ); | |
var mapSpec2 = new MapSpec(6, 6, 1, 1, false); | |
Assert.AreEqual(new Coord(3, 3), mapSpec2.Center); | |
} | |
[Test] | |
public void GetAllCoords() | |
{ | |
var mapSpec1 = new MapSpec(5, 5, 1, 1, false); | |
Assert.AreEqual(25, mapSpec1.GetAllCoords().Count); | |
var mapSpec2 = new MapSpec(6, 7, 1, 1, false); | |
Assert.AreEqual(42, mapSpec2.GetAllCoords().Count); | |
} | |
[Test] | |
public void Test_GetCoordInRectangle_ExcludeOutOfMap() | |
{ | |
var mapSpec = new MapSpec(5, 5, 1, 1, false); | |
Assert.AreEqual(new List<Coord>{new Coord(0,0), new Coord(0,1), new Coord(1,0), new Coord(1,1)} , mapSpec.GetCoordInRectangle(new Coord( -1, 0), new Coord(1,1))); | |
} | |
[Test] | |
public void Test_GetTrueOutline4WayCoords_Returns4coordOutLine() | |
{ | |
var mapSpec = new MapSpec(5, 5, 1, 1, false); | |
//□□□□□ | |
//□□■□□ | |
//□■@■□ | |
//□□■□□ | |
//□□□□□ | |
var outlineCoords = mapSpec.GetTrueOutline4WayCoords(new List<Coord>() {new Coord(2, 2)}); | |
Assert.AreEqual(4, outlineCoords.Count()); | |
Assert.IsTrue(outlineCoords.Contains(new Coord(3, 2))); | |
Assert.IsTrue(outlineCoords.Contains(new Coord(1, 2))); | |
Assert.IsTrue(outlineCoords.Contains(new Coord(2, 1))); | |
Assert.IsTrue(outlineCoords.Contains(new Coord(2, 3))); | |
} | |
[Test] | |
public void Test_GetTrueOutline4WayCoords_Returns_InMap() | |
{ | |
var mapSpec = new MapSpec(5, 5, 1, 1, false); | |
//□□□□□ | |
//□□□□□ | |
//□□□□□ | |
//■□□□□ | |
//@■□□□ | |
var outlineCoords = mapSpec.GetTrueOutline4WayCoords(new List<Coord>() { new Coord(0, 0) }); | |
Assert.AreEqual(2, outlineCoords.Count()); | |
Assert.IsTrue(outlineCoords.Contains(new Coord(1, 0))); | |
Assert.IsTrue(outlineCoords.Contains(new Coord(0, 1))); | |
} | |
[Test] | |
public void Test_GetTrueOutline4WayCoords_ReturnsMixedShape() | |
{ | |
var mapSpec = new MapSpec(5, 5, 1, 1, false); | |
//□□■□□ | |
//□■@■□ | |
//□■@■□ | |
//□□■□□ | |
//□□□□□ | |
var outlineCoords = mapSpec.GetTrueOutline4WayCoords(new List<Coord>() { new Coord(2, 2), new Coord(2,3) }); | |
Assert.AreEqual(6, outlineCoords.Count()); | |
Assert.IsTrue(outlineCoords.Contains(new Coord(3, 2))); | |
Assert.IsTrue(outlineCoords.Contains(new Coord(1, 2))); | |
Assert.IsTrue(outlineCoords.Contains(new Coord(2, 1))); | |
Assert.IsTrue(outlineCoords.Contains(new Coord(2, 4))); | |
Assert.IsTrue(outlineCoords.Contains(new Coord(3, 3))); | |
Assert.IsTrue(outlineCoords.Contains(new Coord(1, 3))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment