2020-01-14 22:43:39 +00:00
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2020-01-14 17:47:19 +00:00
|
|
|
using System;
|
2020-01-14 22:36:30 +00:00
|
|
|
using System.Collections.Generic;
|
2020-01-14 17:47:19 +00:00
|
|
|
|
|
|
|
namespace SemiColinGames.Tests {
|
|
|
|
[TestClass]
|
|
|
|
public class HistoryTests {
|
|
|
|
[TestMethod]
|
|
|
|
public void TestLength() {
|
|
|
|
var h = new History<int>(3);
|
|
|
|
Assert.AreEqual(3, h.Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
public void TestGetFromEmpty() {
|
|
|
|
var ints = new History<int>(3);
|
|
|
|
Assert.AreEqual(0, ints[0]);
|
|
|
|
Assert.AreEqual(0, ints[1]);
|
|
|
|
Assert.AreEqual(0, ints[2]);
|
|
|
|
|
|
|
|
var objects = new History<Object>(1);
|
|
|
|
Assert.AreEqual(null, objects[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
public void TestAdds() {
|
|
|
|
var h = new History<int>(3);
|
2020-01-14 22:36:30 +00:00
|
|
|
Assert.AreEqual("0 0 0", String.Join(" ", h.ToArray()));
|
2020-01-14 17:47:19 +00:00
|
|
|
h.Add(2);
|
2020-01-14 22:36:30 +00:00
|
|
|
Assert.AreEqual("2 0 0", String.Join(" ", h.ToArray()));
|
2020-01-14 17:47:19 +00:00
|
|
|
h.Add(3);
|
|
|
|
h.Add(5);
|
2020-01-14 22:36:30 +00:00
|
|
|
Assert.AreEqual("5 3 2", String.Join(" ", h.ToArray()));
|
2020-01-14 17:47:19 +00:00
|
|
|
h.Add(7);
|
2020-01-14 22:36:30 +00:00
|
|
|
Assert.AreEqual("7 5 3", String.Join(" ", h.ToArray()));
|
2020-01-14 17:47:19 +00:00
|
|
|
h.Add(11);
|
|
|
|
h.Add(13);
|
2020-01-14 22:36:30 +00:00
|
|
|
Assert.AreEqual("13 11 7", String.Join(" ", h.ToArray()));
|
2020-01-14 17:47:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
public void TestThrowsExceptions() {
|
|
|
|
var h = new History<int>(3);
|
|
|
|
Assert.ThrowsException<IndexOutOfRangeException>(() => h[-1]);
|
|
|
|
Assert.ThrowsException<IndexOutOfRangeException>(() => h[3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|