Advertisement
kstoyanov

02. Ski Resort-26 October 2019 exam

Oct 22nd, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('SkiResort functionality', () => {
  2.   let expectedResult;
  3.   let actualResult;
  4.   let resort;
  5.   let willThrow;
  6.  
  7.   beforeEach(() => {
  8.     resort = new SkiResort('NewHope');
  9.     expectedResult = '';
  10.     actualResult = '';
  11.     willThrow;
  12.   });
  13.  
  14.   describe('constructor functionality', () => {
  15.     it('creates a new class object with given name', () => {
  16.       const newResort = new SkiResort('Funn');
  17.  
  18.       assert.equal(newResort.name, 'Funn');
  19.       assert.equal(newResort.voters, 0);
  20.       assert.deepEqual(newResort.hotels, []);
  21.     });
  22.   });
  23.  
  24.   describe('bestHotel getter functionality', () => {
  25.     it('return "No votes yet" message if voters counter is 0', () => {
  26.       expectedResult = 'No votes yet';
  27.       actualResult = resort.bestHotel;
  28.  
  29.       assert.equal(expectedResult, actualResult);
  30.     });
  31.  
  32.     it('returns best hotel in resort', () => {
  33.       resort.build('Rila', 100);
  34.       resort.build('Pogled', 80);
  35.  
  36.       resort.leave('Rila', 2, 5);
  37.       resort.leave('Pogled', 2, 50);
  38.  
  39.       expectedResult = 'Best hotel is Pogled with grade 100. Available beds: 82';
  40.       actualResult = resort.bestHotel;
  41.  
  42.       assert.equal(expectedResult, actualResult);
  43.     });
  44.   });
  45.  
  46.   describe('build method functionality', () => {
  47.     it('trows an error, if invalid name is passed in', () => {
  48.       willThrow = () => resort.build('', 3);
  49.       assert.throws(willThrow, 'Invalid input');
  50.     });
  51.  
  52.     it('trows an error, if invalid number of beds is passed in', () => {
  53.       willThrow = () => resort.build('Rila', 0);
  54.       assert.throws(willThrow, 'Invalid input');
  55.     });
  56.  
  57.     it('return propper message', () => {
  58.       actualResult = resort.build('Rila', 100);
  59.       expectedResult = 'Successfully built new hotel - Rila';
  60.  
  61.       assert.equal(expectedResult, actualResult);
  62.     });
  63.  
  64.     it('adds a new bulded hotel to hotels list', () => {
  65.       resort.build('Rila', 100);
  66.       expectedResult = 1;
  67.       actualResult = resort.hotels.length;
  68.  
  69.       assert.equal(expectedResult, actualResult);
  70.     });
  71.   });
  72.  
  73.   describe('book method functionality', () => {
  74.     it('throws a new error, if invalid hotel name is passed in', () => {
  75.       willThrow = () => resort.book('', 4);
  76.       assert.throws(willThrow, 'Invalid input');
  77.     });
  78.  
  79.     it('trows a new error, if invalid number of beds is passed in', () => {
  80.       willThrow = () => resort.book('Rila', 0);
  81.       assert.throws(willThrow, 'Invalid input');
  82.     });
  83.  
  84.     it('throws a new errror, if there is no such a hotel', () => {
  85.       resort.build('Rila', 100);
  86.       willThrow = () => resort.book('Plam', 3);
  87.       assert.throws(willThrow, 'There is no such hotel');
  88.     });
  89.  
  90.     it('throws a new error, if there are not free beds', () => {
  91.       resort.build('Hija', 4);
  92.       willThrow = () => resort.book('Hija', 5);
  93.       assert.throws(willThrow, 'There is no free space');
  94.     });
  95.  
  96.     it('returns a properly message', () => {
  97.       resort.build('Rila', 100);
  98.       expectedResult = 'Successfully booked';
  99.       actualResult = resort.book('Rila', 8);
  100.  
  101.       assert.equal(expectedResult, actualResult);
  102.     });
  103.  
  104.     it('decrease the number of free beds', () => {
  105.       resort.build('Rila', 100);
  106.       resort.book('Rila', 10);
  107.  
  108.       const hotel = resort.hotels.find((hotel) => hotel.name === 'Rila');
  109.  
  110.       expectedResult = 90;
  111.       actualResult = hotel.beds;
  112.  
  113.       assert.equal(expectedResult, actualResult);
  114.     });
  115.   });
  116.  
  117.   describe('leave method functionality', () => {
  118.     it('throws a new error, if invalid name is passed in', () => {
  119.       willThrow = () => resort.leave('', 4, 10);
  120.       assert.throws(willThrow, 'Invalid input');
  121.     });
  122.  
  123.     it('throws a new error, if invalid number of beds is passed in', () => {
  124.       resort.build('Rila', 100);
  125.       willThrow = () => resort.leave('Rila', 0, 10);
  126.       assert.throws(willThrow, 'Invalid input');
  127.     });
  128.  
  129.     it('throws a new error, if there is no such a hotel in hotels list', () => {
  130.       resort.build('Rila', 100);
  131.       willThrow = () => resort.leave('Ra', 4, 10);
  132.       assert.throws(willThrow, 'There is no such hotel');
  133.     });
  134.  
  135.     it('return proper message if all arguments are correct', () => {
  136.       resort.build('Rila', 100);
  137.       resort.book('Rila', 4);
  138.       actualResult = resort.leave('Rila', 4, 10);
  139.       expectedResult = '4 people left Rila hotel';
  140.  
  141.       assert.equal(expectedResult, actualResult);
  142.     });
  143.  
  144.     it('increase number of beds', () => {
  145.       resort.build('Rila', 100);
  146.       resort.book('Rila', 4);
  147.       resort.book('Rila', 4);
  148.       resort.leave('Rila', 4, 10);
  149.  
  150.       const hotel = resort.hotels.find((hotel) => hotel.name === 'Rila');
  151.       actualResult = hotel.beds;
  152.       expectedResult = 96;
  153.  
  154.       assert.equal(expectedResult, actualResult);
  155.     });
  156.   });
  157.  
  158.   describe('averageGrade method functionality', () => {
  159.     it('returns proper message, if no voters registred', () => {
  160.       expectedResult = 'No votes yet';
  161.       actualResult = resort.averageGrade();
  162.  
  163.       assert.equal(expectedResult, actualResult);
  164.     });
  165.  
  166.     it('returns average resort grade', () => {
  167.       resort.build('Rila', 100);
  168.       resort.build('Ela', 80);
  169.       resort.build('Bor', 120);
  170.  
  171.       resort.leave('Rila', 2, 10);
  172.       const rilaPoints = 2 * 10;
  173.  
  174.       resort.leave('Ela', 4, 2);
  175.       const elaPoints = 4 * 2;
  176.  
  177.       resort.leave('Bor', 6, 1);
  178.       const borPoints = 6 * 1;
  179.  
  180.       const avrgGrade = (rilaPoints + elaPoints + borPoints) / 12;
  181.  
  182.       expectedResult = `Average grade: ${avrgGrade.toFixed(2)}`;
  183.       actualResult = resort.averageGrade();
  184.  
  185.       assert.equal(expectedResult, actualResult);
  186.     });
  187.   });
  188. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement