History: add ToArray() method to make tests cleaner
GitOrigin-RevId: 5bbf5be614ed6c2d9884ac924ab627ccaa57e355
This commit is contained in:
parent
3f6fc67cb6
commit
960521a6e0
@ -49,5 +49,14 @@ namespace SemiColinGames {
|
||||
return items[lookup];
|
||||
}
|
||||
}
|
||||
|
||||
// This creates and populates a new array. It's O(n) and should probably only be used for tests.
|
||||
public T[] ToArray() {
|
||||
T[] result = new T[items.Length];
|
||||
for (int i = 0; i < items.Length; i++) {
|
||||
result[i] = this[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SemiColinGames.Tests {
|
||||
[TestClass]
|
||||
@ -24,17 +25,17 @@ namespace SemiColinGames.Tests {
|
||||
[TestMethod]
|
||||
public void TestAdds() {
|
||||
var h = new History<int>(3);
|
||||
Assert.AreEqual("0 0 0", String.Format("{0} {1} {2}", h[0], h[1], h[2]));
|
||||
Assert.AreEqual("0 0 0", String.Join(" ", h.ToArray()));
|
||||
h.Add(2);
|
||||
Assert.AreEqual("2 0 0", String.Format("{0} {1} {2}", h[0], h[1], h[2]));
|
||||
Assert.AreEqual("2 0 0", String.Join(" ", h.ToArray()));
|
||||
h.Add(3);
|
||||
h.Add(5);
|
||||
Assert.AreEqual("5 3 2", String.Format("{0} {1} {2}", h[0], h[1], h[2]));
|
||||
Assert.AreEqual("5 3 2", String.Join(" ", h.ToArray()));
|
||||
h.Add(7);
|
||||
Assert.AreEqual("7 5 3", String.Format("{0} {1} {2}", h[0], h[1], h[2]));
|
||||
Assert.AreEqual("7 5 3", String.Join(" ", h.ToArray()));
|
||||
h.Add(11);
|
||||
h.Add(13);
|
||||
Assert.AreEqual("13 11 7", String.Format("{0} {1} {2}", h[0], h[1], h[2]));
|
||||
Assert.AreEqual("13 11 7", String.Join(" ", h.ToArray()));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
Loading…
Reference in New Issue
Block a user