From 2e144e18b1e3fa3827d964b6fbdc63b8ad42053d Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 16:51:54 +0100 Subject: [PATCH 01/15] Test and Fixed #year attribute --- src/car.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/car.js b/src/car.js index 5a72227..a09a1c9 100644 --- a/src/car.js +++ b/src/car.js @@ -1,5 +1,5 @@ function Car(make, model, year, color){ - + this.year = year; } Car.prototype.sale = function(newOwner){ From 246684a94b5b94e6ebe5cf8cafd6cb19a0e65f6e Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 16:59:32 +0100 Subject: [PATCH 02/15] Fixed and tested #state attribute --- spec/test.js | 2 +- src/car.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/test.js b/spec/test.js index de4c18b..ab1b602 100644 --- a/spec/test.js +++ b/spec/test.js @@ -18,7 +18,7 @@ describe('Car', function(){ }); describe('#state', function(){ - xit('should initially be off', function(){ + it('should initially be off', function(){ expect(myCar.state).to.equal("off"); }); }); diff --git a/src/car.js b/src/car.js index a09a1c9..0e625d6 100644 --- a/src/car.js +++ b/src/car.js @@ -2,6 +2,8 @@ function Car(make, model, year, color){ this.year = year; } +Car.prototype.state = 'off'; + Car.prototype.sale = function(newOwner){ }; From 4ff52c3bddb40115141d3c0c88462a3aa5363936 Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 17:13:24 +0100 Subject: [PATCH 03/15] Fixed and tested #currentOwner, #passengers and #previousOwners attributes --- spec/test.js | 8 ++++---- src/car.js | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/spec/test.js b/spec/test.js index ab1b602..8c2bf0e 100644 --- a/spec/test.js +++ b/spec/test.js @@ -24,25 +24,25 @@ describe('Car', function(){ }); describe('#previousOwners', function(){ - xit('should exist and initially be empty', function(){ + it('should exist and initially be empty', function(){ expect(myCar.previousOwners).to.exist.to.be.empty; }); }); describe('#currentOwner', function(){ - xit('should initially be manufacturer', function(){ + it('should initially be manufacturer', function(){ expect(myCar.currentOwner).to.equal("Manufacturer"); }); }); describe('#passengers', function(){ - xit('should exist and initially be empty', function(){ + it('should exist and initially be empty', function(){ expect(myCar.passengers).to.exist.to.be.empty; }); }); describe('#sale', function(){ - xit('should move currentOwner to previousOwners array', function(){ + it('should move currentOwner to previousOwners array', function(){ myCar.sale("Charlie"); expect(myCar.previousOwners[0]).to.equal("Manufacturer"); }); diff --git a/src/car.js b/src/car.js index 0e625d6..7c15e51 100644 --- a/src/car.js +++ b/src/car.js @@ -4,8 +4,14 @@ function Car(make, model, year, color){ Car.prototype.state = 'off'; -Car.prototype.sale = function(newOwner){ +Car.prototype.previousOwners = []; + +Car.prototype.currentOwner = 'Manufacturer'; +Car.prototype.passengers = ''; + +Car.prototype.sale = function(newOwner){ + // append newOwner to previous }; Car.prototype.paint = function(newColor){ From 578763de763ac6b7bcc448d07a7c7d1f622bcf69 Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 17:22:10 +0100 Subject: [PATCH 04/15] Fixed and tested #sale attribute --- spec/test.js | 6 +++--- src/car.js | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spec/test.js b/spec/test.js index 8c2bf0e..1933597 100644 --- a/spec/test.js +++ b/spec/test.js @@ -47,21 +47,21 @@ describe('Car', function(){ expect(myCar.previousOwners[0]).to.equal("Manufacturer"); }); - xit('should update currentOwner with the new owner', function(){ + it('should update currentOwner with the new owner', function(){ myCar.sale("Charlie"); expect(myCar.currentOwner).to.equal("Charlie"); }); }); describe('#paint', function(){ - xit('should update the color of myCar', function(){ + it('should update the color of myCar', function(){ myCar.paint("Blue"); expect(myCar.color).to.equal("Blue"); }); }); describe('#start', function(){ - xit('should update the state to on', function(){ + it('should update the state to on', function(){ myCar.start(); expect(myCar.state).to.equal("on"); }); diff --git a/src/car.js b/src/car.js index 7c15e51..95e99e8 100644 --- a/src/car.js +++ b/src/car.js @@ -12,10 +12,11 @@ Car.prototype.passengers = ''; Car.prototype.sale = function(newOwner){ // append newOwner to previous + }; Car.prototype.paint = function(newColor){ - + this.color = newColor; }; From 718305dcea8fd4d13c904445f44fbbf141f6de40 Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 17:24:59 +0100 Subject: [PATCH 05/15] Fixed and tested #paint attribute --- spec/test.js | 2 +- src/car.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/test.js b/spec/test.js index 1933597..8558f34 100644 --- a/spec/test.js +++ b/spec/test.js @@ -61,7 +61,7 @@ describe('Car', function(){ }); describe('#start', function(){ - it('should update the state to on', function(){ + xit('should update the state to on', function(){ myCar.start(); expect(myCar.state).to.equal("on"); }); diff --git a/src/car.js b/src/car.js index 95e99e8..0a5ae89 100644 --- a/src/car.js +++ b/src/car.js @@ -12,7 +12,8 @@ Car.prototype.passengers = ''; Car.prototype.sale = function(newOwner){ // append newOwner to previous - + this.previousOwners.push(this.currentOwner); + this.currentOwner = newOwner; }; Car.prototype.paint = function(newColor){ From 4ce4a3f770310c944911a525cd49c0268e97bc4a Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 17:44:05 +0100 Subject: [PATCH 06/15] Fixed and tested #start --- spec/test.js | 2 +- src/car.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/test.js b/spec/test.js index 8558f34..1933597 100644 --- a/spec/test.js +++ b/spec/test.js @@ -61,7 +61,7 @@ describe('Car', function(){ }); describe('#start', function(){ - xit('should update the state to on', function(){ + it('should update the state to on', function(){ myCar.start(); expect(myCar.state).to.equal("on"); }); diff --git a/src/car.js b/src/car.js index 0a5ae89..45381bd 100644 --- a/src/car.js +++ b/src/car.js @@ -20,5 +20,9 @@ Car.prototype.paint = function(newColor){ this.color = newColor; }; +Car.prototype.start = function() { + this.state = 'on'; +} + module.exports=Car; \ No newline at end of file From f3a60030b384f26ca8786e3b8e173f32548456a6 Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 17:48:27 +0100 Subject: [PATCH 07/15] Fixed and tested #start --- spec/test.js | 2 +- src/car.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/test.js b/spec/test.js index 1933597..899e1fe 100644 --- a/spec/test.js +++ b/spec/test.js @@ -68,7 +68,7 @@ describe('Car', function(){ }); describe('#off', function(){ - xit('should update the state to off', function(){ + it('should update the state to off', function(){ myCar.off(); expect(myCar.state).to.equal("off"); }); diff --git a/src/car.js b/src/car.js index 45381bd..0c0d132 100644 --- a/src/car.js +++ b/src/car.js @@ -8,7 +8,7 @@ Car.prototype.previousOwners = []; Car.prototype.currentOwner = 'Manufacturer'; -Car.prototype.passengers = ''; +Car.prototype.passengers = []; Car.prototype.sale = function(newOwner){ // append newOwner to previous From 2749118eea822b14a4ce5991964f0768491bbbcc Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 17:56:08 +0100 Subject: [PATCH 08/15] Added and tested #off attribute --- src/car.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/car.js b/src/car.js index 0c0d132..8fbcce4 100644 --- a/src/car.js +++ b/src/car.js @@ -11,7 +11,6 @@ Car.prototype.currentOwner = 'Manufacturer'; Car.prototype.passengers = []; Car.prototype.sale = function(newOwner){ - // append newOwner to previous this.previousOwners.push(this.currentOwner); this.currentOwner = newOwner; }; @@ -24,5 +23,9 @@ Car.prototype.start = function() { this.state = 'on'; } +Car.prototype.off = function() { + this.state = 'off'; +} + module.exports=Car; \ No newline at end of file From 3222464e028b912ec68b2136e8da6a2b18537f1a Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 18:04:44 +0100 Subject: [PATCH 09/15] Added #pickUp attribute --- spec/test.js | 2 +- src/car.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/test.js b/spec/test.js index 899e1fe..96d35c3 100644 --- a/spec/test.js +++ b/spec/test.js @@ -75,7 +75,7 @@ describe('Car', function(){ }); describe('#pickUp', function(){ - xit('should add the passenger to the passengers array', function(){ + it('should add the passenger to the passengers array', function(){ myCar.start(); myCar.pickUp("john"); expect(myCar.passengers[0]).to.equal("john"); diff --git a/src/car.js b/src/car.js index 8fbcce4..cefd9e4 100644 --- a/src/car.js +++ b/src/car.js @@ -27,5 +27,10 @@ Car.prototype.off = function() { this.state = 'off'; } +Car.prototype.pickUp = function(passenger){ + this.start(); + this.passengers.push(passenger); +} + module.exports=Car; \ No newline at end of file From 75a7d9005048c4fc1a27b9775d4985494975c7f7 Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 18:30:20 +0100 Subject: [PATCH 10/15] Changed and tested #pickUp function --- spec/test.js | 6 +++--- src/car.js | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/spec/test.js b/spec/test.js index 96d35c3..a07dc97 100644 --- a/spec/test.js +++ b/spec/test.js @@ -75,13 +75,13 @@ describe('Car', function(){ }); describe('#pickUp', function(){ - it('should add the passenger to the passengers array', function(){ - myCar.start(); + xit('should add the passenger to the passengers array', function(){ + // myCar.start(); myCar.pickUp("john"); expect(myCar.passengers[0]).to.equal("john"); }); - xit('should only modify passengers array if car is on', function(){ + it('should only modify passengers array if car is on', function(){ // myCar.off(); myCar.pickUp("john"); expect(myCar.passengers[0]).to.be.empty; diff --git a/src/car.js b/src/car.js index cefd9e4..8655577 100644 --- a/src/car.js +++ b/src/car.js @@ -21,16 +21,17 @@ Car.prototype.paint = function(newColor){ Car.prototype.start = function() { this.state = 'on'; -} +}; Car.prototype.off = function() { this.state = 'off'; -} +}; -Car.prototype.pickUp = function(passenger){ - this.start(); - this.passengers.push(passenger); -} +Car.prototype.pickUp = function(passenger) { + if (this.state === 'on') { + this.passengers.push(passenger); + }; +}; module.exports=Car; \ No newline at end of file From e8aa9d54c7746b8231f3f7402c169b56d49b84ca Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 18:49:43 +0100 Subject: [PATCH 11/15] Created #dropOff feature and tested it --- spec/test.js | 2 +- src/car.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/test.js b/spec/test.js index a07dc97..85c451b 100644 --- a/spec/test.js +++ b/spec/test.js @@ -89,7 +89,7 @@ describe('Car', function(){ }); describe('#dropOff', function(){ - xit('should remove passenger from the passengers array', function(){ + it('should remove passenger from the passengers array', function(){ myCar.start(); myCar.pickUp("john"); myCar.dropOff("john"); diff --git a/src/car.js b/src/car.js index 8655577..36378a9 100644 --- a/src/car.js +++ b/src/car.js @@ -33,5 +33,14 @@ Car.prototype.pickUp = function(passenger) { }; }; +Car.prototype.dropOff = function(passenger) { + if (this.state === 'on') { + for (i = 0; i < this.passengers.length; i++) { + if (this.passengers[i] === passenger) { + this.passengers.splice(i, 1); + } + } + } +} module.exports=Car; \ No newline at end of file From a5ae761b59f52c21977ed1a554ee63a2d2b59edd Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 18:54:09 +0100 Subject: [PATCH 12/15] #dropOff feature will only run if the car is on --- spec/test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/test.js b/spec/test.js index 85c451b..85e7002 100644 --- a/spec/test.js +++ b/spec/test.js @@ -75,14 +75,14 @@ describe('Car', function(){ }); describe('#pickUp', function(){ - xit('should add the passenger to the passengers array', function(){ - // myCar.start(); + it('should add the passenger to the passengers array', function(){ + myCar.start(); myCar.pickUp("john"); expect(myCar.passengers[0]).to.equal("john"); }); it('should only modify passengers array if car is on', function(){ - // myCar.off(); + myCar.off(); myCar.pickUp("john"); expect(myCar.passengers[0]).to.be.empty; }); @@ -96,7 +96,7 @@ describe('Car', function(){ expect(myCar.passengers).to.be.empty; }); - xit('should leave passenger in the passengers array if car is off', function(){ + it('should leave passenger in the passengers array if car is off', function(){ myCar.start(); myCar.pickUp("john"); myCar.off(); From f1e6b89b41c7c979d7779d956e3c36735feb05c7 Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 19:24:56 +0100 Subject: [PATCH 13/15] Fixed issues with #pickUp --- spec/test.js | 6 +++--- src/car.js | 19 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/spec/test.js b/spec/test.js index 85e7002..fd160a7 100644 --- a/spec/test.js +++ b/spec/test.js @@ -82,21 +82,21 @@ describe('Car', function(){ }); it('should only modify passengers array if car is on', function(){ - myCar.off(); + // myCar.off(); myCar.pickUp("john"); expect(myCar.passengers[0]).to.be.empty; }); }); describe('#dropOff', function(){ - it('should remove passenger from the passengers array', function(){ + xit('should remove passenger from the passengers array', function(){ myCar.start(); myCar.pickUp("john"); myCar.dropOff("john"); expect(myCar.passengers).to.be.empty; }); - it('should leave passenger in the passengers array if car is off', function(){ + xit('should leave passenger in the passengers array if car is off', function(){ myCar.start(); myCar.pickUp("john"); myCar.off(); diff --git a/src/car.js b/src/car.js index 36378a9..5dc7c2b 100644 --- a/src/car.js +++ b/src/car.js @@ -1,15 +1,14 @@ function Car(make, model, year, color){ + this.make = make; + this.model = model; this.year = year; + this.color = color; + this.state = 'off'; + this.previousOwners = []; + this.currentOwner = 'Manufacturer'; + this.passengers = []; } -Car.prototype.state = 'off'; - -Car.prototype.previousOwners = []; - -Car.prototype.currentOwner = 'Manufacturer'; - -Car.prototype.passengers = []; - Car.prototype.sale = function(newOwner){ this.previousOwners.push(this.currentOwner); this.currentOwner = newOwner; @@ -28,9 +27,9 @@ Car.prototype.off = function() { }; Car.prototype.pickUp = function(passenger) { - if (this.state === 'on') { + if (this.state === "on") { this.passengers.push(passenger); - }; + } }; Car.prototype.dropOff = function(passenger) { From 7990b6485ebc3615eda497e1bc5098d3dbc6eb08 Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Thu, 30 Apr 2015 19:53:32 +0100 Subject: [PATCH 14/15] Final Commit --- spec/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/test.js b/spec/test.js index fd160a7..eba5b48 100644 --- a/spec/test.js +++ b/spec/test.js @@ -89,14 +89,14 @@ describe('Car', function(){ }); describe('#dropOff', function(){ - xit('should remove passenger from the passengers array', function(){ + it('should remove passenger from the passengers array', function(){ myCar.start(); myCar.pickUp("john"); myCar.dropOff("john"); expect(myCar.passengers).to.be.empty; }); - xit('should leave passenger in the passengers array if car is off', function(){ + it('should leave passenger in the passengers array if car is off', function(){ myCar.start(); myCar.pickUp("john"); myCar.off(); From 1c0e52a816d9987783765dd8bc3d53ac29121f06 Mon Sep 17 00:00:00 2001 From: Erika Jonikaite Date: Fri, 1 May 2015 10:32:23 +0100 Subject: [PATCH 15/15] Added an easier way of looking through an array --- src/car.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/car.js b/src/car.js index 5dc7c2b..2b9e0fc 100644 --- a/src/car.js +++ b/src/car.js @@ -39,6 +39,11 @@ Car.prototype.dropOff = function(passenger) { this.passengers.splice(i, 1); } } +// Alternative for going through an array when the array item is known: +// +// var passengerIndex = this.passengers.indexOf(passengers); +// this.passengers.splice(passengerIndex, 1); + } }