Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. using System;
  2. using CustomLinkedList;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using System.Collections.Generic;
  5.  
  6. namespace UnitTestProject1.DynamicList.Tests
  7. {
  8. [TestClass]
  9. public class DynamicListTests
  10. {
  11. private DynamicList<int> dynamListTest;
  12.  
  13. [TestInitialize]
  14. public void DynamicListInitilizer()
  15. {
  16. this.dynamListTest = new DynamicList<int>();
  17. for (int i = 0; i < 5; i++)
  18. {
  19. dynamListTest.Add(i);
  20. }
  21. }
  22.  
  23. [TestMethod]
  24. public void TestCount()
  25. {
  26. dynamListTest.Add(5);
  27. Assert.AreEqual(6, dynamListTest.Count);
  28. }
  29.  
  30. [TestMethod]
  31. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  32. public void TestSetInvalidIndex()
  33. {
  34. var index = dynamListTest[10];
  35. }
  36.  
  37. [TestMethod]
  38. public void TestAddItemAtTheEndOfList()
  39. {
  40. for (int i = 0; i < 5; i++)
  41. {
  42. dynamListTest.Add(i);
  43. Assert.AreEqual(i, dynamListTest[i], "Does not add the right item at the end of the list.");
  44. }
  45. }
  46.  
  47. [TestMethod]
  48. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  49. public void TestRemoveElementAtNegativeIndex()
  50. {
  51. dynamListTest.RemoveAt(-2);
  52. }
  53.  
  54. [TestMethod]
  55. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  56. public void TestRemoveElementAtGraterThanCountIndex()
  57. {
  58. dynamListTest.RemoveAt(dynamListTest.Count + 1);
  59. }
  60.  
  61. [TestMethod]
  62. public void TestRemoveElementsAtGivenIndex()
  63. {
  64. dynamListTest.RemoveAt(2);
  65. Assert.AreEqual(3, dynamListTest[2], "Returns wrong element after removal.");
  66. }
  67.  
  68. [TestMethod]
  69. public void TestRemoveExistingElementAndReturnsIndex()
  70. {
  71. Assert.AreEqual(3, dynamListTest.Remove(3));
  72. }
  73.  
  74. [TestMethod]
  75. public void TestRemoveUneistingElementAndReturnsIndex()
  76. {
  77. Assert.AreEqual(-1, dynamListTest.Remove(7));
  78. }
  79.  
  80. [TestMethod]
  81. public void TestSearchOfExistingElementAndReturnFirstOccurenceIndex()
  82. {
  83. Assert.AreEqual(3, dynamListTest.IndexOf(3));
  84. }
  85.  
  86. [TestMethod]
  87. public void TestSearchOfUnexistingElementAndReturnNegativeIndex()
  88. {
  89. Assert.AreEqual(-1, dynamListTest.IndexOf(7));
  90. }
  91.  
  92. [TestMethod]
  93. public void TestIfListContainsExistingElement()
  94. {
  95. Assert.IsTrue(dynamListTest.Contains(2));
  96. }
  97.  
  98. [TestMethod]
  99. public void TestIfListContainsUnexistingElement()
  100. {
  101. Assert.IsFalse(dynamListTest.Contains(10));
  102. }
  103.  
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement