From f42d2749e573a401dbcb6def802f37889f3a27b7 Mon Sep 17 00:00:00 2001 From: Jeremiah Black Date: Mon, 13 Feb 2023 21:09:54 -0700 Subject: [PATCH 01/12] creating initial structure for their first test --- mythical-creatures/exercises/pegasus.js | 7 +++++++ mythical-creatures/test/pegasus-test.js | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 mythical-creatures/exercises/pegasus.js create mode 100644 mythical-creatures/test/pegasus-test.js diff --git a/mythical-creatures/exercises/pegasus.js b/mythical-creatures/exercises/pegasus.js new file mode 100644 index 000000000..c4b2d7e58 --- /dev/null +++ b/mythical-creatures/exercises/pegasus.js @@ -0,0 +1,7 @@ +function createYourPegasus() { + +}; + +module.exports = { + createYourPegasus, +} \ No newline at end of file diff --git a/mythical-creatures/test/pegasus-test.js b/mythical-creatures/test/pegasus-test.js new file mode 100644 index 000000000..65a1edaf0 --- /dev/null +++ b/mythical-creatures/test/pegasus-test.js @@ -0,0 +1,14 @@ +var assert = require('chai').assert; +var {createYourPegasus} = require('../exercises/pegasus'); + +describe('Pegasus', function() { + + it('should be a function', function() { + assert.isFunction(createYourPegasus); + }); + + it('should take any name you give it', function() { + var samplePegasus = + + }); +}); \ No newline at end of file From b1988a41d81d7537ec1b88baaff2807c135d4948 Mon Sep 17 00:00:00 2001 From: Jeremiah Black Date: Tue, 14 Feb 2023 20:50:18 -0700 Subject: [PATCH 02/12] want to look back and make sure it is a clear test suite for the first week --- mythical-creatures/exercises/pegasus.js | 14 +++++- mythical-creatures/test/pegasus-test.js | 66 +++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/mythical-creatures/exercises/pegasus.js b/mythical-creatures/exercises/pegasus.js index c4b2d7e58..4a484b14f 100644 --- a/mythical-creatures/exercises/pegasus.js +++ b/mythical-creatures/exercises/pegasus.js @@ -1,7 +1,19 @@ -function createYourPegasus() { +function createYourPegasus(namePlaceholder, colorPlaceholder, patternPlaceholder) { + var myPegasus = { + name: namePlaceholder, + color: colorPlaceholder, + pattern: patternPlaceholder, + canFly: true + } + return myPegasus +}; + +function makeAnEntrance(greeting, pegasus) { + return `${greeting}! My name is ${pegasus.name}, and I am a ${pegasus.color}, ${pegasus.pattern} coat Pegasus!` }; module.exports = { createYourPegasus, + makeAnEntrance } \ No newline at end of file diff --git a/mythical-creatures/test/pegasus-test.js b/mythical-creatures/test/pegasus-test.js index 65a1edaf0..c6031132b 100644 --- a/mythical-creatures/test/pegasus-test.js +++ b/mythical-creatures/test/pegasus-test.js @@ -1,14 +1,70 @@ var assert = require('chai').assert; -var {createYourPegasus} = require('../exercises/pegasus'); +var {createYourPegasus, makeAnEntrance} = require('../exercises/pegasus'); describe('Pegasus', function() { it('should be a function', function() { - assert.isFunction(createYourPegasus); + assert.isFunction(createYourPegasus) }); - it('should take any name you give it', function() { - var samplePegasus = - + it('should be an object', function() { + var samplePegasus = createYourPegasus() + + assert.typeOf(samplePegasus, "object") + }); + + it('should have any name you give it', function() { + var samplePegasus = createYourPegasus("Carlsbad Caveman") + + assert.equal(samplePegasus.name, "Carlsbad Caveman") + }); + + it('should have a color and a pattern', function() { + var samplePegasusColor = "mustard yellow" + var samplePegasusPattern = "zebra stripes" + var samplePegasusName = "Spin That DJ" + var newSamplePegasus = createYourPegasus(samplePegasusName, samplePegasusColor, samplePegasusPattern) + + assert.equal(newSamplePegasus.color, "mustard yellow") + assert.equal(newSamplePegasus.pattern, "zebra stripes") + }); + + it('should be able to have a different color and pattern', function() { + var newSamplePegasusColor = "cerulean" + var newSamplePegasusPattern = "leapord print" + var newSamplePegasusName = "Not Too Cool For School" + var newSamplePegasus = createYourPegasus(newSamplePegasusName, newSamplePegasusColor, newSamplePegasusPattern) + + assert.equal(newSamplePegasus.color, newSamplePegasusColor) + assert.equal(newSamplePegasus.pattern, newSamplePegasusPattern) + }); + + it('should know how to fly by default', function() { + var newSamplePegasusColor = "burgundy" + var newSamplePegasusPattern = "snow cap" + var newSamplePegasusName = "I'm Medusa's Baby" + var newSamplePegasus = { + name: newSamplePegasusName, + color: newSamplePegasusColor, + pattern: newSamplePegasusPattern, + canFly: true + } + + assert.deepEqual(newSamplePegasus, createYourPegasus(newSamplePegasusName, newSamplePegasusColor, newSamplePegasusPattern)) + }); + + it('should be able to make an entrance', function() { + var newSamplePegasusColor = "safety orange" + var newSamplePegasusPattern = "cape" + var newSamplePegasusName = "Who Do You Think You Are? I Am!" + var newSamplePegasus = createYourPegasus(newSamplePegasusName, newSamplePegasusColor, newSamplePegasusPattern) + + assert.equal(newSamplePegasus.name, "Who Do You Think You Are? I Am!") + assert.equal(newSamplePegasus.color, "safety orange") + assert.equal(newSamplePegasus.pattern, "cape") + + var greeting = "Hi" + + assert.equal(makeAnEntrance(greeting, newSamplePegasus), "Hi! My name is Who Do You Think You Are? I Am!, and I am a safety orange, cape coat Pegasus!") }); }); \ No newline at end of file From d12a7b91c623e44948836ff2a37118127e1fa1e2 Mon Sep 17 00:00:00 2001 From: Jeremiah Black Date: Wed, 15 Feb 2023 13:51:24 -0700 Subject: [PATCH 03/12] added skips and some comments --- mythical-creatures/exercises/pegasus.js | 19 +++---------------- mythical-creatures/test/pegasus-test.js | 14 +++++++------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/mythical-creatures/exercises/pegasus.js b/mythical-creatures/exercises/pegasus.js index 4a484b14f..5cac68a8b 100644 --- a/mythical-creatures/exercises/pegasus.js +++ b/mythical-creatures/exercises/pegasus.js @@ -1,19 +1,6 @@ -function createYourPegasus(namePlaceholder, colorPlaceholder, patternPlaceholder) { - var myPegasus = { - name: namePlaceholder, - color: colorPlaceholder, - pattern: patternPlaceholder, - canFly: true - } - - return myPegasus -}; - -function makeAnEntrance(greeting, pegasus) { - return `${greeting}! My name is ${pegasus.name}, and I am a ${pegasus.color}, ${pegasus.pattern} coat Pegasus!` -}; module.exports = { - createYourPegasus, - makeAnEntrance +//!!!after declaring your function above, un-comment the function export below!!! + // createYourPegasus, + // makeAnEntrance } \ No newline at end of file diff --git a/mythical-creatures/test/pegasus-test.js b/mythical-creatures/test/pegasus-test.js index c6031132b..e5ec49c13 100644 --- a/mythical-creatures/test/pegasus-test.js +++ b/mythical-creatures/test/pegasus-test.js @@ -3,23 +3,23 @@ var {createYourPegasus, makeAnEntrance} = require('../exercises/pegasus'); describe('Pegasus', function() { - it('should be a function', function() { + it.skip('should be a function', function() { assert.isFunction(createYourPegasus) }); - it('should be an object', function() { + it.skip('should be an object', function() { var samplePegasus = createYourPegasus() assert.typeOf(samplePegasus, "object") }); - it('should have any name you give it', function() { + it.skip('should have any name you give it', function() { var samplePegasus = createYourPegasus("Carlsbad Caveman") assert.equal(samplePegasus.name, "Carlsbad Caveman") }); - it('should have a color and a pattern', function() { + it.skip('should have a color and a pattern', function() { var samplePegasusColor = "mustard yellow" var samplePegasusPattern = "zebra stripes" var samplePegasusName = "Spin That DJ" @@ -29,7 +29,7 @@ describe('Pegasus', function() { assert.equal(newSamplePegasus.pattern, "zebra stripes") }); - it('should be able to have a different color and pattern', function() { + it.skip('should be able to have a different color and pattern', function() { var newSamplePegasusColor = "cerulean" var newSamplePegasusPattern = "leapord print" var newSamplePegasusName = "Not Too Cool For School" @@ -39,7 +39,7 @@ describe('Pegasus', function() { assert.equal(newSamplePegasus.pattern, newSamplePegasusPattern) }); - it('should know how to fly by default', function() { + it.skip('should know how to fly by default', function() { var newSamplePegasusColor = "burgundy" var newSamplePegasusPattern = "snow cap" var newSamplePegasusName = "I'm Medusa's Baby" @@ -53,7 +53,7 @@ describe('Pegasus', function() { assert.deepEqual(newSamplePegasus, createYourPegasus(newSamplePegasusName, newSamplePegasusColor, newSamplePegasusPattern)) }); - it('should be able to make an entrance', function() { + it.skip('should be able to make an entrance', function() { var newSamplePegasusColor = "safety orange" var newSamplePegasusPattern = "cape" var newSamplePegasusName = "Who Do You Think You Are? I Am!" From 6f9922f0be63826d35112dd50efd327437eda621 Mon Sep 17 00:00:00 2001 From: Jeremiah Black Date: Tue, 21 Feb 2023 10:43:45 -0700 Subject: [PATCH 04/12] added marathon test suite and README --- marathon/README.md | 18 ++++++++++++++++++ marathon/src/road.js | 0 marathon/src/runner.js | 0 marathon/test/road-test.js | 0 marathon/test/runner-test.js | 0 5 files changed, 18 insertions(+) create mode 100644 marathon/README.md create mode 100644 marathon/src/road.js create mode 100644 marathon/src/runner.js create mode 100644 marathon/test/road-test.js create mode 100644 marathon/test/runner-test.js diff --git a/marathon/README.md b/marathon/README.md new file mode 100644 index 000000000..6af0bd3cc --- /dev/null +++ b/marathon/README.md @@ -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 \ No newline at end of file diff --git a/marathon/src/road.js b/marathon/src/road.js new file mode 100644 index 000000000..e69de29bb diff --git a/marathon/src/runner.js b/marathon/src/runner.js new file mode 100644 index 000000000..e69de29bb diff --git a/marathon/test/road-test.js b/marathon/test/road-test.js new file mode 100644 index 000000000..e69de29bb diff --git a/marathon/test/runner-test.js b/marathon/test/runner-test.js new file mode 100644 index 000000000..e69de29bb From 2781f9d97437f4fb31b806fe8bce931b17fbf931 Mon Sep 17 00:00:00 2001 From: Jeremiah Black Date: Tue, 21 Feb 2023 19:09:25 -0700 Subject: [PATCH 05/12] got first runner tests written --- marathon/src/runner.js | 29 +++++++++++++ marathon/test/runner-test.js | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/marathon/src/runner.js b/marathon/src/runner.js index e69de29bb..a65bb1635 100644 --- a/marathon/src/runner.js +++ b/marathon/src/runner.js @@ -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 +}; \ No newline at end of file diff --git a/marathon/test/runner-test.js b/marathon/test/runner-test.js index e69de29bb..26407504f 100644 --- a/marathon/test/runner-test.js +++ b/marathon/test/runner-test.js @@ -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 + 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!') + }); +}); \ No newline at end of file From 0e5eedf945c61cfbf0ffec6f8db0c0b8dd33e91d Mon Sep 17 00:00:00 2001 From: Jeremiah Black Date: Wed, 1 Mar 2023 14:00:13 -0700 Subject: [PATCH 06/12] modified all direwolf (not stark) tests to fp --- mythical-creatures/test/direwolf-test.js | 36 +++++++++++++----------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/mythical-creatures/test/direwolf-test.js b/mythical-creatures/test/direwolf-test.js index 75a9b9f85..c4115561d 100644 --- a/mythical-creatures/test/direwolf-test.js +++ b/mythical-creatures/test/direwolf-test.js @@ -1,62 +1,66 @@ const assert = require('chai').assert; -const Direwolf = require('../exercises/direwolf'); -const Stark = require('../exercises/stark'); +const { createMyDirewolf } = require('../exercises/direwolf'); +const { buildAStark } = require('../exercises/stark'); describe('Direwolf', function() { it.skip('should be a function', function() { - assert.isFunction(Direwolf); + assert.isFunction(createMyDirewolf); }); - it.skip('should instantiate our good friend, Direwolf', function() { - const direwolf = new Direwolf(); + it.skip('should create our new friend, Direwolf', function() { + const direwolf = createMyDirewolf(); assert.isObject(direwolf); }); it.skip('should have a name', function() { - const direwolf = new Direwolf('Nymeria'); + const direwolf = createMyDirewolf('Nymeria'); assert.equal(direwolf.name, 'Nymeria'); }); it.skip('should have a default home of Beyond the Wall', function() { - const direwolf = new Direwolf('Lady'); + const direwolf = createMyDirewolf('Lady'); assert.equal(direwolf.name, 'Lady'); assert.equal(direwolf.home, 'Beyond the Wall'); }); it.skip('should be able to have other homes', function() { - const direwolf = new Direwolf('Ghost', 'Winterfell'); + const direwolf = createMyDirewolf('Ghost', 'Winterfell'); assert.equal(direwolf.home, 'Winterfell'); }); it.skip('should have a default size of massive', function() { - const direwolf = new Direwolf('Ghost'); + const direwolf = createMyDirewolf('Ghost'); assert.equal(direwolf.size, 'Massive'); }); it.skip('should be able to have another size', function() { - const direwolf = new Direwolf('Shaggydog', 'Karhold', 'Smol Pupper'); + const direwolf = createMyDirewolf('Shaggydog', 'Karhold', 'Smol Pupper'); - assert.equal(direwolf.name, 'Shaggydog'); - assert.equal(direwolf.home, 'Karhold'); - assert.equal(direwolf.size, 'Smol Pupper'); + assert.deepEqual(direwolf, { + name: 'Shaggydog', + home: 'Karhold', + size: 'Smol Pupper' + }); }); - it.skip('should instantiate our good friend, Stark', function() { - const stark = new Stark({name: 'Bran'}); + it.skip('should build our new friend, Stark', function() { + const stark = buildAStark({name: 'Bran'}); assert.isObject(stark); }); it.skip('should have a name', function() { - const stark = new Stark({name:'Bran'}); + const stark = buildAStark({name:'Bran'}); assert.equal(stark.name, 'Bran'); }); + //!!!!!!!!!!!!!!!! start here when you get back + it.skip('should have a default location of Winterfell', function() { const stark = new Stark({name:'Bran'}); From dd9fd41d80f45ceb956f82c03ccf15f0f964d294 Mon Sep 17 00:00:00 2001 From: Jeremiah Black Date: Tue, 7 Mar 2023 09:17:00 -0700 Subject: [PATCH 07/12] rough tests for direwolf added - need to test them --- mythical-creatures/test/direwolf-test.js | 67 +++++++++++------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/mythical-creatures/test/direwolf-test.js b/mythical-creatures/test/direwolf-test.js index c4115561d..d393f4484 100644 --- a/mythical-creatures/test/direwolf-test.js +++ b/mythical-creatures/test/direwolf-test.js @@ -1,6 +1,6 @@ const assert = require('chai').assert; -const { createMyDirewolf } = require('../exercises/direwolf'); -const { buildAStark } = require('../exercises/stark'); +const { createMyDirewolf, buildAStark } = require('../exercises/direwolf'); +// const { buildAStark } = require('../exercises/stark'); describe('Direwolf', function() { @@ -40,11 +40,8 @@ describe('Direwolf', function() { it.skip('should be able to have another size', function() { const direwolf = createMyDirewolf('Shaggydog', 'Karhold', 'Smol Pupper'); - assert.deepEqual(direwolf, { - name: 'Shaggydog', - home: 'Karhold', - size: 'Smol Pupper' - }); + assert.equal(direwolf.size, 'Smol Pupper'); + assert.equal(direwolf.home, 'Karhold'); }); it.skip('should build our new friend, Stark', function() { @@ -59,25 +56,24 @@ describe('Direwolf', function() { assert.equal(stark.name, 'Bran'); }); - //!!!!!!!!!!!!!!!! start here when you get back it.skip('should have a default location of Winterfell', function() { - const stark = new Stark({name:'Bran'}); + const stark = buildAStark({name:'Bran'}); assert.equal(stark.name, 'Bran'); assert.equal(stark.location, 'Winterfell'); }); it.skip('should be able to have different locations', function() { - const stark = new Stark({name: 'Eddard', area: 'King\'s Landing'}) + const stark = buildAStark({name: 'Eddard', area: 'King\'s Landing'}) assert.equal(stark.name, 'Eddard') assert.equal(stark.location, 'King\'s Landing') }) it.skip('should start with no Starks to protect', function() { - const direwolf = new Direwolf('Nymeria'); - const stark = new Stark({name: 'Arya'}); + const direwolf = createMyDirewolf('Nymeria'); + const stark = buildAStark({name: 'Arya'}); assert.deepEqual(direwolf.starksToProtect, []); assert.equal(direwolf.home, 'Beyond the Wall'); @@ -85,8 +81,8 @@ describe('Direwolf', function() { }); it.skip('should be able to protect a Stark', function() { - const direwolf = new Direwolf('Nymeria', 'Riverlands'); - const stark = new Stark({name: 'Arya', area: 'Riverlands'}); + const direwolf = createMyDirewolf('Nymeria', 'Riverlands'); + const stark = buildAStark({name: 'Arya', area: 'Riverlands'}); assert.deepEqual(direwolf.starksToProtect, []); @@ -96,8 +92,8 @@ describe('Direwolf', function() { }); it.skip('should only be able to protect a Stark if direwolf and Stark locations match', function() { - const direwolf = new Direwolf('Ghost'); - const stark = new Stark({name: 'John', area: 'King\'s Landing'}); + const direwolf = createMyDirewolf('Ghost'); + const stark = buildAStark({name: 'John', area: 'King\'s Landing'}); direwolf.protect(stark); @@ -105,13 +101,13 @@ describe('Direwolf', function() { }); it.skip('should only be able to protect two Starks at a time', function() { - const direwolf1 = new Direwolf('Summer', 'Winterfell'); - const direwolf2 = new Direwolf('Lady', 'Winterfell'); - const stark1 = new Stark({name: 'Sansa'}); - const stark2 = new Stark({name: 'John'}); - const stark3 = new Stark({name: 'Rob'}); - const stark4 = new Stark({name: 'Bran'}); - const stark5 = new Stark({name: 'Arya'}); + const direwolf1 = createMyDirewolf('Summer', 'Winterfell'); + const direwolf2 = createMyDirewolf('Lady', 'Winterfell'); + const stark1 = buildAStark({name: 'Sansa'}); + const stark2 = buildAStark({name: 'John'}); + const stark3 = buildAStark({name: 'Rob'}); + const stark4 = buildAStark({name: 'Bran'}); + const stark5 = buildAStark({name: 'Arya'}); direwolf1.protect(stark1); direwolf1.protect(stark2); @@ -129,21 +125,21 @@ describe('Direwolf', function() { }); it.skip('Stark should start off unsafe', function() { - const stark = new Stark({name: 'John', area: 'Winterfell'}); + const stark = buildAStark({name: 'John', area: 'Winterfell'}); assert.equal(stark.safe, false); }); it.skip('should know their house words', function() { - const stark = new Stark ({name: 'Benjen'}) + const stark = buildAStark({name: 'Benjen'}) assert.equal(stark.sayHouseWords(), 'Winter is Coming') }) it.skip('should change house words once protected', function() { - const direwolf = new Direwolf('Nymeria', 'Dorne'); - const stark1 = new Stark({name: 'Arya', area: 'Dorne'}); - const stark2 = new Stark({name: 'Sansa', area: 'Dorne'}); + const direwolf = createMyDirewolf('Nymeria', 'Dorne'); + const stark1 = buildAStark({name: 'Arya', area: 'Dorne'}); + const stark2 = buildAStark({name: 'Sansa', area: 'Dorne'}); assert.equal(stark1.safe, false); assert.equal(stark2.safe, false); @@ -157,8 +153,8 @@ describe('Direwolf', function() { }); it.skip('should hunt white walkers when not protecting Starks', function() { - const direwolf = new Direwolf('Nymeria', 'Winterfell'); - const stark = new Stark({name: 'Sansa'}); + const direwolf = createMyDirewolf('Nymeria', 'Winterfell'); + const stark = buildAStark({name: 'Sansa'}); assert.equal(direwolf.huntsWhiteWalkers, true); @@ -167,10 +163,10 @@ describe('Direwolf', function() { }); it.skip('should be able to stop protecting Starks', function() { - const direwolf1 = new Direwolf('Summer', 'Winterfell'); - const direwolf2 = new Direwolf('Lady', 'Winterfell'); - const stark1 = new Stark({name: 'Sansa'}); - const stark2 = new Stark({name: 'Arya'}); + const direwolf1 = createMyDirewolf('Summer', 'Winterfell'); + const direwolf2 = createMyDirewolf('Lady', 'Winterfell'); + const stark1 = buildAStark({name: 'Sansa'}); + const stark2 = buildAStark({name: 'Arya'}); direwolf1.protect(stark2); assert.equal(stark2.safe, true); @@ -184,11 +180,10 @@ describe('Direwolf', function() { }); it.skip('should be able to call their direwolf to become protected', function() { - const stark = new Stark({name: 'Arya', area: 'Riverlands'}) + const stark = buildAStark({name: 'Arya', area: 'Riverlands'}) var direwolf = stark.callDirewolf('Nymeria', 'Winterfell') - assert.instanceOf(direwolf, Direwolf) assert.equal(direwolf.name, 'Nymeria') assert.equal(direwolf.home, 'Riverlands') assert.deepEqual(direwolf.starksToProtect[0].name, 'Arya') From f4f9e72d26c5a188fcdd0af4ce6441f69c49f926 Mon Sep 17 00:00:00 2001 From: Jeremiah Black Date: Tue, 7 Mar 2023 09:48:31 -0700 Subject: [PATCH 08/12] feels spicy, students will need to understand 'this' in context --- mythical-creatures/exercises/direwolf.js | 46 ++++++++++++++++++++++++ mythical-creatures/test/direwolf-test.js | 42 +++++++++++----------- 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/mythical-creatures/exercises/direwolf.js b/mythical-creatures/exercises/direwolf.js index e69de29bb..0c3e9593d 100644 --- a/mythical-creatures/exercises/direwolf.js +++ b/mythical-creatures/exercises/direwolf.js @@ -0,0 +1,46 @@ +function createMyDirewolf(name, home, size) { + return { + name: name, + home: home || 'Beyond the Wall', + size: size || 'Massive', + starksToProtect: [], + protect: function(stark) { + 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 +} \ No newline at end of file diff --git a/mythical-creatures/test/direwolf-test.js b/mythical-creatures/test/direwolf-test.js index d393f4484..8b0167685 100644 --- a/mythical-creatures/test/direwolf-test.js +++ b/mythical-creatures/test/direwolf-test.js @@ -4,74 +4,74 @@ const { createMyDirewolf, buildAStark } = require('../exercises/direwolf'); describe('Direwolf', function() { - it.skip('should be a function', function() { + it('should be a function', function() { assert.isFunction(createMyDirewolf); }); - it.skip('should create our new friend, Direwolf', function() { + it('should create our new friend, Direwolf', function() { const direwolf = createMyDirewolf(); assert.isObject(direwolf); }); - it.skip('should have a name', function() { + it('should have a name', function() { const direwolf = createMyDirewolf('Nymeria'); assert.equal(direwolf.name, 'Nymeria'); }); - it.skip('should have a default home of Beyond the Wall', function() { + it('should have a default home of Beyond the Wall', function() { const direwolf = createMyDirewolf('Lady'); assert.equal(direwolf.name, 'Lady'); assert.equal(direwolf.home, 'Beyond the Wall'); }); - it.skip('should be able to have other homes', function() { + it('should be able to have other homes', function() { const direwolf = createMyDirewolf('Ghost', 'Winterfell'); assert.equal(direwolf.home, 'Winterfell'); }); - it.skip('should have a default size of massive', function() { + it('should have a default size of massive', function() { const direwolf = createMyDirewolf('Ghost'); assert.equal(direwolf.size, 'Massive'); }); - it.skip('should be able to have another size', function() { + it('should be able to have another size', function() { const direwolf = createMyDirewolf('Shaggydog', 'Karhold', 'Smol Pupper'); assert.equal(direwolf.size, 'Smol Pupper'); assert.equal(direwolf.home, 'Karhold'); }); - it.skip('should build our new friend, Stark', function() { + it('should build our new friend, Stark', function() { const stark = buildAStark({name: 'Bran'}); assert.isObject(stark); }); - it.skip('should have a name', function() { + it('should have a name', function() { const stark = buildAStark({name:'Bran'}); assert.equal(stark.name, 'Bran'); }); - it.skip('should have a default location of Winterfell', function() { + it('should have a default location of Winterfell', function() { const stark = buildAStark({name:'Bran'}); assert.equal(stark.name, 'Bran'); assert.equal(stark.location, 'Winterfell'); }); - it.skip('should be able to have different locations', function() { + it('should be able to have different locations', function() { const stark = buildAStark({name: 'Eddard', area: 'King\'s Landing'}) assert.equal(stark.name, 'Eddard') assert.equal(stark.location, 'King\'s Landing') }) - it.skip('should start with no Starks to protect', function() { + it('should start with no Starks to protect', function() { const direwolf = createMyDirewolf('Nymeria'); const stark = buildAStark({name: 'Arya'}); @@ -80,7 +80,7 @@ describe('Direwolf', function() { assert.equal(stark.location, 'Winterfell'); }); - it.skip('should be able to protect a Stark', function() { + it('should be able to protect a Stark', function() { const direwolf = createMyDirewolf('Nymeria', 'Riverlands'); const stark = buildAStark({name: 'Arya', area: 'Riverlands'}); @@ -91,7 +91,7 @@ describe('Direwolf', function() { assert.equal(direwolf.starksToProtect[0].name, 'Arya'); }); - it.skip('should only be able to protect a Stark if direwolf and Stark locations match', function() { + it('should only be able to protect a Stark if direwolf and Stark locations match', function() { const direwolf = createMyDirewolf('Ghost'); const stark = buildAStark({name: 'John', area: 'King\'s Landing'}); @@ -100,7 +100,7 @@ describe('Direwolf', function() { assert.deepEqual(direwolf.starksToProtect, []); }); - it.skip('should only be able to protect two Starks at a time', function() { + it('should only be able to protect two Starks at a time', function() { const direwolf1 = createMyDirewolf('Summer', 'Winterfell'); const direwolf2 = createMyDirewolf('Lady', 'Winterfell'); const stark1 = buildAStark({name: 'Sansa'}); @@ -124,19 +124,19 @@ describe('Direwolf', function() { assert.equal(direwolf2.starksToProtect[1].name, 'Bran'); }); - it.skip('Stark should start off unsafe', function() { + it('Stark should start off unsafe', function() { const stark = buildAStark({name: 'John', area: 'Winterfell'}); assert.equal(stark.safe, false); }); - it.skip('should know their house words', function() { + it('should know their house words', function() { const stark = buildAStark({name: 'Benjen'}) assert.equal(stark.sayHouseWords(), 'Winter is Coming') }) - it.skip('should change house words once protected', function() { + it('should change house words once protected', function() { const direwolf = createMyDirewolf('Nymeria', 'Dorne'); const stark1 = buildAStark({name: 'Arya', area: 'Dorne'}); const stark2 = buildAStark({name: 'Sansa', area: 'Dorne'}); @@ -152,7 +152,7 @@ describe('Direwolf', function() { assert.equal(stark2.sayHouseWords(), 'Winter is Coming'); }); - it.skip('should hunt white walkers when not protecting Starks', function() { + it('should hunt white walkers when not protecting Starks', function() { const direwolf = createMyDirewolf('Nymeria', 'Winterfell'); const stark = buildAStark({name: 'Sansa'}); @@ -162,7 +162,7 @@ describe('Direwolf', function() { assert.equal(direwolf.huntsWhiteWalkers, false); }); - it.skip('should be able to stop protecting Starks', function() { + it('should be able to stop protecting Starks', function() { const direwolf1 = createMyDirewolf('Summer', 'Winterfell'); const direwolf2 = createMyDirewolf('Lady', 'Winterfell'); const stark1 = buildAStark({name: 'Sansa'}); @@ -179,7 +179,7 @@ describe('Direwolf', function() { assert.equal(stark2.safe, false); }); - it.skip('should be able to call their direwolf to become protected', function() { + it('should be able to call their direwolf to become protected', function() { const stark = buildAStark({name: 'Arya', area: 'Riverlands'}) var direwolf = stark.callDirewolf('Nymeria', 'Winterfell') From e96513029bce4b79196f3cf8352dfc8c447b9f70 Mon Sep 17 00:00:00 2001 From: Jeremiah Black Date: Tue, 7 Mar 2023 09:53:27 -0700 Subject: [PATCH 09/12] removed stark implementation file cleaned up commented out code --- mythical-creatures/test/direwolf-test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/mythical-creatures/test/direwolf-test.js b/mythical-creatures/test/direwolf-test.js index 8b0167685..02fc8c820 100644 --- a/mythical-creatures/test/direwolf-test.js +++ b/mythical-creatures/test/direwolf-test.js @@ -1,6 +1,5 @@ const assert = require('chai').assert; const { createMyDirewolf, buildAStark } = require('../exercises/direwolf'); -// const { buildAStark } = require('../exercises/stark'); describe('Direwolf', function() { From e54e81c650241ada7954944b679a06860d55dade Mon Sep 17 00:00:00 2001 From: Jeremiah Black Date: Tue, 7 Mar 2023 11:25:51 -0700 Subject: [PATCH 10/12] start modifying ogre test to fp --- mythical-creatures/test/ogre-test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mythical-creatures/test/ogre-test.js b/mythical-creatures/test/ogre-test.js index e3ef84fad..aa7400576 100644 --- a/mythical-creatures/test/ogre-test.js +++ b/mythical-creatures/test/ogre-test.js @@ -1,12 +1,12 @@ const assert = require('chai').assert; -const Ogre = require('../exercises/ogre'); -const Human = require('../exercises/human'); +const { describeOgre } = require('../exercises/ogre'); +// const Human = require('../exercises/human'); describe('Ogre', () => { // Oh no! It looks like there's no text in the `it` blocks! I guess you'll have to read the tests SUPER carefully to know what the test is expecting! - it.skip('', function() { - const ogre = new Ogre({name:'Brak'}); + it('', function() { + const ogre = describeOgre({name:'Brak'}); assert.equal(ogre.name, 'Brak'); }); From a578a86e509e28896821f0e01b329ac45797b60f Mon Sep 17 00:00:00 2001 From: Jeremiah Black Date: Tue, 7 Mar 2023 11:48:23 -0700 Subject: [PATCH 11/12] having a hard time converting final 2 tests, consider deleting them and making this an earlier suite --- mythical-creatures/exercises/ogre.js | 34 +++++++++++++++++++++ mythical-creatures/test/ogre-test.js | 44 ++++++++++++++-------------- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/mythical-creatures/exercises/ogre.js b/mythical-creatures/exercises/ogre.js index e69de29bb..87529a943 100644 --- a/mythical-creatures/exercises/ogre.js +++ b/mythical-creatures/exercises/ogre.js @@ -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 +} \ No newline at end of file diff --git a/mythical-creatures/test/ogre-test.js b/mythical-creatures/test/ogre-test.js index aa7400576..0143a88cb 100644 --- a/mythical-creatures/test/ogre-test.js +++ b/mythical-creatures/test/ogre-test.js @@ -1,5 +1,5 @@ const assert = require('chai').assert; -const { describeOgre } = require('../exercises/ogre'); +const { describeOgre, createHuman } = require('../exercises/ogre'); // const Human = require('../exercises/human'); describe('Ogre', () => { @@ -10,19 +10,19 @@ describe('Ogre', () => { assert.equal(ogre.name, 'Brak'); }); - it.skip('', function() { - const ogre = new Ogre({name: 'Brak'}); + it('', function() { + const ogre = describeOgre({name: 'Brak'}); assert.equal(ogre.home, 'Swamp'); }); - it.skip('', function() { - const ogre = new Ogre({name: 'Brak', abode: 'The Ritz'}); + it('', function() { + const ogre = describeOgre({name: 'Brak', abode: 'The Ritz'}); assert.equal(ogre.home, 'The Ritz'); }); - it.skip('', function() { - const ogre = new Ogre({name: 'Brak'}); - const human = new Human('Jane'); + it('', function() { + const ogre = describeOgre({name: 'Brak'}); + const human = createHuman('Jane'); assert.equal(human.name, 'Jane'); assert.equal(human.encounterCounter, 0) @@ -31,9 +31,9 @@ describe('Ogre', () => { assert.equal(human.encounterCounter, 1); }); - it.skip('', function() { - const ogre = new Ogre({name: 'Brak'}); - const human = new Human('Jane'); + it('', function() { + const ogre = describeOgre({name: 'Brak'}); + const human = createHuman('Jane'); ogre.encounter(human); ogre.encounter(human); @@ -43,9 +43,9 @@ describe('Ogre', () => { assert.equal(human.noticesOgre(), true); }); - it.skip('', function() { - const ogre = new Ogre({name: 'Brak'}); - const human = new Human('Jane'); + it('', function() { + const ogre = describeOgre({name: 'Brak'}); + const human = createHuman('Jane'); assert.equal(human.noticesOgre(), false); @@ -62,9 +62,9 @@ describe('Ogre', () => { assert.equal(human.noticesOgre(), true); }); - it.skip('', function() { - const ogre = new Ogre({name: 'Brak'}); - const human = new Human('Jane'); + it('', function() { + const ogre = describeOgre({name: 'Brak'}); + const human = createHuman('Jane'); assert.equal(ogre.swings, 0) ogre.swingAt(human); @@ -73,8 +73,8 @@ describe('Ogre', () => { }); it.skip('', function() { - const ogre = new Ogre({name: 'Brak'}); - const human = new Human('Jane'); + const ogre = describeOgre({name: 'Brak'}); + const human = createHuman('Jane'); ogre.encounter(human); assert.equal(ogre.swings, 0); @@ -86,9 +86,9 @@ describe('Ogre', () => { assert.equal(ogre.swings, 1); }); - it.skip('', function() { - const ogre = new Ogre({name: 'Brak'}); - const human = new Human('Jane'); + it('', function() { + const ogre = describeOgre({name: 'Brak'}); + const human = createHuman('Jane'); assert.equal(human.knockedOut, false) ogre.encounter(human); From 4d73e376c014b8b079ceead273bcc70587565e7f Mon Sep 17 00:00:00 2001 From: Jeremiah Black Date: Tue, 7 Mar 2023 11:50:56 -0700 Subject: [PATCH 12/12] commented final tests out for now --- mythical-creatures/test/ogre-test.js | 64 ++++++++++++++-------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/mythical-creatures/test/ogre-test.js b/mythical-creatures/test/ogre-test.js index 0143a88cb..7aec31238 100644 --- a/mythical-creatures/test/ogre-test.js +++ b/mythical-creatures/test/ogre-test.js @@ -86,36 +86,36 @@ describe('Ogre', () => { assert.equal(ogre.swings, 1); }); - it('', function() { - const ogre = describeOgre({name: 'Brak'}); - const human = createHuman('Jane'); - - assert.equal(human.knockedOut, false) - ogre.encounter(human); - ogre.encounter(human); - ogre.encounter(human); - ogre.encounter(human); - ogre.encounter(human); - ogre.encounter(human); - - assert.equal(human.encounterCounter, 6); - assert.equal(ogre.swings, 2); - assert.equal(human.knockedOut, true); - }); - - it.skip('', function() { - const ogre = new Ogre({name: 'Brak'}); - const human = new Human('Jane'); - - ogre.encounter(human); - ogre.encounter(human); - ogre.encounter(human); - ogre.encounter(human); - ogre.encounter(human); - ogre.encounter(human); - assert.equal(human.knockedOut, true); - - ogre.apologize(human); - assert.equal(human.knockedOut, false); - }); + // it('', function() { + // const ogre = describeOgre({name: 'Brak'}); + // const human = createHuman('Jane'); + + // assert.equal(human.knockedOut, false) + // ogre.encounter(human); + // ogre.encounter(human); + // ogre.encounter(human); + // ogre.encounter(human); + // ogre.encounter(human); + // ogre.encounter(human); + + // assert.equal(human.encounterCounter, 6); + // assert.equal(ogre.swings, 2); + // assert.equal(human.knockedOut, true); + // }); + + // it.skip('', function() { + // const ogre = new Ogre({name: 'Brak'}); + // const human = new Human('Jane'); + + // ogre.encounter(human); + // ogre.encounter(human); + // ogre.encounter(human); + // ogre.encounter(human); + // ogre.encounter(human); + // ogre.encounter(human); + // assert.equal(human.knockedOut, true); + + // ogre.apologize(human); + // assert.equal(human.knockedOut, false); + // }); });