-
Notifications
You must be signed in to change notification settings - Fork 71
initial commit #56
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
robert-smith-07
wants to merge
1
commit into
paircolumbus:master
Choose a base branch
from
robert-smith-07: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
initial commit #56
Changes from all commits
Commits
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
Empty file.
Empty file.
Empty file.
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 |
|---|---|---|
| @@ -1,38 +1,62 @@ | ||
| class NoApplesError < StandardError; end | ||
|
|
||
| class AppleTree | ||
| attr_#fill_in :height, :age, :apples, :alive | ||
| class Tree | ||
| attr_reader :height, :age, :apples, :alive | ||
|
|
||
| def initialize | ||
| @height = 0 | ||
| @age = 0 | ||
| @apples = [] | ||
| @alive = true | ||
| end | ||
|
|
||
| def age! | ||
| @age += 1 | ||
| @height += 1 | ||
| self.add_apples | ||
| if @age == 16 | ||
| @alive = false | ||
| end | ||
| end | ||
|
|
||
| def add_apples | ||
| $i = 0 | ||
|
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. You may have intended to use a local variable here, but that |
||
| $num = rand(0...6) | ||
| possibleColors = ['red', 'green', 'yellow', 'dark red'] | ||
| until $i > $num | ||
| @apples.push Apple.new(possibleColors[rand(0...3)], rand(1...4)) | ||
| $i += 1 | ||
| end | ||
| end | ||
|
|
||
| def any_apples? | ||
| @apples.count > 1 | ||
| end | ||
|
|
||
| def pick_an_apple! | ||
| raise NoApplesError, "This tree has no apples" unless self.any_apples? | ||
| @apples.pop | ||
| end | ||
|
|
||
| def dead? | ||
| !@alive | ||
| end | ||
| end | ||
|
|
||
| class Fruit | ||
| attr_reader :has_seeds | ||
| def initialize | ||
| has_seeds = true | ||
| @has_seeds = true | ||
| end | ||
| end | ||
|
|
||
| class Apple < | ||
| attr_reader #what should go here | ||
| class Apple < Fruit | ||
| attr_reader :color, :diameter | ||
|
|
||
| def initialize(color, diameter) | ||
| @color = color | ||
| @diameter = diameter | ||
| super() | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -61,7 +85,7 @@ def tree_data | |
| diameter_sum += apple.diameter | ||
| end | ||
|
|
||
| avg_diameter = # It's up to you to calculate the average diameter for this harvest. | ||
| avg_diameter = diameter_sum / basket.count | ||
|
|
||
| puts "Year #{tree.age} Report" | ||
| puts "Tree height: #{tree.height} feet" | ||
|
|
||
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 |
|---|---|---|
| @@ -1,14 +1,78 @@ | ||
| require 'rspec' | ||
| require 'tree' | ||
|
|
||
| describe 'Tree' do | ||
| describe Tree do | ||
| it 'should be a Class' do | ||
| expect(described_class.is_a? 'Class').to be_true | ||
| expect(described_class.is_a? Class).to eq true | ||
| end | ||
|
|
||
| it 'should add apples' do | ||
| appleTree = Tree.new | ||
| appleTree.add_apples | ||
| expect(appleTree.apples.count()).to be > 0 | ||
| end | ||
|
|
||
| it 'should pick an apple' do | ||
| appleTree = Tree.new | ||
| appleTree.add_apples | ||
| startingApples = appleTree.apples.count() | ||
| appleTree.pick_an_apple! | ||
| endingApples = appleTree.apples.count() | ||
| expect(startingApples).to be > endingApples | ||
| end | ||
|
|
||
| it 'should age' do | ||
| appleTree = Tree.new | ||
| appleTree.age! | ||
| expect(appleTree.age).to eq 1 | ||
| expect(appleTree.height).to eq 1 | ||
| expect(appleTree.apples.count()).to be > 0 | ||
| end | ||
|
|
||
| it 'should reveal alive status' do | ||
| appleTree = Tree.new | ||
| appleTree.age! | ||
| expect(appleTree.dead?).to eq false | ||
| end | ||
|
|
||
| it 'should reveal dead status' do | ||
| appleTree = Tree.new | ||
| 16.times { appleTree.age! } | ||
| expect(appleTree.dead?).to eq true | ||
| end | ||
|
|
||
| end | ||
|
|
||
| describe 'Fruit' do | ||
| describe Fruit do | ||
| it 'should be a Class' do | ||
| expect(described_class.is_a? Class).to eq true | ||
| end | ||
|
|
||
| it 'should have seeds' do | ||
| aFruit = Fruit.new | ||
| expect(aFruit.has_seeds).to eq true | ||
| end | ||
| end | ||
|
|
||
| describe 'Apple' do | ||
| describe Apple do | ||
| it 'should be a Class' do | ||
| expect(described_class.is_a? Class).to eq true | ||
| end | ||
|
|
||
| it 'should have seeds' do | ||
| apple = Apple.new("red", 3) | ||
| expect(apple.has_seeds).to eq true | ||
| end | ||
|
|
||
| it 'should have a color' do | ||
| apple = Apple.new("red", 3) | ||
| expect(apple.color).to be_a_kind_of(String) | ||
| expect(apple.color).to eq "red" | ||
| end | ||
|
|
||
| it 'should have a diameter' do | ||
| apple = Apple.new("green", 2) | ||
| expect(apple.diameter).to be_a_kind_of(Numeric) | ||
| expect(apple.diameter).to eq 2 | ||
| 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.
The
attr_readerat the top exposes@age, etc. by calling methodsage.This line is both reading and assigning age if you used
attr_accessor, to define the setter methods too, this line could beage += 1.I prefer depending on the methods as much as possible. Ruby will gladly return
nilfor a typoed instance variable, but raises an error for a typoed method name.