Advertisement
megi_al

Untitled

Aug 12th, 2021
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. const {
  2. expect
  3. } = require("chai");
  4.  
  5. const cinema = {
  6. showMovies: function (movieArr) {
  7.  
  8. if (movieArr.length == 0) {
  9. return 'There are currently no movies to show.';
  10. } else {
  11. let result = movieArr.join(', ');
  12. return result;
  13. }
  14.  
  15. },
  16. ticketPrice: function (projectionType) {
  17.  
  18. const schedule = {
  19. "Premiere": 12.00,
  20. "Normal": 7.50,
  21. "Discount": 5.50
  22. }
  23. if (schedule.hasOwnProperty(projectionType)) {
  24. let price = schedule[projectionType];
  25. return price;
  26. } else {
  27. throw new Error('Invalid projection type.')
  28. }
  29.  
  30. },
  31. swapSeatsInHall: function (firstPlace, secondPlace) {
  32. if (!Number.isInteger(firstPlace) || firstPlace <= 0 || firstPlace > 20 || !Number.isInteger(secondPlace) || secondPlace <= 0 || secondPlace > 20 || firstPlace === secondPlace) {
  33. return "Unsuccessful change of seats in the hall.";
  34. } else {
  35. return "Successful change of seats in the hall.";
  36. }
  37.  
  38. }
  39. };
  40.  
  41. describe('Cinema', () => {
  42. describe('Show movies', () => {
  43. it('Should fail if the given input array is empty', () => {
  44. expect(cinema.showMovies([])).to.be.equal('There are currently no movies to show.');
  45. });
  46.  
  47. it('Should return joined array if the array is correct', () => {
  48. expect(cinema.showMovies(['BBB','CCC'])).to.be.equal('BBB, CCC');
  49. });
  50. });
  51.  
  52. describe('ticketPrice', () => {
  53. it('Should pass if the projection type is available', () => {
  54. expect(cinema.ticketPrice('Premiere')).to.be.equal(12.00);
  55. expect(cinema.ticketPrice('Normal')).to.be.equal(7.50);
  56. expect(cinema.ticketPrice('Discount')).to.be.equal(5.50);
  57.  
  58.  
  59. });
  60. it('Should throw if the projection type is not correct', () => {
  61. expect(() => cinema.ticketPrice('Casual')).to.throw(Error, 'Invalid projection type.');
  62. });
  63. });
  64.  
  65. describe('swapSeatsInHall', () => {
  66. it('Should fail if the input numbers are not integers', () => {
  67. expect(cinema.swapSeatsInHall(2.2, 3)).to.be.equal('Unsuccessful change of seats in the hall.');
  68. expect(cinema.swapSeatsInHall(2.2, 3.2)).to.be.equal('Unsuccessful change of seats in the hall.');
  69. });
  70. it('Should fail if one of the input numbers is greater than 20', () => {
  71. expect(cinema.swapSeatsInHall(25, 2)).to.be.equal('Unsuccessful change of seats in the hall.');
  72. expect(cinema.swapSeatsInHall(2, 30)).to.be.equal('Unsuccessful change of seats in the hall.');
  73. });
  74. it('Should fail if one of the input numbers is less or equal to 0', () => {
  75. expect(cinema.swapSeatsInHall(0, 2)).to.be.equal('Unsuccessful change of seats in the hall.');
  76. expect(cinema.swapSeatsInHall(2, -2)).to.be.equal('Unsuccessful change of seats in the hall.');
  77. });
  78. it('Should fail if one of the input numbers do not exist', () => {
  79. expect(cinema.swapSeatsInHall(2)).to.be.equal('Unsuccessful change of seats in the hall.');
  80. });
  81. it('Should fail if the input numbers are equal', () => {
  82. expect(cinema.swapSeatsInHall(2, 2)).to.be.equal('Unsuccessful change of seats in the hall.');
  83. });
  84. it('Should pass if the input numbers are correct', () => {
  85. expect(cinema.swapSeatsInHall(2, 3)).to.be.equal('Successful change of seats in the hall.');
  86. });
  87. });
  88. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement