kstoyanov

6.String Builder-unit

Oct 27th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('Test StringBuilder class', () => {
  2.   it('Has initial param', () => {
  3.     expect(StringBuilder.prototype.hasOwnProperty('append')).to.be.equal(true);
  4.     expect(StringBuilder.prototype.hasOwnProperty('prepend')).to.be.equal(true);
  5.     expect(StringBuilder.prototype.hasOwnProperty('insertAt')).to.be.equal(true);
  6.     expect(StringBuilder.prototype.hasOwnProperty('remove')).to.be.equal(true);
  7.     expect(StringBuilder.prototype.hasOwnProperty('toString')).to.be.equal(true);
  8.   });
  9.  
  10.   it('If param is undefined should return obj with empty arr', () => {
  11.     const str = new StringBuilder();
  12.     expect(str._stringArray.length).to.be.equal(0);
  13.   });
  14.  
  15.   it('_stringArray must be array ', () => {
  16.     const str = new StringBuilder();
  17.     expect(Array.isArray(str._stringArray)).to.be.equal(true);
  18.   });
  19.  
  20.   it('Should return not empty arr if passed param is not undefined', () => {
  21.     const str = new StringBuilder('test');
  22.     expect(str._stringArray.length).to.be.equal(4);
  23.   });
  24.  
  25.   it('Should throw error if param is not string type', () => {
  26.     const str = new StringBuilder();
  27.     const willThrow = () => str.append(5);
  28.     expect(willThrow).to.throw();
  29.   });
  30.  
  31.   it('Test append function', () => {
  32.     const str = new StringBuilder('str');
  33.     str.append('newStr');
  34.     expect(str._stringArray.join('')).to.be.equal('strnewStr');
  35.   });
  36.  
  37.   it('Test prepend function', () => {
  38.     const str = new StringBuilder('str');
  39.     str.prepend('newStr');
  40.     expect(str._stringArray.join('')).to.be.equal('newStrstr');
  41.   });
  42.  
  43.   it('Test insertAt function', () => {
  44.     const str = new StringBuilder('s');
  45.     str.insertAt('st', 0);
  46.     expect(str._stringArray.join('')).to.be.equal('sts');
  47.     expect(str._stringArray.length).to.be.equal(3);
  48.   });
  49.  
  50.   it('Test remove function', () => {
  51.     const str = new StringBuilder('str');
  52.     str.remove(0, 2);
  53.     expect(str._stringArray.join('')).to.be.equal('r');
  54.   });
  55.  
  56.   it('Test toString function', () => {
  57.     const str = new StringBuilder('str');
  58.     str.append('newStr');
  59.     str.remove(0, 1);
  60.     str.append('testnewstr');
  61.     expect(str.toString()).to.be.equal('trnewStrtestnewstr');
  62.   });
  63. });
Advertisement
Add Comment
Please, Sign In to add comment