diela33

03. Library

Dec 7th, 2021
672
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe("Test list", () => {
  2.     describe("Test 1 ", () => {
  3.         it("calcPriceOfBook ", () => {
  4.             assert.throw(() => library.calcPriceOfBook(1, 'abv'), 'Invalid input');
  5.             assert.throw(() => library.calcPriceOfBook([], []), 'Invalid input');
  6.             assert.throw(() => library.calcPriceOfBook(1.1, 1.1), 'Invalid input');
  7.             assert.throw(() => library.calcPriceOfBook(' ', -1.1), 'Invalid input');
  8.             assert.throw(() => library.calcPriceOfBook({}, {}), 'Invalid input');
  9.             assert.throw(() => library.calcPriceOfBook(NaN, {}), 'Invalid input');
  10.             assert.throw(() => library.calcPriceOfBook(NaN, NaN), 'Invalid input');
  11.             assert.throw(() => library.calcPriceOfBook(1, 0), 'Invalid input');
  12.             assert.throw(() => library.calcPriceOfBook(undefined, NaN), 'Invalid input');
  13.             assert.throw(() => library.calcPriceOfBook([], {}), 'Invalid input');
  14.         });
  15.         it("calcPrice", () => {
  16.             let price = 20;
  17.             let total = 10;
  18.             let nameOfBook = "Book";
  19.             // assert.equal(library.calcPriceOfBook(nameOfBook, price), `Price of ${nameOfBook} is ${price.toFixed(2)}`);
  20.             assert.equal(library.calcPriceOfBook(nameOfBook, 1981), `Price of ${nameOfBook} is ${price.toFixed(2)}`);
  21.             assert.equal(library.calcPriceOfBook(nameOfBook, 1979), `Price of ${nameOfBook} is ${total.toFixed(2)}`);
  22.             assert.equal(library.calcPriceOfBook(nameOfBook, 1980), `Price of ${nameOfBook} is ${total.toFixed(2)}`);
  23.             assert.equal(library.calcPriceOfBook(nameOfBook, 0), `Price of ${nameOfBook} is ${total.toFixed(2)}`);
  24.             assert.equal(library.calcPriceOfBook(nameOfBook, -1980), `Price of ${nameOfBook} is ${total.toFixed(2)}`);
  25.         });
  26.  
  27.         it('test findBook', () => {
  28.             assert.throw(() => library.findBook(([])), "No books currently available");
  29.            
  30.         });
  31.         it("test findBook 1 ", () => {
  32.             booksArr = ["Troy", "Life Style", "Torronto"];
  33.  
  34.             desiredBook = "Troy";
  35.             desiredBook1 = " "
  36.  
  37.             assert.equal(library.findBook(booksArr, desiredBook), "We found the book you want.")
  38.             assert.equal(library.findBook(booksArr, desiredBook1), "The book you are looking for is not here!")
  39.          
  40.         });
  41.  
  42.         it("arrangeTheBooks", () => {
  43.             assert.throw(() => library.arrangeTheBooks(1.1, -5), "Invalid input");
  44.             assert.throw(() => library.arrangeTheBooks([], -5), "Invalid input");
  45.             assert.throw(() => library.arrangeTheBooks(NaN, -5), "Invalid input");
  46.             assert.throw(() => library.arrangeTheBooks(NaN, NaN), "Invalid input");
  47.             assert.throw(() => library.arrangeTheBooks(1.1, 5), "Invalid input");
  48.             assert.throw(() => library.arrangeTheBooks(1.1, undefined), "Invalid input");
  49.             assert.throw(() => library.arrangeTheBooks(1.1, 0.2), "Invalid input");
  50.             assert.throw(() => library.arrangeTheBooks('1.1', -5), "Invalid input");
  51.             assert.throw(() => library.arrangeTheBooks([], []), "Invalid input");
  52.             assert.throw(() => library.arrangeTheBooks({}, {}), "Invalid input");
  53.             assert.throw(() => library.arrangeTheBooks([], {}), "Invalid input");
  54.  
  55.         });
  56.  
  57.         it("arrangeTheBooks", () => {
  58.             const countShelves = 5;
  59.             const availableSpace = countShelves * 8;
  60.             let countShelves1 = 5.5
  61.             let availableSpace1 = countShelves1 * 8;
  62.             let countShelves2 = 0
  63.             let availableSpace2 = countShelves2 * 8;
  64.  
  65.  
  66.             let countShelves4 = 1
  67.             let availableSpace4 = countShelves4 * 8;
  68.  
  69.             assert.equal(library.arrangeTheBooks(availableSpace, countShelves), "Great job, the books are arranged.");
  70.             assert.equal(library.arrangeTheBooks(availableSpace1, countShelves1), "Insufficient space, more shelves need to be purchased.");
  71.             assert.equal(library.arrangeTheBooks(availableSpace2, countShelves2), "Great job, the books are arranged.");
  72.  
  73.             assert.equal(library.arrangeTheBooks(availableSpace4, countShelves4), "Great job, the books are arranged.");
  74.         })
  75.  
  76.  
  77.  
  78.     });
  79.  
  80. });
  81.  
RAW Paste Data