Advertisement
Guest User

Sorted List

a guest
Jul 7th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. describe("Tests for sortedList", function () {
  2. let list;
  3. beforeEach(function () {
  4. list = new SortedList();
  5. });
  6.  
  7. describe("General tests", function () {
  8. it("add exist", function () {
  9. expect(SortedList.prototype.hasOwnProperty("add")).to.be.true;
  10. });
  11.  
  12. it("remove exist", function () {
  13. expect(SortedList.prototype.hasOwnProperty("remove")).to.be.true;
  14. });
  15.  
  16. it("get exist", function () {
  17. expect(SortedList.prototype.hasOwnProperty("get")).to.be.true;
  18. });
  19.  
  20. });
  21.  
  22. describe("Add func tests", function () {
  23. it("with one param", function () {
  24. list.add(5);
  25. expect(list.list.join(", ")).to.be.equal("5", "The function don't add correctly!");
  26. });
  27.  
  28. it('with many params', function () {
  29. list.add(25);
  30. list.add(15);
  31. list.add(5);
  32. expect(list.list.join(", ")).to.be.equal("5, 15, 25", "The function don't add correctly!");
  33. });
  34. });
  35.  
  36. describe("Remove func tests", function () {
  37. it("with negative index", function () {
  38. list.add(5);
  39. list.add({});
  40. list.add(3);
  41. list.add(2);
  42. list.add(1);
  43. try {
  44. list.remove(-5)
  45. } catch (error) {
  46. expect(error.name).to.be.equal("Error");
  47. expect(error.message).to.be.equal("Index was outside the bounds of the collection.");
  48. }
  49. });
  50.  
  51. it("with index equal to the array's length", function () {
  52. list.add(5);
  53. list.add({});
  54. list.add(3);
  55. list.add(2);
  56. list.add(1);
  57. try {
  58. list.remove(5)
  59. } catch (error) {
  60. expect(error.name).to.be.equal("Error");
  61. expect(error.message).to.be.equal("Index was outside the bounds of the collection.");
  62. }
  63. });
  64.  
  65. it("with index bigger than the array's length", function () {
  66. list.add(5);
  67. list.add({});
  68. list.add(3);
  69. list.add(2);
  70. list.add(1);
  71. try {
  72. list.remove(6)
  73. } catch (error) {
  74. expect(error.name).to.be.equal("Error");
  75. expect(error.message).to.be.equal("Index was outside the bounds of the collection.");
  76. }
  77. });
  78.  
  79. it("with empty array", function () {
  80. try {
  81. list.remove(50)
  82. } catch (error) {
  83. expect(error.name).to.be.equal("Error");
  84. expect(error.message).to.be.equal("Collection is empty.");
  85. }
  86. });
  87.  
  88. it("with valid index remove ones", function () {
  89. list.add(5);
  90. list.add({});
  91. list.add(3);
  92. list.add(2);
  93. list.add(1);
  94. list.remove(1);
  95. expect(list.list.join(", ")).to.equal("1, 3, 4, 5, {}");
  96. });
  97.  
  98. it('with valid index remove many times', function () {
  99. list.add(5);
  100. list.add({});
  101. list.add(3);
  102. list.add(2);
  103. list.add(1);
  104. list.remove(3);
  105. expect(list.list.join(", ")).to.be.equal("1, 2, 3, 4, {}");
  106. list.remove(2);
  107. expect(list.list.join(", ")).to.be.equal("1, 2, 4, {}");
  108. });
  109. });
  110.  
  111. describe("Get func tests", function () {
  112. it("with negative index", function () {
  113. list.add(5);
  114. list.add({});
  115. list.add(3);
  116. list.add(2);
  117. list.add(1);
  118. try {
  119. list.get(-5)
  120. } catch (error) {
  121. expect(error.name).to.be.equal("Error");
  122. expect(error.message).to.be.equal("Index was outside the bounds of the collection.");
  123. }
  124. });
  125.  
  126. it("with index equal to the array's length", function () {
  127. list.add(5);
  128. list.add({});
  129. list.add(3);
  130. list.add(2);
  131. list.add(1);
  132. try {
  133. list.get(5)
  134. } catch (error) {
  135. expect(error.name).to.be.equal("Error");
  136. expect(error.message).to.be.equal("Index was outside the bounds of the collection.");
  137. }
  138. });
  139.  
  140. it("with index bigger than the array's length", function () {
  141. list.add(5);
  142. list.add({});
  143. list.add(3);
  144. list.add(2);
  145. list.add(1);
  146. try {
  147. list.get(6)
  148. } catch (error) {
  149. expect(error.name).to.be.equal("Error");
  150. expect(error.message).to.be.equal("Index was outside the bounds of the collection.");
  151. }
  152. });
  153.  
  154. it("with empty array", function () {
  155. try {
  156. list.get(50)
  157. } catch (error) {
  158. expect(error.name).to.be.equal("Error");
  159. expect(error.message).to.be.equal("Collection is empty.");
  160. }
  161. });
  162. it('with valid index get ones', function () {
  163. list.add(5);
  164. list.add({});
  165. list.add(3);
  166. list.add(2);
  167. list.add(1);
  168. expect(list.get(4)).to.be.equal({});
  169. });
  170.  
  171. it('with valid index get many', function () {
  172. list.add(5);
  173. list.add({});
  174. list.add(3);
  175. list.add(2);
  176. list.add(1);
  177. expect(list.get(2)).to.be.equal(3);
  178. list.add(22);
  179. list.add(55);
  180. expect(list.get(5)).to.be.equal(55);
  181. });
  182. });
  183. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement