kema

02. Sorted List

Nov 2nd, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe("SortedList",function () {
  2.     let myList ={};
  3.     beforeEach(function () {
  4.         myLst = new SortedList();
  5.     });
  6.     it('should have a constructor', function () {
  7.             expect(typeof SortedList).to.equal('function');
  8.  
  9.         expect(SortedList.prototype.hasOwnProperty('add')).to.equal(true, "Didn't find add function");
  10.         expect(SortedList.prototype.hasOwnProperty('remove')).to.equal(true, "Didn't find remove function");
  11.         expect(SortedList.prototype.hasOwnProperty('get')).to.equal(true, "Didn't find get function");
  12.         expect(SortedList.prototype.hasOwnProperty('size')).to.equal(true, "Didn't find size function");
  13.         });
  14.     it('should have size property',function () {
  15.         expect(myList.size).to.equal(0);
  16.     });
  17.     it('should have working add',function () {
  18.         myList.add(5);
  19.         expect(myList.size).to.equal(1);
  20.     });
  21.     it('should have working add and get',function () {
  22.         myList.add(4);
  23.         expect(myList.get(0)).to.equal(4);
  24.     });
  25.     it('should be sorted',function () {
  26.         myList.add(4);
  27.         myList.add(3);
  28.         myList.add(10);
  29.         myList.add(1);
  30.         expect(myList.get(0)).to.equal(1);
  31.         expect(myList.get(1)).to.equal(3);
  32.         expect(myList.get(2)).to.equal(4);
  33.         expect(myList.get(3)).to.equal(10);
  34.         expect(myList.size).to.equal(4);
  35.  
  36.     });
  37.     it('should have working remove and get',function () {
  38.         myList.add(4);
  39.         myList.add(3);
  40.         myList.add(10);
  41.         myList.add(1);
  42.         myList.remove(1)
  43.         expect(myList.get(0)).to.equal(1);
  44.         expect(myList.get(1)).to.equal(4);
  45.         expect(myList.get(2)).to.equal(10);
  46.         expect(myList.size).to.equal(3);
  47.  
  48.     });
  49.     it('should not work with negative index',function () {
  50.         myList.add(4);
  51.         myList.add(3);
  52.         myList.add(10);
  53.         myList.add(1);
  54.         myList.remove(1)
  55.         expect(() => myList.get(-1)).to.throw(Error);
  56.         expect(() => myList.remove(-1)).to.throw(Error);
  57.  
  58.     });
  59.     it('should not work with outside index',function () {
  60.         myList.add(4);
  61.         myList.add(3);
  62.         myList.add(10);
  63.         myList.add(1);
  64.         myList.remove(1)
  65.         expect(() => myList.get(4)).to.throw(Error);
  66.         expect(() => myList.remove(4)).to.throw(Error);
  67.  
  68.     });
  69.     it('should not work with empty collection',function(){
  70.         expect(() => myList.get(0)).to.throw(Error);
  71.         expect(() => myList.remove(0)).to.throw(Error);
  72.  
  73.     });
  74. });
Advertisement
Add Comment
Please, Sign In to add comment