Advertisement
Guest User

Untitled

a guest
Feb 20th, 2015
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 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 TestAddItemAtTheEndOfList()
  25. {
  26. for (int i = 0; i < 5; i++)
  27. {
  28. dynamListTest.Add(i);
  29. Assert.AreEqual(i, dynamListTest[i], "Does not add the right item at the end of the list.");
  30. }
  31. }
  32.  
  33. [TestMethod]
  34. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  35. public void TestRemoveElementAtNegativeIndex()
  36. {
  37. dynamListTest.RemoveAt(-2);
  38. }
  39.  
  40. [TestMethod]
  41. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  42. public void TestRemoveElementAtGraterThanCountIndex()
  43. {
  44. dynamListTest.RemoveAt(dynamListTest.Count+1);
  45. }
  46.  
  47. [TestMethod]
  48. public void TestRemoveElementsAtGivenIndex()
  49. {
  50. dynamListTest.RemoveAt(2);
  51. Assert.AreEqual(3, dynamListTest[2], "Returns wrong element after removal.");
  52. }
  53.  
  54. [TestMethod]
  55. public void TestRemoveExistingElementAndReturnsIndex()
  56. {
  57. Assert.AreEqual(3, dynamListTest.Remove(3));
  58. }
  59.  
  60. [TestMethod]
  61. public void TestRemoveUneistingElementAndReturnsIndex()
  62. {
  63. Assert.AreEqual(-1, dynamListTest.Remove(7));
  64. }
  65.  
  66. [TestMethod]
  67. public void TestSearchOfExistingElementAndReturnFirstOccurenceIndex()
  68. {
  69. Assert.AreEqual(3, dynamListTest.IndexOf(3));
  70. }
  71.  
  72. [TestMethod]
  73. public void TestSearchOfUnexistingElementAndReturnNegativeIndex()
  74. {
  75. Assert.AreEqual(-1, dynamListTest.IndexOf(7));
  76. }
  77.  
  78. [TestMethod]
  79. public void TestIfListContainsExistingElement()
  80. {
  81. Assert.IsTrue(dynamListTest.Contains(2));
  82. }
  83.  
  84. [TestMethod]
  85. public void TestIfListContainsUnexistingElement()
  86. {
  87. Assert.IsFalse(dynamListTest.Contains(10));
  88. }
  89.  
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement