yep
This commit is contained in:
@@ -1,44 +1,22 @@
|
||||
using AutoFixture;
|
||||
using FluentAssertions;
|
||||
using FluentAssertions.Execution;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using PathFinding;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Gameboard.ShogiUI.UnitTests.PathFinding
|
||||
{
|
||||
[TestClass]
|
||||
public class PlanarCollectionShould
|
||||
{
|
||||
private class SimpleElement : IPlanarElement
|
||||
{
|
||||
public static int Seed { get; private set; }
|
||||
public MoveSet MoveSet => null;
|
||||
public bool IsUpsideDown => false;
|
||||
|
||||
|
||||
public SimpleElement()
|
||||
{
|
||||
Seed = Seed++;
|
||||
}
|
||||
}
|
||||
|
||||
private Fixture fixture;
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
fixture = new Fixture();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Index()
|
||||
{
|
||||
// Arrange
|
||||
var collection = new PlanarCollection<SimpleElement>(10, 10);
|
||||
var expected1 = new SimpleElement();
|
||||
var expected2 = new SimpleElement();
|
||||
var collection = new TestPlanarCollection();
|
||||
var expected1 = new SimpleElement(1);
|
||||
var expected2 = new SimpleElement(2);
|
||||
|
||||
// Act
|
||||
collection[0, 0] = expected1;
|
||||
@@ -53,40 +31,27 @@ namespace Gameboard.ShogiUI.UnitTests.PathFinding
|
||||
public void Iterate()
|
||||
{
|
||||
// Arrange
|
||||
var expected = new List<SimpleElement>();
|
||||
for (var i = 0; i < 9; i++) expected.Add(new SimpleElement());
|
||||
var collection = new PlanarCollection<SimpleElement>(3, 3);
|
||||
for (var x = 0; x < 3; x++)
|
||||
for (var y = 0; y < 3; y++)
|
||||
collection[x, y] = expected[x + y];
|
||||
var planarCollection = new TestPlanarCollection();
|
||||
planarCollection[0, 0] = new SimpleElement(1);
|
||||
planarCollection[0, 1] = new SimpleElement(2);
|
||||
planarCollection[0, 2] = new SimpleElement(3);
|
||||
planarCollection[1, 0] = new SimpleElement(4);
|
||||
planarCollection[1, 1] = new SimpleElement(5);
|
||||
|
||||
// Act
|
||||
var actual = new List<SimpleElement>();
|
||||
foreach (var elem in collection)
|
||||
foreach (var elem in planarCollection)
|
||||
actual.Add(elem);
|
||||
|
||||
// Assert
|
||||
actual.Should().BeEquivalentTo(expected);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Yep()
|
||||
{
|
||||
var collection = new PlanarCollection<SimpleElement>(3, 3);
|
||||
collection[0, 0] = new SimpleElement();
|
||||
collection[1, 0] = new SimpleElement();
|
||||
collection[0, 1] = new SimpleElement();
|
||||
|
||||
// Act
|
||||
var array2d = new SimpleElement[3, 3];
|
||||
for (var x = 0; x < 3; x++)
|
||||
for (var y = 0; y < 3; y++)
|
||||
{
|
||||
array2d[x, y] = collection[x, y];
|
||||
}
|
||||
|
||||
|
||||
Console.WriteLine("hey");
|
||||
using (new AssertionScope())
|
||||
{
|
||||
actual[0].Number.Should().Be(1);
|
||||
actual[1].Number.Should().Be(2);
|
||||
actual[2].Number.Should().Be(3);
|
||||
actual[3].Number.Should().Be(4);
|
||||
actual[4].Number.Should().Be(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using PathFinding;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Gameboard.ShogiUI.UnitTests.PathFinding
|
||||
{
|
||||
public class SimpleElement : IPlanarElement
|
||||
{
|
||||
public int Number { get; }
|
||||
public MoveSet MoveSet => null;
|
||||
public bool IsUpsideDown => false;
|
||||
|
||||
public SimpleElement(int number)
|
||||
{
|
||||
Number = number;
|
||||
}
|
||||
}
|
||||
|
||||
public class TestPlanarCollection : IPlanarCollection<SimpleElement>
|
||||
{
|
||||
private readonly SimpleElement[,] array;
|
||||
public TestPlanarCollection()
|
||||
{
|
||||
array = new SimpleElement[3, 3];
|
||||
}
|
||||
public SimpleElement this[int x, int y]
|
||||
{
|
||||
get => array[x, y];
|
||||
set => array[x, y] = value;
|
||||
}
|
||||
public SimpleElement this[Vector2 vector]
|
||||
{
|
||||
get => this[(int)vector.X, (int)vector.Y];
|
||||
set => this[(int)vector.X, (int)vector.Y] = value;
|
||||
}
|
||||
|
||||
public IEnumerator<SimpleElement> GetEnumerator()
|
||||
{
|
||||
foreach (var e in array)
|
||||
yield return e;
|
||||
}
|
||||
//IEnumerator IEnumerable.GetEnumerator()
|
||||
//{
|
||||
// return array.GetEnumerator();
|
||||
//}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user