Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {
- expect
- } = require("chai");
- const cinema = {
- showMovies: function (movieArr) {
- if (movieArr.length == 0) {
- return 'There are currently no movies to show.';
- } else {
- let result = movieArr.join(', ');
- return result;
- }
- },
- ticketPrice: function (projectionType) {
- const schedule = {
- "Premiere": 12.00,
- "Normal": 7.50,
- "Discount": 5.50
- }
- if (schedule.hasOwnProperty(projectionType)) {
- let price = schedule[projectionType];
- return price;
- } else {
- throw new Error('Invalid projection type.')
- }
- },
- swapSeatsInHall: function (firstPlace, secondPlace) {
- if (!Number.isInteger(firstPlace) || firstPlace <= 0 || firstPlace > 20 || !Number.isInteger(secondPlace) || secondPlace <= 0 || secondPlace > 20 || firstPlace === secondPlace) {
- return "Unsuccessful change of seats in the hall.";
- } else {
- return "Successful change of seats in the hall.";
- }
- }
- };
- describe('Cinema', () => {
- describe('Show movies', () => {
- it('Should fail if the given input array is empty', () => {
- expect(cinema.showMovies([])).to.be.equal('There are currently no movies to show.');
- });
- it('Should return joined array if the array is correct', () => {
- expect(cinema.showMovies(['BBB','CCC'])).to.be.equal('BBB, CCC');
- });
- });
- describe('ticketPrice', () => {
- it('Should pass if the projection type is available', () => {
- expect(cinema.ticketPrice('Premiere')).to.be.equal(12.00);
- expect(cinema.ticketPrice('Normal')).to.be.equal(7.50);
- expect(cinema.ticketPrice('Discount')).to.be.equal(5.50);
- });
- it('Should throw if the projection type is not correct', () => {
- expect(() => cinema.ticketPrice('Casual')).to.throw(Error, 'Invalid projection type.');
- });
- });
- describe('swapSeatsInHall', () => {
- it('Should fail if the input numbers are not integers', () => {
- expect(cinema.swapSeatsInHall(2.2, 3)).to.be.equal('Unsuccessful change of seats in the hall.');
- expect(cinema.swapSeatsInHall(2.2, 3.2)).to.be.equal('Unsuccessful change of seats in the hall.');
- });
- it('Should fail if one of the input numbers is greater than 20', () => {
- expect(cinema.swapSeatsInHall(25, 2)).to.be.equal('Unsuccessful change of seats in the hall.');
- expect(cinema.swapSeatsInHall(2, 30)).to.be.equal('Unsuccessful change of seats in the hall.');
- });
- it('Should fail if one of the input numbers is less or equal to 0', () => {
- expect(cinema.swapSeatsInHall(0, 2)).to.be.equal('Unsuccessful change of seats in the hall.');
- expect(cinema.swapSeatsInHall(2, -2)).to.be.equal('Unsuccessful change of seats in the hall.');
- });
- it('Should fail if one of the input numbers do not exist', () => {
- expect(cinema.swapSeatsInHall(2)).to.be.equal('Unsuccessful change of seats in the hall.');
- });
- it('Should fail if the input numbers are equal', () => {
- expect(cinema.swapSeatsInHall(2, 2)).to.be.equal('Unsuccessful change of seats in the hall.');
- });
- it('Should pass if the input numbers are correct', () => {
- expect(cinema.swapSeatsInHall(2, 3)).to.be.equal('Successful change of seats in the hall.');
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement