Advertisement
viligen

library

Jun 16th, 2022
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('Tests library', function () {
  2.     describe('calcPriceOfBook ', function () {
  3.         it('assert with valid params', function () {
  4.             assert.equal(
  5.                 library.calcPriceOfBook('Some book', 1980),
  6.                 'Price of Some book is 10.00'
  7.             );
  8.             assert.equal(
  9.                 library.calcPriceOfBook('Some book', 1979),
  10.                 'Price of Some book is 10.00'
  11.             );
  12.             assert.equal(
  13.                 library.calcPriceOfBook('Some book', 1981),
  14.                 'Price of Some book is 20.00'
  15.             );
  16.             assert.equal(
  17.                 library.calcPriceOfBook('Some book', 0),
  18.                 'Price of Some book is 10.00'
  19.             );
  20.         });
  21.  
  22.         it('assert with invalid params, expect to throw', function () {
  23.             assert.Throw(
  24.                 () => library.calcPriceOfBook('Some book'),
  25.                 'Invalid input'
  26.             );
  27.             assert.Throw(
  28.                 () => library.calcPriceOfBook('Some book', '1987'),
  29.                 'Invalid input'
  30.             );
  31.             assert.Throw(
  32.                 () => library.calcPriceOfBook('Some book', [1987]),
  33.                 'Invalid input'
  34.             );
  35.             assert.Throw(
  36.                 () => library.calcPriceOfBook('Some book', 1987.6),
  37.                 'Invalid input'
  38.             );
  39.             assert.Throw(
  40.                 () => library.calcPriceOfBook(['Some book'], 0),
  41.                 'Invalid input'
  42.             );
  43.             assert.Throw(() => library.calcPriceOfBook(0, 0), 'Invalid input');
  44.             assert.Throw(() => library.calcPriceOfBook(1876), 'Invalid input');
  45.         });
  46.     });
  47.  
  48.     describe('findBook', function () {
  49.         it('assert  with valid param', function () {
  50.             assert.equal(
  51.                 library.findBook(
  52.                     ['Troy', 'Life Style', 'Torronto'],
  53.                     'Some book'
  54.                 ),
  55.                 'The book you are looking for is not here!'
  56.             );
  57.             assert.equal(
  58.                 library.findBook(['Troy', 'Life Style', 'Torronto'], 'Troy'),
  59.                 'We found the book you want.'
  60.             );
  61.         });
  62.         it('assert  with valid param, [] - throw', function () {
  63.             assert.Throw(
  64.                 () => library.findBook([], 'Some book'),
  65.                 'No books currently available'
  66.             );
  67.         });
  68.     });
  69.     describe('arrangeTheBooks', function () {
  70.         it('assert with valid params', function () {
  71.             assert.equal(
  72.                 library.arrangeTheBooks(6),
  73.                 'Great job, the books are arranged.'
  74.             );
  75.             assert.equal(
  76.                 library.arrangeTheBooks(40),
  77.                 'Great job, the books are arranged.'
  78.             );
  79.             assert.equal(
  80.                 library.arrangeTheBooks(41),
  81.                 'Insufficient space, more shelves need to be purchased.'
  82.             );
  83.             assert.equal(
  84.                 library.arrangeTheBooks(0),
  85.                 'Great job, the books are arranged.'
  86.             );
  87.         });
  88.         it('assert with invalid params', function () {
  89.             assert.throw(() => library.arrangeTheBooks(-1), 'Invalid input');
  90.  
  91.             assert.throw(() => library.arrangeTheBooks(), 'Invalid input');
  92.             assert.throw(() => library.arrangeTheBooks(8.7), 'Invalid input');
  93.  
  94.             assert.throw(() => library.arrangeTheBooks('8'), 'Invalid input');
  95.         });
  96.     });
  97. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement