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
18 changes: 18 additions & 0 deletions marathon/README.md
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
Empty file added marathon/src/road.js
Empty file.
29 changes: 29 additions & 0 deletions marathon/src/runner.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) {
Copy link
Collaborator

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!

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
};
Empty file added marathon/test/road-test.js
Empty file.
80 changes: 80 additions & 0 deletions marathon/test/runner-test.js
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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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!')
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test suite looks great!

46 changes: 46 additions & 0 deletions mythical-creatures/exercises/direwolf.js
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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
}
34 changes: 34 additions & 0 deletions mythical-creatures/exercises/ogre.js
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
}
6 changes: 6 additions & 0 deletions mythical-creatures/exercises/pegasus.js
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
}
Loading