-
Notifications
You must be signed in to change notification settings - Fork 22
Panda Assignment submission. #20
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
Open
codeblahblah
wants to merge
19
commits into
RubyoffRails:master
Choose a base branch
from
codeblahblah:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7617310
Panda Assignment submission.
codeblahblah 66d4a23
Corrections to Panda Assignment submission.
codeblahblah 86755ba
Tiger Assignment submission.
codeblahblah 4344aac
Panda and Tiger assignment corrections.
codeblahblah 93e0222
Added update feature to Automobile class.
codeblahblah 4fa755a
Stopped update method from resetting instance variables if set.
codeblahblah 31b8b38
Feature: Allow overwrite on update.
codeblahblah c5bf5c3
Feature: Fixed typos.
codeblahblah 3a2f800
Eagle level: Create a class variable (@@) in the Vehicle that tracks …
codeblahblah 73bb8b6
Eagle level: Corrected Automobile super method call to take zero argu…
codeblahblah cb981b9
Eagle level: First attempt at Vehicle search method based on https://…
codeblahblah 4fba59b
Eagle level: Implemented Vehicle search method.
codeblahblah d7b7038
Eagle level: Added a more dynamic 'register' method.
codeblahblah 8af26ed
Eagle level: Added first RSpec test for Motorcycle class.
codeblahblah 4b8b0bb
Cleaned up registration process and add test case ideas.
codeblahblah e476509
Feature: Added .build . First Automobile test case now passes.
codeblahblah 4e247f2
Feature: Added Automobile and Motorcycle test specs.
codeblahblah c7e1d6d
Switched to RSpec's let(:sym) {} syntax and added more tests.
codeblahblah 0ef2e55
Latest Vehicle test specfications including #search test
codeblahblah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| class Vehicle | ||
|
|
||
| @@vehicles = [] | ||
| def initialize | ||
|
|
||
| end | ||
|
|
||
| def self.count | ||
| @@vehicles.count | ||
| end | ||
|
|
||
| def self.search(args) | ||
|
|
||
| results = @@vehicles | ||
| args.each do |key, value| | ||
| results.select!{|vehicle| vehicle.send(key) == value.to_sym} | ||
| end | ||
| results | ||
| end | ||
|
|
||
| def self.all_vehicles | ||
| @@vehicles | ||
| end | ||
|
|
||
| def self.wheels | ||
| 2 | ||
| end | ||
| end | ||
|
|
||
|
|
||
| class Automobile < Vehicle | ||
| @@auto = [] | ||
| attr_accessor :color, :make, :model, :year | ||
| def self.wheels | ||
| 4 | ||
| end | ||
|
|
||
| def initialize(args) | ||
| @color = args[:color] | ||
| @make = args[:make] | ||
| @model = args[:model] | ||
| @year = args[:year] | ||
| super() | ||
| end | ||
|
|
||
| def self.build(args) | ||
| auto = Automobile.new(args) | ||
| @@vehicles << auto | ||
| @@auto << auto | ||
| auto | ||
| end | ||
|
|
||
| def update(new_args) | ||
| @color = new_args[:color] if new_args[:color] | ||
| @make = new_args[:make] if new_args[:make] | ||
| @model = new_args[:model] if new_args[:model] | ||
| @year = new_args[:year] if new_args[:year] | ||
| end | ||
|
|
||
| def self.all_autos | ||
| @@auto | ||
| end | ||
|
|
||
| def self.count | ||
| @@auto.count | ||
| end | ||
| end | ||
|
|
||
| class Motorcycle < Vehicle | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| class Automobile | ||
| attr_accessor :color, :make, :model, :year | ||
| def self.wheels | ||
| 4 | ||
| end | ||
|
|
||
| def initialize(args) | ||
| @color = args[:color] | ||
| @make = args[:make] | ||
| @model = args[:model] | ||
| @year = args[:year] | ||
| end | ||
| end | ||
|
|
||
| puts Automobile.wheels |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| class Vehicle | ||
| def self.wheels | ||
| 2 | ||
| end | ||
| end | ||
|
|
||
| class Automobile < Vehicle | ||
|
|
||
| attr_accessor :color, :make, :model, :year | ||
| def self.wheels | ||
| 4 | ||
| end | ||
|
|
||
| def initialize(args) | ||
| @color = args[:color] | ||
| @make = args[:make] | ||
| @model = args[:model] | ||
| @year = args[:year] | ||
| end | ||
|
|
||
| def update(new_args) | ||
| @color = new_args[:color] if new_args[:color] | ||
| @make = new_args[:make] if new_args[:make] | ||
| @model = new_args[:model] if new_args[:model] | ||
| @year = new_args[:year] if new_args[:year] | ||
| end | ||
| end | ||
|
|
||
| class Motorcycle < Vehicle | ||
| end | ||
|
|
||
| puts Motorcycle.wheels | ||
|
|
||
| auto = Automobile.new(color: 'Red', make: 'Ford', model: 'Mustang', year: 2007) | ||
| p auto | ||
| auto.update(color: 'Blue', year: 2012) | ||
| puts auto.color | ||
| puts auto.year | ||
| puts auto.model | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| require 'rspec' | ||
| require '../models/eagle' | ||
|
|
||
| describe Automobile do | ||
| describe '.wheels' do | ||
| it 'should return four' do | ||
| Automobile.wheels.should eq(4) | ||
| end | ||
| end | ||
|
|
||
| let (:auto) { Automobile.new(model: 'Mustang', color: 'Red', make: 'Ford', year: 2007)} | ||
|
|
||
| describe "#new" do | ||
| it "takes four parameters and returns a Automobile object" do | ||
| auto.should be_an_instance_of Automobile | ||
| end | ||
|
|
||
| it 'should inherit from vehicle' do | ||
| auto.is_a?(Vehicle).should be_true | ||
| end | ||
| end | ||
|
|
||
| describe "#model" do | ||
| it 'should have model attribute' do | ||
| auto.should respond_to(:model) | ||
| end | ||
|
|
||
| it "returns the correct model" do | ||
| auto.model.should eql 'Mustang' | ||
| end | ||
| end | ||
|
|
||
| describe "#color" do | ||
| it 'should have color attribute' do | ||
| auto.should respond_to(:color) | ||
| end | ||
|
|
||
| it "returns the correct color" do | ||
| auto.color.should eql 'Red' | ||
| end | ||
| end | ||
|
|
||
| describe "#make" do | ||
| it 'should have make attribute' do | ||
| auto.should respond_to(:make) | ||
| end | ||
|
|
||
| it "returns the correct make" do | ||
| auto.make.should eql 'Ford' | ||
| end | ||
| end | ||
|
|
||
| describe "#year" do | ||
| it 'should have year attribute' do | ||
| auto.should respond_to(:year) | ||
| end | ||
|
|
||
| it "returns the correct year" do | ||
| auto.year.should eql 2007 | ||
| end | ||
| end | ||
|
|
||
| describe "#update" do | ||
| context "with no parameters" do | ||
| it "should keep the Automobile unchanged if no parameters are given " do | ||
| auto.update({}) | ||
| auto.model.should eql 'Mustang' | ||
| auto.color.should eql 'Red' | ||
| auto.make.should eql 'Ford' | ||
| auto.year.should eql 2007 | ||
| end | ||
| end | ||
|
|
||
| it 'should update the model attribute' do | ||
| auto.update(model: 'Calibre') | ||
| auto.model.should eql 'Calibre' | ||
| end | ||
| it 'should update the color attribute' do | ||
| auto.update(color: 'Blue') | ||
| auto.color.should eql 'Blue' | ||
| end | ||
| it 'should update the make attribute' do | ||
| auto.update(make: 'Dodge') | ||
| auto.make.should eql 'Dodge' | ||
| end | ||
| it 'should update the year attribute' do | ||
| auto.update(year: 2009) | ||
| auto.year.should eql 2009 | ||
| end | ||
|
|
||
| context "with all parameters" do | ||
| it 'should takes four parameters and changes the entire Automobile object' do | ||
| auto.update(model: 'Explorer', color: 'Silver', make: 'Ford', year: 1998) | ||
| auto.model.should eql 'Explorer' | ||
| auto.color.should eql 'Silver' | ||
| auto.make.should eql 'Ford' | ||
| auto.year.should eql 1998 | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "#build" do | ||
| it "records the auto when I build it" do | ||
| auto = Automobile.build(model: 'Mustang', color: 'Red', make: 'Ford', year: 2007) | ||
| expect(Automobile.all_autos).to include (auto) | ||
| expect(Vehicle.all_vehicles).to include (auto) | ||
| end | ||
|
|
||
| it "should increment the Vehicle count" do | ||
| expect{Automobile.build model: :honda, color: :blue, make: 'Civic', year: 2013}.to change{Vehicle.count}.from(1).to(2) | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| require 'rspec' | ||
| require '../models/eagle' | ||
|
|
||
| describe Motorcycle do | ||
| let (:bike) {Motorcycle.new} | ||
|
|
||
| describe '.wheels' do | ||
| it 'should return two' do | ||
| Motorcycle.wheels.should eq(2) | ||
| end | ||
| end | ||
|
|
||
| describe "#new" do | ||
| it "takes no parameters and returns a Motorcycle object" do | ||
| bike.should be_an_instance_of Motorcycle | ||
| end | ||
|
|
||
| it 'should inherit from vehicle' do | ||
| bike.is_a?(Vehicle).should be_true | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #Vehicle scenarios | ||
| Vehicle.wheels | ||
| 8.times { Vehicle.new } and Vehicle.count == 8 | ||
| Vehicle.search(color: "blue", model: "honda").inspect | ||
|
|
||
|
|
||
| #Automobilce scenarios | ||
| Automobile.is_a?(Automobile) | ||
| Automobile.wheels == 4 | ||
| auto = Automobile.new(model: 'Mustang', color: 'Red', make: 'Ford', year: 2007) | ||
| auto.color == 'Red' | ||
| auto.update(color: 'Blue', year: 2012) | ||
| auto.color == 'Blue' | ||
| auto.make = 'Ford' | ||
| auto.year == 2012 | ||
|
|
||
| Automobile.new model: :mazda, color: :red, make: 'Civic', year: 2012 | ||
| Automobile.new model: :toyota, color: :red, make: 'Corolla', year: 2010 | ||
| Automobile.new model: :honda, color: :blue, make: 'Civic', year: 2013 | ||
| Automobile.new model: :mazda, color: :blue, make: 'Accord', year: 2003 | ||
| Vehicle.count == 5 #=> after all the above tests have run | ||
|
|
||
| Automobile.count #=> 0 | ||
| Automobile.build(model: 'Mustang', color: 'Red', make: 'Ford', year: 2007) | ||
| Automobile.count #=> 1 | ||
|
|
||
| #Motorcycle | ||
| Motorcycle.wheels | ||
| 4.times { Motorcycle.new } and Vehicle.count == 4 | ||
| Motorcycle.is_a?(Motorcycle) | ||
|
|
||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| require 'rspec' | ||
| require '../models/eagle' | ||
|
|
||
| describe Vehicle do | ||
|
|
||
| let(:vehicle) { Vehicle.new } | ||
|
|
||
| describe '.wheels' do | ||
| it 'should return two' do | ||
| Vehicle.wheels.should eq(2) | ||
| end | ||
| end | ||
|
|
||
| describe "#new" do | ||
| it "takes no parameters and returns a Vehicle object" do | ||
| vehicle.should be_an_instance_of Vehicle | ||
| end | ||
| end | ||
|
|
||
| describe "#search" do | ||
| it "should find an Automobile when it is searched for" do | ||
| Automobile.build model: :mazda, color: :red, make: 'Civic', year: 2012 | ||
| Automobile.build model: :toyota, color: :red, make: 'Corolla', year: 2010 | ||
| auto = Automobile.build model: :honda, color: :blue, make: 'Civic', year: 2013 | ||
| Automobile.build model: :mazda, color: :blue, make: 'Accord', year: 2003 | ||
| Vehicle.search(color: "blue", model: "honda").first.should eq(auto) | ||
|
Member
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 seems like a fine search. It doesn't cover all functionality though. I might like it if it were the following, where you are more assertive about the results. Vehicle.search(color: "blue", model: "honda").should eq([auto]) |
||
| end | ||
| end | ||
|
|
||
| describe "#count" do | ||
| it "should not increment the Vehicle count no matter how many vehicles are created but not built" do | ||
| expect{8.times { Vehicle.new }}.to_not change{Vehicle.count}.from(0).to(0) | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what does
purs auto.modeloutput? Is it what you expect?