using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using JacekMatulewski.Collections; namespace HistoryUnitTests { [TestClass] public class HistoryTesty { private const int capacity = 5; private History createHistory() { return new History(capacity); } [TestMethod] public void CreatingTest() { History h = createHistory(); } [TestMethod] public void CreatingTest2() { History h = createHistory(); Assert.AreEqual(0, h.Count); } [TestMethod] public void PushingAndPopingTest() { History h = createHistory(); string s = "coś"; h.Push(s); Assert.AreEqual(1, h.Count); string _s = h.Peek(); Assert.AreEqual(s, _s); _s = h.Pop(); Assert.AreEqual(0, h.Count); Assert.AreEqual(s, _s); } [TestMethod] public void PushingAndPopingTest2() { History h = createHistory(); string s1 = "coś1"; string s2 = "coś2"; h.Push(s1); Assert.AreEqual(1, h.Count); string __s1 = h.Peek(); Assert.AreEqual(s1, __s1); h.Push(s2); Assert.AreEqual(2, h.Count); string __s2 = h.Peek(); Assert.AreEqual(s2, __s2); string _s2 = h.Pop(); Assert.AreEqual(1, h.Count); Assert.AreEqual(s2, _s2); __s1 = h.Peek(); Assert.AreEqual(s1, __s1); string _s1 = h.Pop(); Assert.AreEqual(0, h.Count); Assert.AreEqual(s1, _s1); } [TestMethod] public void ClearTest() { History h = createHistory(); string s1 = "coś1"; string s2 = "coś2"; h.Push(s1); h.Push(s2); Assert.AreEqual(2, h.Count); h.Clear(); Assert.AreEqual(0, h.Count); } [TestMethod] [ExpectedException(typeof(EmptyHistoryException))] public void PopingFromEmptyTest() { History h = createHistory(); string s = h.Pop(); } [TestMethod] public void CapscityTest() { History h = createHistory(); for (int i = 0; i < 10; ++i) { h.Push(i.ToString()); if (i < capacity) Assert.AreEqual(i + 1, h.Count); else Assert.AreEqual(capacity, h.Count); } } [TestMethod] public void PushingSameValuesTest() { History h = createHistory(); string s = "coś"; for (int i = 0; i < 10; ++i) { h.Push(s); Assert.AreEqual(1, h.Count); } Assert.AreEqual(1, h.Count); string _s = h.Peek(); Assert.AreEqual(s, _s); _s = h.Pop(); Assert.AreEqual(0, h.Count); Assert.AreEqual(s, _s); } [TestMethod] public void ValuesTest() { History h = createHistory(); string s1 = "coś1"; string s2 = "coś2"; h.Push(s1); h.Push(s2); Assert.AreEqual(2, h.Count); string[] st = h.Values; Assert.AreEqual(2, st.Length); Assert.AreEqual(s2, st[0]); Assert.AreEqual(s1, st[1]); } [TestMethod] public void ValuesTest2() { History h = createHistory(); int n = 10; for (int i = 0; i < n; ++i) h.Push(i.ToString()); Assert.AreEqual(capacity, h.Count); string[] st = h.Values; Assert.AreEqual(capacity, st.Length); for(int i = 0; i < st.Length; ++i) { Assert.AreEqual((n - 1 - i).ToString(), st[i]); } } } }