Browse Source

move History.ToArray() into test code.

master
Colin McMillen 4 years ago
parent
commit
67550a789b
  1. 10
      Shared/History.cs
  2. 18
      SharedTests/HistoryTests.cs

10
Shared/History.cs

@ -49,15 +49,5 @@ namespace SemiColinGames {
return items[lookup];
}
}
// This creates and populates a new array. It's O(n) and should probably only be used for tests.
// TODO: restrict visibility so that it can only be used by tests.
public T[] ToArray() {
T[] result = new T[items.Length];
for (int i = 0; i < items.Length; i++) {
result[i] = this[i];
}
return result;
}
}
}

18
SharedTests/HistoryTests.cs

@ -4,6 +4,14 @@ using System;
namespace SemiColinGames.Tests {
[TestClass]
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;
}
[TestMethod]
public void TestLength() {
var h = new History<int>(3);
@ -24,17 +32,17 @@ namespace SemiColinGames.Tests {
[TestMethod]
public void TestAdds() {
var h = new History<int>(3);
Assert.AreEqual("0 0 0", String.Join(" ", h.ToArray()));
Assert.AreEqual("0 0 0", String.Join(" ", ToArray(h)));
h.Add(2);
Assert.AreEqual("2 0 0", String.Join(" ", h.ToArray()));
Assert.AreEqual("2 0 0", String.Join(" ", ToArray(h)));
h.Add(3);
h.Add(5);
Assert.AreEqual("5 3 2", String.Join(" ", h.ToArray()));
Assert.AreEqual("5 3 2", String.Join(" ", ToArray(h)));
h.Add(7);
Assert.AreEqual("7 5 3", String.Join(" ", h.ToArray()));
Assert.AreEqual("7 5 3", String.Join(" ", ToArray(h)));
h.Add(11);
h.Add(13);
Assert.AreEqual("13 11 7", String.Join(" ", h.ToArray()));
Assert.AreEqual("13 11 7", String.Join(" ", ToArray(h)));
}
[TestMethod]

Loading…
Cancel
Save