Advertisement
braveheart1989

02. Add/Delete in List

Nov 8th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('', function () {
  2.     let list = {};
  3.     beforeEach('', function () {
  4.         list = a();
  5.     });
  6.  
  7.     describe('testing add function', function () {
  8.         it('should return empty string', function () {
  9.             expect(list.toString()).to.be.equal('');
  10.         });
  11.         it('should add only 312', function () {
  12.             list.add(312);
  13.             expect(list.toString()).to.be.equal("312");
  14.         });
  15.         it('should add only 22.3', function () {
  16.             list.add(22.3);
  17.             expect(list.toString()).to.be.equal("22.3");
  18.         });
  19.         it('should add 5 pesho and Stamat to array', function () {
  20.             list.add(5);
  21.             list.add('pesho');
  22.             list.add('Stamat');
  23.             expect(list.toString()).to.be.equal("5, pesho, Stamat");
  24.         });
  25.         it('should add "-1" to array', function () {
  26.             list.add("-1");
  27.             list.add({name:"Pesho"});
  28.             expect(list.toString()).to.be.equal('-1, [object Object]');
  29.         });
  30.         it('should add "[2]" to array', function () {
  31.             list.add("[2]");
  32.             expect(list.toString()).to.be.equal('[2]');
  33.         });
  34.     });
  35.  
  36.     describe('testing delete function', function () {
  37.         it('should delete at position 1', function () {
  38.             list.add("Pesho");
  39.             list.add("1");
  40.             list.add("3");
  41.             expect(list.toString()).to.be.equal('Pesho, 1, 3');
  42.             expect(list.delete(1)).to.be.equal("1");
  43.             expect(list.toString()).to.be.equal('Pesho, 3')
  44.         });
  45.  
  46.         it('should return correct result with valid input',function () {
  47.             list.add(4);
  48.             list.add(8);
  49.             list.add("Ivan");
  50.             list.add("Pesho");
  51.             expect(list.toString()).to.be.equal('4, 8, Ivan, Pesho');
  52.             expect(list.delete(2)).to.be.equal('Ivan');
  53.             expect(list.toString()).to.be.equal('4, 8, Pesho');
  54.         });
  55.  
  56.         it('should return correct result with valid input',function () {
  57.             list.add(4);
  58.             list.add(8);
  59.             list.add("Ivan");
  60.             list.add("Pesho");
  61.             expect(list.toString()).to.be.equal('4, 8, Ivan, Pesho');
  62.             expect(list.delete(2)).to.be.equal('Ivan');
  63.             expect(list.toString()).to.be.equal('4, 8, Pesho');
  64.         });
  65.  
  66.         it('should return undefined for non integer index',function () {
  67.             list.add(5);
  68.             list.add(133);
  69.             list.add(-12);
  70.             list.add("Stamat");
  71.             list.add(5);
  72.             expect(list.toString()).to.be.equal('5, 133, -12, Stamat, 5');
  73.             expect(list.delete("Pesho")).to.be.equal(undefined);
  74.         });
  75.         it('should return undefined for negative index',function () {
  76.             list.add(5);
  77.             list.add(133);
  78.             expect(list.delete(1)).to.be.equal(133);
  79.             list.add(-12);
  80.             list.add("Stamat");
  81.             list.add(5);
  82.             expect(list.toString()).to.be.equal('5, -12, Stamat, 5');
  83.             expect(list.delete(-1)).to.be.equal(undefined);
  84.         });
  85.  
  86.         it('should return undefined for index == arr.length',function () {
  87.             list.add(5);
  88.             list.add(133);
  89.             expect(list.delete(1)).to.be.equal(133);
  90.             list.add(-12);
  91.             list.add("Stamat");
  92.             list.add(5);
  93.             expect(list.toString()).to.be.equal('5, -12, Stamat, 5');
  94.             expect(list.delete(4)).to.be.equal(undefined);
  95.         });
  96.  
  97.         it('should return undefined for index > arr.length',function () {
  98.             list.add(5);
  99.             list.add(133);
  100.             expect(list.delete(1)).to.be.equal(133);
  101.             list.add(-12);
  102.             list.add("Stamat");
  103.             list.add(5);
  104.             expect(list.toString()).to.be.equal('5, -12, Stamat, 5');
  105.             expect(list.delete(23)).to.be.equal(undefined);
  106.         });
  107.  
  108.         it('should return undefined for floating point index',function () {
  109.             list.add(5);
  110.             list.add(12.5);
  111.             expect(list.delete(0)).to.be.equal(5,'didnt delete correct item');
  112.             list.add(-12);
  113.             list.add("Stamat");
  114.             list.add(5);
  115.             expect(list.toString()).to.be.equal('12.5, -12, Stamat, 5');
  116.             expect(list.delete(1.2)).to.be.equal(undefined);
  117.         });
  118.     });
  119. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement