Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 11 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,22 @@ Each exercise emphasizes the fundamentals of functional programming in JavaScrip
3. Run `npm install`
4. Test that the unit tests are working by running the command `npm test mythical-creatures/test/dragon-test.js` in your terminal

You should see something like:

```shell
> foundations@1.0.0 test
> mocha mythical-creatures/test/dragon-test.js

Dragon
- should be able to create a dragon with a name
- should be able to have a different name
- should have a rider
- should be able to have a different rider
- should have a temperment
- should be able to have different temperments
- should greet their rider
- should start off having eaten 0 times
- should start off being hungry
- should be full after eating 3 times
- should be a fireBreather if aggressive in temperment

0 passing (6ms)
11 pending
```
5. Make sure you read each subdirectory's README carefully before starting to code!

## Overview

There are lots of test suites in this repo! Our recommendation is to work through this repo as preparation for your final assessment.
There are lots of test suites in this repo! Our recommendation is to work through this repo as preparation for your final assessment.

We find that when students complete the same test suite over and over, memorization and pattern matching kick in (which is not what we want!). These test suites should be improving your problem solving skills. If you feel yourself being able to write code without reading the full test, it’s probably time for a new test suite. You can (and should) be strategic about how you use these - for example, you might use one of the repos for a mock final assessment with your mentor.

Completing all of these test suites is not necessary, but you should be working on this repo regularly. We see that students are the most successful when they establish a routine for working through these test suites. For example, you might work on them for 45 minutes every morning before class. Find a routine that works best for you and plan ahead so you remain on track to complete the majority of the tests.

### Test Suites
- [ ] 🧚 ‍[Mythical Creatures](./mythical-creatures)
- [ ] ✈️ [Airport](./airport)
- [ ] 🎧 [DJ](./dj)
- [ ] 🍔 [Favorite Foods](./favorite-foods)

- [x] 🧚 ‍[Mythical Creatures](./mythical-creatures)
- [x] ✈️ [Airport](./airport)
- [x] 🎧 [DJ](./dj)
- [x] 🍔 [Favorite Foods](./favorite-foods)
- [ ] 🎮 [Video Games](./video-games/)
- [ ] 🎂 [Birthdays](./birthdays)
- [x] 🎂 [Birthdays](./birthdays)
- [ ] 🗓 [Calendar](./calendar/)
- [ ] 💵 [Vending Machine](./vending-machine/)
- [ ] 🛗 [Elevator](./elevator/)
Expand All @@ -62,10 +39,8 @@ Completing all of these test suites is not necessary, but you should be working
- [ ] 📼 [VHS](./vhs/)
- [ ] 🐉 [RPG](./rpg/)

- [x] Want to track your progress? First, make sure you're on a forked version of this repo. Then, you can edit the README and change `[ ]` to `[x]` on the suites you've completed!

## Skipped Tests
## TODO's

Most of the tests are skipped. When you see `it.skip('should be a function', function () {` in a test, it means that test has been skipped. They are skipped for a good reason - that way, when you run the test suite for the first time, you don't see tons of errors screaming at you in the terminal.
_Come back and finish later..._

Unskip each test, one at a time in order, so you can concentrate on making one test pass. Unskip the test by deleting the `.skip` from the test's first line so it should look more like `it('should be a function', function () {`. Run the test to see what kind of error you are getting, and then implement the code to make the test pass!
- [ ] Mythical Creatures -> create custom creature & test suite
118 changes: 90 additions & 28 deletions airport/airport-test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,57 @@
var assert = require('chai').assert;
var { createAirport, welcomeGuests, landPlanes, checkAirlineLocations } = require('./airport');

describe('Airport', function() {
it.skip('should create an airport', function() {
var airport = createAirport('Denver International Airport', ['United', 'Southwest', 'Delta'], 144);
var {
createAirport,
welcomeGuests,
landPlanes,
checkAirlineLocations,
} = require('./airport');

describe('Airport', function () {
it('should create an airport', function () {
var airport = createAirport(
'Denver International Airport',
['United', 'Southwest', 'Delta'],
144
);

assert.equal(airport.name, 'Denver International Airport');
assert.equal(airport.availableGates, 144);
assert.equal(airport.airlines[0], 'United');
});

it.skip('should welcome people to the airport', function() {
var denverAirport = createAirport('Denver International Airport', ['United', 'Southwest', 'Delta'], 144);
var sanDiegoAirport = createAirport('San Diego International Airport', ['Frontier', 'American'], 48);
it('should welcome people to the airport', function () {
var denverAirport = createAirport(
'Denver International Airport',
['United', 'Southwest', 'Delta'],
144
);
var sanDiegoAirport = createAirport(
'San Diego International Airport',
['Frontier', 'American'],
48
);


var denverWelcome = welcomeGuests(denverAirport);
var sanDiegoWelcome = welcomeGuests(sanDiegoAirport);

assert.equal(denverWelcome, 'Welcome to Denver International Airport!');
assert.equal(sanDiegoWelcome, 'Welcome to San Diego International Airport!');
assert.equal(
sanDiegoWelcome,
'Welcome to San Diego International Airport!'
);
});

it.skip('should keep track of open gates', function() {
var bakersfieldAirport = createAirport('Meadows Field Airport', ['United', 'American'], 12);
var sanDiegoAirport = createAirport('San Diego International Airport', ['Frontier', 'American'], 48);
it('should keep track of open gates', function () {
var bakersfieldAirport = createAirport(
'Meadows Field Airport',
['United', 'American'],
12
);
var sanDiegoAirport = createAirport(
'San Diego International Airport',
['Frontier', 'American'],
48
);

var bakersfieldGates = landPlanes(bakersfieldAirport, 11);
var sanDiegoGates = landPlanes(sanDiegoAirport, 2);
Expand All @@ -33,33 +60,68 @@ describe('Airport', function() {
assert.equal(sanDiegoGates.availableGates, 46);
});

it.skip('should not be able to occupy more gates than available', function() {
var columbusAiport = createAirport('John Glenn Airport', ['Southwest', 'Frontier'], 24);
it('should not be able to occupy more gates than available', function () {
var columbusAiport = createAirport(
'John Glenn Airport',
['Southwest', 'Frontier'],
24
);

var updatedAirportGates = landPlanes(columbusAiport, 22);

assert.equal(updatedAirportGates.availableGates, 2);
assert.equal(updatedAirportGates.message, 'Success! Current availability is 2.')
assert.equal(
updatedAirportGates.message,
'Success! Current availability is 2.'
);

var updatedAirportGates2 = landPlanes(updatedAirportGates, 3);

assert.equal(updatedAirportGates2.availableGates, 0);
assert.equal(updatedAirportGates2.message, 'Oh no! Not enough gates available. Current overflow is 1.')
assert.equal(
updatedAirportGates2.message,
'Oh no! Not enough gates available. Current overflow is 1.'
);
});

it.skip('should be able to tell you where an airline flies to', function() {
var columbusAiport = createAirport('John Glenn Airport', ['Southwest', 'Frontier'], 24);
var bakersfieldAirport = createAirport('Meadows Field Airport', ['United', 'American'], 12);
var sanDiegoAirport = createAirport('San Diego International Airport', ['Frontier', 'American'], 48);
var denverAirport = createAirport('Denver International Airport', ['United', 'Southwest', 'Delta'], 144);
var allAirports = [columbusAiport, bakersfieldAirport, sanDiegoAirport, denverAirport];
it('should be able to tell you where an airline flies to', function () {
var columbusAiport = createAirport(
'John Glenn Airport',
['Southwest', 'Frontier'],
24
);
var bakersfieldAirport = createAirport(
'Meadows Field Airport',
['United', 'American'],
12
);
var sanDiegoAirport = createAirport(
'San Diego International Airport',
['Frontier', 'American'],
48
);
var denverAirport = createAirport(
'Denver International Airport',
['United', 'Southwest', 'Delta'],
144
);
var allAirports = [
columbusAiport,
bakersfieldAirport,
sanDiegoAirport,
denverAirport,
];

var southwestCarriers = checkAirlineLocations(allAirports, 'Southwest');
var unitedCarriers = checkAirlineLocations(allAirports, 'United');

assert.deepEqual(southwestCarriers, ['John Glenn Airport', 'Denver International Airport']);
assert.deepEqual(unitedCarriers, ['Meadows Field Airport', 'Denver International Airport']);
assert.deepEqual(southwestCarriers, [
'John Glenn Airport',
'Denver International Airport',
]);
assert.deepEqual(unitedCarriers, [
'Meadows Field Airport',
'Denver International Airport',
]);
});


});
});
36 changes: 31 additions & 5 deletions airport/airport.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
function createAirport(name, airlines, availableGates) {
return { name, airlines, availableGates };
}

function welcomeGuests(airport) {
return `Welcome to ${airport.name}!`;
}

function landPlanes(airport, numberOfPlanes) {
airport.availableGates -= numberOfPlanes;
if (airport.availableGates < 0) {
airport.message = `Oh no! Not enough gates available. Current overflow is ${-airport.availableGates}.`;
airport.availableGates = 0;
} else {
airport.message = `Success! Current availability is ${airport.availableGates}.`;
}
return airport;
}

module.exports = {
// createAirport,
// welcomeGuests,
// landPlanes,
// checkAirlineLocations
function checkAirlineLocations(airports, carrier) {
const locations = [];

for (const airport of airports) {
if (airport.airlines.includes(carrier)) locations.push(airport.name);
}

return locations;
}

module.exports = {
createAirport,
welcomeGuests,
landPlanes,
checkAirlineLocations,
};
8 changes: 4 additions & 4 deletions birthdays/birthdays-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var assert = require('chai').assert;
var { createBirthday, celebrateBirthday, countBirthdays } = require('./birthdays');

describe('Birthdays', function() {
it.skip('should create birthdays', function() {
it('should create birthdays', function() {
var leahBirthday = createBirthday('Leah', 2, 10);
var christyBirthday = createBirthday('Christy', 3, 8);

Expand All @@ -15,7 +15,7 @@ describe('Birthdays', function() {
assert.deepEqual(christyBirthday.day, 8);
});

it.skip('should celebrate birthdays', function() {
it('should celebrate birthdays', function() {
var alexBirthday = createBirthday('Alex', 5, 19);

var celebrateAlex = celebrateBirthday(alexBirthday);
Expand All @@ -29,7 +29,7 @@ describe('Birthdays', function() {
assert.equal(celebrateHeather, 'Today is 6/29! Happy birthday, Heather!');
})

it.skip('should count how many birthdays are in a given month', function() {
it('should count how many birthdays are in a given month', function() {
var leahBirthday = createBirthday('Leah', 2, 10);
var christyBirthday = createBirthday('Christy', 3, 8);
var alexBirthday = createBirthday('Alex', 5, 19);
Expand All @@ -44,4 +44,4 @@ describe('Birthdays', function() {
assert.equal(mayCount, 1);
assert.equal(decCount, 0);
});
});
});
26 changes: 25 additions & 1 deletion birthdays/birthdays.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
function createBirthday(name, month, day) {
return {
name,
month,
day,
};
}

function celebrateBirthday(birthday) {
return `Today is ${birthday.month}/${birthday.day}! Happy birthday, ${birthday.name}!`
}

module.exports = { };
function countBirthdays(birthdays, month) {
var count = 0;

for (let i = 0; i < birthdays.length; i += 1) {
if (birthdays[i].month === month) count += 1;
}

return count;
}

module.exports = {
createBirthday,
celebrateBirthday,
countBirthdays,
};
Loading