2020-01-18 03:41:45 +00:00
|
|
|
using System;
|
2020-11-18 19:03:19 +00:00
|
|
|
using Xunit;
|
2020-01-18 03:41:45 +00:00
|
|
|
|
|
|
|
namespace SemiColinGames.Tests {
|
2020-11-18 19:03:19 +00:00
|
|
|
|
2020-01-18 03:41:45 +00:00
|
|
|
public class HistoryTests {
|
2020-03-18 18:03:37 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-11-18 19:03:19 +00:00
|
|
|
[Fact]
|
2020-01-18 03:41:45 +00:00
|
|
|
public void TestLength() {
|
|
|
|
var h = new History<int>(3);
|
2020-11-18 19:03:19 +00:00
|
|
|
Assert.Equal(3, h.Length);
|
2020-01-18 03:41:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 19:03:19 +00:00
|
|
|
[Fact]
|
2020-01-18 03:41:45 +00:00
|
|
|
public void TestGetFromEmpty() {
|
|
|
|
var ints = new History<int>(3);
|
2020-11-18 19:03:19 +00:00
|
|
|
Assert.Equal(0, ints[0]);
|
|
|
|
Assert.Equal(0, ints[1]);
|
|
|
|
Assert.Equal(0, ints[2]);
|
2020-01-18 03:41:45 +00:00
|
|
|
|
|
|
|
var objects = new History<Object>(1);
|
2020-11-18 19:03:19 +00:00
|
|
|
Assert.Null(objects[0]);
|
2020-01-18 03:41:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 19:03:19 +00:00
|
|
|
[Fact]
|
2020-01-18 03:41:45 +00:00
|
|
|
public void TestAdds() {
|
|
|
|
var h = new History<int>(3);
|
2020-11-18 19:03:19 +00:00
|
|
|
Assert.Equal("0 0 0", String.Join(" ", ToArray(h)));
|
2020-01-18 03:41:45 +00:00
|
|
|
h.Add(2);
|
2020-11-18 19:03:19 +00:00
|
|
|
Assert.Equal("2 0 0", String.Join(" ", ToArray(h)));
|
2020-01-18 03:41:45 +00:00
|
|
|
h.Add(3);
|
|
|
|
h.Add(5);
|
2020-11-18 19:03:19 +00:00
|
|
|
Assert.Equal("5 3 2", String.Join(" ", ToArray(h)));
|
2020-01-18 03:41:45 +00:00
|
|
|
h.Add(7);
|
2020-11-18 19:03:19 +00:00
|
|
|
Assert.Equal("7 5 3", String.Join(" ", ToArray(h)));
|
2020-01-18 03:41:45 +00:00
|
|
|
h.Add(11);
|
|
|
|
h.Add(13);
|
2020-11-18 19:03:19 +00:00
|
|
|
Assert.Equal("13 11 7", String.Join(" ", ToArray(h)));
|
2020-01-18 03:41:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 19:03:19 +00:00
|
|
|
[Fact]
|
2020-01-18 03:41:45 +00:00
|
|
|
public void TestThrowsExceptions() {
|
|
|
|
var h = new History<int>(3);
|
2020-11-18 19:03:19 +00:00
|
|
|
Assert.Throws<IndexOutOfRangeException>(() => h[-1]);
|
|
|
|
Assert.Throws<IndexOutOfRangeException>(() => h[3]);
|
2020-01-18 03:41:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|