Advertisement
nikolayneykov92

Untitled

Jun 25th, 2019
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('StringBuilder', () => {
  2.   let sb = null
  3.   beforeEach(() => {
  4.     sb = new StringBuilder('test')
  5.   })
  6.  
  7.   describe('methods', () => {
  8.     it('should have methods to manipulate the string', () => {
  9.       let methods = ['append', 'prepend', 'insertAt', 'remove', 'toString']
  10.       methods.every(m => assert.isFunction(StringBuilder.prototype[m]))
  11.     })
  12.   })
  13.  
  14.   describe('instantiating', () => {
  15.     it('should be instantiated without argument', () => {
  16.       sb = new StringBuilder()
  17.       assert.isObject(sb)
  18.     })
  19.  
  20.     it('should be instantiated with argument', () => {
  21.       assert.isObject(sb)
  22.     })
  23.   })
  24.  
  25.   describe('append', () => {
  26.     it('should add the argument to the end of the storage', () => {
  27.       sb.append(' appended')
  28.       assert.equal(sb.toString(), 'test appended')
  29.     })
  30.   })
  31.  
  32.   describe('prepend', () => {
  33.     it('should add the argument at the begining of the storage', () => {
  34.       sb.prepend('prepended ')
  35.       assert.equal(sb.toString(), 'prepended test')
  36.     })
  37.   })
  38.  
  39.   describe('insertAt', () => {
  40.     it('should insert argument at given index', () => {
  41.       sb.insertAt(' inserted ', 2)
  42.       assert.equal(sb.toString(), 'te inserted st')
  43.     })
  44.  
  45.     it('insert new test', () => {
  46.       sb = new StringBuilder('test')
  47.       sb.insertAt('str', 0)
  48.       let source = sb._stringArray
  49.       let expected = Array.from('test')
  50.       expected.splice(0, 0, ...'str')
  51.  
  52.       // expect(source.length).to.equal(expected.length, "Arrays don't match")
  53.       for (let i = 0; i < source.length; i++) {
  54.         expect(source[i]).to.equal(expected[i], 'Element ' + i + ' mismatch')
  55.       }
  56.     })
  57.   })
  58.  
  59.   describe('remove', () => {
  60.     it('should remove number of characters starting from a given index', () => {
  61.       sb.remove(1, 2)
  62.       assert.equal(sb.toString(), 'tt')
  63.     })
  64.   })
  65.  
  66.   describe('toString', () => {
  67.     it('should return string', () => {
  68.       assert.isString(sb.toString())
  69.     })
  70.  
  71.     it('should throw error for nonstring argument', () => {
  72.       assert.throws(() => sb.append(false))
  73.     })
  74.   })
  75. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement