56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
using System;
|
|
using Xunit;
|
|
|
|
namespace SemiColinGames.Tests {
|
|
|
|
public class HistoryTests {
|
|
public static int[] ToArray(History<int> history) {
|
|
int[] result = new int[history.Length];
|
|
for (int i = 0; i < history.Length; i++) {
|
|
result[i] = history[i];
|
|
}
|
|
return result;
|
|
}
|
|
|
|
[Fact]
|
|
public void TestLength() {
|
|
var h = new History<int>(3);
|
|
Assert.Equal(3, h.Length);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestGetFromEmpty() {
|
|
var ints = new History<int>(3);
|
|
Assert.Equal(0, ints[0]);
|
|
Assert.Equal(0, ints[1]);
|
|
Assert.Equal(0, ints[2]);
|
|
|
|
var objects = new History<Object>(1);
|
|
Assert.Null(objects[0]);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestAdds() {
|
|
var h = new History<int>(3);
|
|
Assert.Equal("0 0 0", String.Join(" ", ToArray(h)));
|
|
h.Add(2);
|
|
Assert.Equal("2 0 0", String.Join(" ", ToArray(h)));
|
|
h.Add(3);
|
|
h.Add(5);
|
|
Assert.Equal("5 3 2", String.Join(" ", ToArray(h)));
|
|
h.Add(7);
|
|
Assert.Equal("7 5 3", String.Join(" ", ToArray(h)));
|
|
h.Add(11);
|
|
h.Add(13);
|
|
Assert.Equal("13 11 7", String.Join(" ", ToArray(h)));
|
|
}
|
|
|
|
[Fact]
|
|
public void TestThrowsExceptions() {
|
|
var h = new History<int>(3);
|
|
Assert.Throws<IndexOutOfRangeException>(() => h[-1]);
|
|
Assert.Throws<IndexOutOfRangeException>(() => h[3]);
|
|
}
|
|
}
|
|
}
|