Advertisement
Guest User

Untitled

a guest
Jul 8th, 2018
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. describe("Test sortedListClass", () => {
  2. let list;
  3.  
  4. beforeEach(() => {
  5. list = new SortedList();
  6. });
  7.  
  8. describe("General tests", () => {
  9. it("constructor should be a function", () => {
  10. expect(typeof SortedList.constructor).to.equal('function');
  11. });
  12.  
  13. it("constructor should take 0 parameters", () => {
  14. expect(SortedList.length).to.equal(0);
  15. });
  16.  
  17. it("instance of the created object should be the class constructor", () => {
  18. let check = list instanceof SortedList;
  19. expect(check).to.be.true;
  20. });
  21.  
  22. it("should have property add", () => {
  23. expect(SortedList.prototype.hasOwnProperty('add')).to.be.true;
  24. });
  25.  
  26. it("add should be a function", () => {
  27. expect(typeof list.add).to.equal('function');
  28. });
  29.  
  30. it("should have property remove", () => {
  31. expect(SortedList.prototype.hasOwnProperty('remove')).to.be.true;
  32. });
  33.  
  34. it("remove should be a function", () => {
  35. expect(typeof list.remove).to.equal('function');
  36. });
  37.  
  38. it("should have property get", () => {
  39. expect(SortedList.prototype.hasOwnProperty('get')).to.be.true;
  40. });
  41.  
  42. it("get should be a function", () => {
  43. expect(typeof list.get).to.equal('function');
  44. });
  45.  
  46. it("should have property size", () => {
  47. expect(SortedList.prototype.hasOwnProperty('size')).to.be.true;
  48. });
  49.  
  50. it("size should only be a getter and return a number", () => {
  51. expect(typeof list.size).to.equal('number');
  52. });
  53.  
  54. it("size should be 0 when the list is created", () => {
  55. expect(list.size).to.equal(0);
  56. });
  57. });
  58.  
  59. describe("Invalid input tests", () => {
  60. it("remove should throw error when list is empty", () => {
  61. expect(() => list.remove(0)).to.throw(Error);
  62. });
  63.  
  64. it("remove should throw error with negative index", () => {
  65. list.add(3);
  66. list.add(4);
  67. expect(() => list.remove(-1)).to.throw(Error);
  68. });
  69.  
  70. it("remove should throw error with index bigger than current length", () => {
  71. list.add(3);
  72. list.add(4);
  73. expect(() => list.remove(2)).to.throw(Error);
  74. });
  75.  
  76. it("get should throw error when list is empty", () => {
  77. expect(() => list.get(0)).to.throw(Error);
  78. });
  79.  
  80. it("get should throw error with negative index", () => {
  81. list.add(3);
  82. list.add(4);
  83. expect(() => list.get(-1)).to.throw(Error);
  84. });
  85.  
  86. it("get should throw error with index bigger than current length", () => {
  87. list.add(3);
  88. list.add(4);
  89. expect(() => list.get(2)).to.throw(Error);
  90. });
  91. });
  92.  
  93. describe("add method tests", () => {
  94. it("should add and maintain ascending order at all times", () => {
  95. list.add(4);
  96. list.add(1);
  97. expect(list.get(0)).to.equal(1);
  98. list.add(7);
  99. list.add(12);
  100. list.add(0);
  101. expect(list.get(0)).to.equal(0);
  102. expect(list.get(list.size - 1)).to.equal(12);
  103. expect(list.get(3)).to.equal(7);
  104. });
  105. });
  106.  
  107. describe("remove method tests", () => {
  108. it("should remove and maintain ascending order at all times", () => {
  109. list.add(19);
  110. list.add(2);
  111. list.add(3);
  112. list.add(222);
  113. list.add(88);
  114. list.remove(0);
  115. expect(list.get(0)).to.equal(3);
  116. expect(list.get(list.size - 1)).to.equal(222);
  117. list.add(999);
  118. list.add(1);
  119. list.add(444);
  120. list.remove(list.size - 1);
  121. expect(list.get(list.size - 1)).to.equal(444);
  122. expect(list.get(4)).to.equal(222);
  123. });
  124. });
  125.  
  126. describe("get method tests", () => {
  127. it("should return the correct element", () => {
  128. list.add(19);
  129. list.add(2);
  130. list.add(3);
  131. list.add(222);
  132. list.add(88);
  133. list.remove(0);
  134. expect(list.get(1)).to.equal(19);
  135. list.add(100);
  136. expect(list.get(1)).to.equal(19);
  137. });
  138. });
  139.  
  140. describe("size property tests", () => {
  141. it("should return the proper size", () => {
  142. list.add(3);
  143. list.add(4);
  144. list.add(29);
  145. list.add(11);
  146. list.add(454);
  147. expect(list.size).to.equal(5);
  148. list.add(3.14);
  149. list.add(222);
  150. expect(list.size).to.equal(7);
  151. });
  152. });
  153. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement