-
Notifications
You must be signed in to change notification settings - Fork 886
Feature/unicorn fix #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f42d274
b1988a4
d12a7b9
6f9922f
2781f9d
0e5eedf
dd9fd41
f4f9e72
e965130
e54e81c
a578a86
4d73e37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Marathon Tests | ||
| Original author: [Jeremiah Black](https://github.com/jeremiahblackol) | ||
| This test suite is for practice. Do not worry about time. | ||
|
|
||
| ## Installation Steps | ||
|
|
||
| In order to be able to run these tests you need to install the dependencies at the root level of this repository. Find the directions at the [root-level of this repository](https://github.com/turingschool-examples/javascript-foundations). | ||
|
|
||
| ### Running the Tests | ||
|
|
||
| You can run the tests from the root of this repository. When you type `pwd` in the console, the last path location should be `javascript-foundations`. | ||
|
|
||
| Run the command `npm test marathon/test/runner-test.js`. To run other tests, just replace the test file name. | ||
|
|
||
| ### Make the tests pass in the following sequence: | ||
|
|
||
| * test/runner-test.js | ||
| * test/road-test.js |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| function buildRunner(name, age) { | ||
| return { | ||
| name: name, | ||
| age: age | ||
| }; | ||
| }; | ||
|
|
||
| function runSomeMiles(runner, miles) { | ||
| if (runner.milesRun) { | ||
| runner.milesRun += miles | ||
| } else { | ||
| runner.milesRun = miles | ||
| } | ||
| return runner | ||
| }; | ||
|
|
||
| function registerForRace(runner) { | ||
| if (runner.milesRun > 26.1) { | ||
| return `Congrats ${runner.name}, you are now registered for the marathon!` | ||
| } else { | ||
| return `Sorry ${runner.name}, you need more training to register for the marathon!` | ||
| } | ||
| }; | ||
|
|
||
| module.exports = { | ||
| buildRunner, | ||
| runSomeMiles, | ||
| registerForRace | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| var { buildRunner, runSomeMiles, registerForRace } = require("../src/runner.js"); | ||
| var assert = require('chai').assert; | ||
|
|
||
| describe("Runner", function() { | ||
|
|
||
| it('should have a name and age', function() { | ||
| var dennis = buildRunner('Dennis', 42); | ||
| var mary = buildRunner('Mary', 27); | ||
|
|
||
| assert.equal(dennis.name, 'Dennis'); | ||
| assert.equal(dennis.age, 42); | ||
|
|
||
| assert.equal(mary.name, 'Mary'); | ||
| assert.equal(mary.age, 27); | ||
| }); | ||
|
|
||
| it('should be able to keep track of miles run', function() { | ||
| var dennis = buildRunner('Dennis', 42); | ||
| var mary = buildRunner('Mary', 27); | ||
|
|
||
| var trainDennis = runSomeMiles(dennis, 3); | ||
| var trainMary = runSomeMiles(mary, 10); | ||
|
|
||
| assert.deepEqual(trainDennis, {name: 'Dennis', age: 42, milesRun: 3}); | ||
| assert.deepEqual(trainMary, {name: 'Mary', age: 27, milesRun: 10}); | ||
| }); | ||
|
|
||
| it('should be able to run more miles', function() { | ||
| var dennis = buildRunner('Dennis', 42); | ||
| var trainDennis = runSomeMiles(dennis, 13); | ||
|
|
||
| assert.deepEqual(trainDennis, {name: 'Dennis', age: 42, milesRun: 13}); | ||
|
|
||
| var trainDennisAgain = runSomeMiles(trainDennis, 21) | ||
|
|
||
| assert.deepEqual(trainDennisAgain, {name: 'Dennis', age: 42, milesRun: 34}); | ||
| }); | ||
|
|
||
| it('should be able to register for a race', function() { | ||
| var dennis = buildRunner('Dennis', 42); | ||
| var trainDennis = runSomeMiles(dennis, 8); | ||
|
|
||
| assert.deepEqual(trainDennis, {name: 'Dennis', age: 42, milesRun: 8}); | ||
|
|
||
| var trainDennisAgain = runSomeMiles(trainDennis, 31.5) | ||
|
|
||
| assert.deepEqual(trainDennisAgain, {name: 'Dennis', age: 42, milesRun: 39.5}); | ||
| assert.equal(registerForRace(trainDennisAgain), 'Congrats Dennis, you are now registered for the marathon!') | ||
| }); | ||
|
|
||
| it('should be able to register a different runner for a race', function() { | ||
| var mary = buildRunner('Mary', 27); | ||
| var trainMary = runSomeMiles(mary, 11); | ||
|
|
||
| assert.deepEqual(trainMary, {name: 'Mary', age: 27, milesRun: 11}); | ||
|
|
||
| var trainMaryAgain = runSomeMiles(trainMary, 18) | ||
|
|
||
| assert.deepEqual(trainMaryAgain, {name: 'Mary', age: 27, milesRun: 29}); | ||
| assert.equal(registerForRace(trainMaryAgain), 'Congrats Mary, you are now registered for the marathon!') | ||
| }); | ||
|
|
||
| it('should not be able to register if they havent trained enough', function() { | ||
| //"enough" is the same as the length of a marathon --> 26.2 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I appreciate the comment here. I know some of our past assessments had comments with extra context that they had to pay attention to, so this is great practice for them! Nice work on this test suite! |
||
| var dennis = buildRunner('Dennis', 42); | ||
| var mary = buildRunner('Mary', 27); | ||
|
|
||
| var trainDennis = runSomeMiles(dennis, 25); | ||
| var trainMary = runSomeMiles(mary, 21); | ||
|
|
||
| assert.deepEqual(trainDennis, {name: 'Dennis', age: 42, milesRun: 25}); | ||
| assert.deepEqual(trainMary, {name: 'Mary', age: 27, milesRun: 21}); | ||
|
|
||
|
|
||
| assert.equal(registerForRace(trainDennis), 'Sorry Dennis, you need more training to register for the marathon!') | ||
|
|
||
| var trainMaryAgain = runSomeMiles(trainMary, 5.2) | ||
| assert.equal(registerForRace(trainMaryAgain), 'Congrats Mary, you are now registered for the marathon!') | ||
| }); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test suite looks great! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| function createMyDirewolf(name, home, size) { | ||
| return { | ||
| name: name, | ||
| home: home || 'Beyond the Wall', | ||
| size: size || 'Massive', | ||
| starksToProtect: [], | ||
| protect: function(stark) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I worry that having methods in objects like this is too much OOP. I'm curious what others think! If no one else reviews this, maybe post in the #frontend-curriculum-updates channel with a code snippet and ask what they think.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, so far I haven't seen any of the assessments have examples with objects having methods. Potentially this could get moved out into a function that takes a stark in as an argument and returns either a new object or updates its values? |
||
| if (this.home === stark.location && this.starksToProtect.length < 2) { | ||
| stark.safe = true | ||
| this.huntsWhiteWalkers = false | ||
| this.starksToProtect.push(stark) | ||
| } | ||
| }, | ||
| huntsWhiteWalkers: true, | ||
| leave: function(stark) { | ||
| stark.safe = false | ||
| this.starksToProtect.pop() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function buildAStark(stark) { | ||
| return { | ||
| name: stark.name, | ||
| location: stark.area || 'Winterfell', | ||
| safe: false, | ||
| sayHouseWords: function() { | ||
| if (this.safe) { | ||
| return 'The North Remembers' | ||
| } else { | ||
| return 'Winter is Coming' | ||
| } | ||
| }, | ||
| callDirewolf: function(name, location) { | ||
| var direwolf = createMyDirewolf(name, location) | ||
| direwolf.home = this.location | ||
| direwolf.protect(this) | ||
| return direwolf | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| createMyDirewolf, | ||
| buildAStark | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| function describeOgre(ogreDetails) { | ||
| return { | ||
| name: ogreDetails.name, | ||
| home: ogreDetails.abode || 'Swamp', | ||
| encounter: function(human) { | ||
| human.encounterCounter++ | ||
| }, | ||
| swings: 0, | ||
| swingAt: function(human) { | ||
| this.swings++ | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| function createHuman(name) { | ||
| return { | ||
| name: name, | ||
| encounterCounter: 0, | ||
| noticesOgre: function() { | ||
| if (this.encounterCounter < 3) { | ||
| return false | ||
| } else { | ||
| this.encounterCounter = 0 | ||
| return true | ||
| } | ||
| }, | ||
| knockedOut: false, | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| describeOgre, | ||
| createHuman | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
|
|
||
| module.exports = { | ||
| //!!!after declaring your function above, un-comment the function export below!!! | ||
| // createYourPegasus, | ||
| // makeAnEntrance | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the tests for
runSomeMiles! This is a great situation of adding properties to an object if it doesn't exist, or updating it if it does. Cheers!