Guest User

Untitled

a guest
Nov 6th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. describe("Tests for this task", function () {
  2.  
  3. let myList;
  4. beforeEach(function () {
  5. myList = new SortedList();
  6. });
  7. //Test initial state:
  8. describe("Test initial state", function () {
  9. it("add should exist", function () {
  10. expect(SortedList.prototype.hasOwnProperty("add")).to.equal(true);
  11. });
  12. it("remove should exist", function () {
  13. expect(SortedList.prototype.hasOwnProperty("remove")).to.equal(true);
  14. });
  15. it("get should exist", function () {
  16. expect(SortedList.prototype.hasOwnProperty("get")).to.equal(true);
  17. });
  18. it("size should exist", function () {
  19. expect(SortedList.prototype.hasOwnProperty("size")).to.equal(true);
  20. })
  21. });
  22.  
  23. //add():
  24. describe("Test add", function () {
  25. it("add with 1 element", function () {
  26. myList.add(5);
  27. expect(myList.list.join(", ")).to.equal("5");
  28. });
  29. it("add with many elements", function () {
  30. myList.add(5);
  31. myList.add(4);
  32. myList.add(3);
  33. expect(myList.list.join(", ")).to.equal("3, 4, 5");
  34. });
  35. });
  36.  
  37. //remove():
  38. describe("Test remove", function () {
  39. it("remove with empty list", function () {
  40. expect(() => myList.remove()).throw(Error, "Collection is empty.")
  41. });
  42. it("remove with negative index", function () {
  43. myList.add(3);
  44. expect(() => myList.remove(-1)).throw(Error, "Index was outside the bounds of the collection.")
  45. });
  46. it("remove - index is equal to list length", function () {
  47. myList.add(3);
  48. expect(() => myList.remove(1)).throw(Error, "Index was outside the bounds of the collection.")
  49. });
  50. it("remove - index is bigger than list length", function () {
  51. myList.add(3);
  52. expect(() => myList.remove(2)).throw(Error, "Index was outside the bounds of the collection.")
  53. });
  54. it("remove - test with correct index", function () {
  55. myList.add(3);
  56. myList.add(4);
  57. myList.add(5);
  58. myList.remove(1);
  59. expect(myList.list.join(", ")).to.equal("3, 5");
  60. });
  61. });
  62.  
  63. //get():
  64. describe("Test get", function () {
  65. it("get with empty list", function () {
  66. expect(() => myList.get()).throw(Error, "Collection is empty.")
  67. });
  68. it("get with negative index", function () {
  69. myList.add(3);
  70. expect(() => myList.get(-1)).throw(Error, "Index was outside the bounds of the collection.")
  71. });
  72. it("get - index is equal to list length", function () {
  73. myList.add(3);
  74. expect(() => myList.get(1)).throw(Error, "Index was outside the bounds of the collection.")
  75. });
  76. it("get - index is bigger than list length", function () {
  77. myList.add(3);
  78. expect(() => myList.get(2)).throw(Error, "Index was outside the bounds of the collection.")
  79. });
  80. it("get - test with correct index", function () {
  81. myList.add(3);
  82. myList.add(4);
  83. myList.add(5);
  84. let element = myList.get(1);
  85. expect(element).to.equal(4);
  86. });
  87. });
  88.  
  89. //size():
  90. describe("Test size", function () {
  91. it("size with empty list", function () {
  92. expect(myList.size).to.equal(0);
  93. });
  94. it("size with non-empty list", function () {
  95. myList.add(1);
  96. myList.add(2);
  97. myList.add(3);
  98. expect(myList.size).to.equal(3);
  99. });
  100. });
  101. });
Advertisement
Add Comment
Please, Sign In to add comment