Skip to content

Instantly share code, notes, and snippets.

@reneedv
Created June 11, 2012 19:22
Show Gist options
  • Save reneedv/2912109 to your computer and use it in GitHub Desktop.
Save reneedv/2912109 to your computer and use it in GitHub Desktop.
Wine Glass Homework 1
# Make the existing tests pass.
# Add 2 more tests and methods for:
## 1. Another print method for material, volume, and stem_length all together
## 2. A method that calculates and returns the percent of the glass that is full when you pass in the
### volume of liquid in the glass.
### This calculation is: (volume_passed_to_method / volume_of_wine_glass) * 100
class WineGlass
attr_accessor :material, :volume, :stem_length
def pretty_print_material
"Happy Dance Party : #{self.material}"
end
end
require 'minitest/autorun'
class TestWineGlass < MiniTest::Unit::TestCase
def setup
@wg = WineGlass.new
@wg.material = 'wood'
@wg.volume = 650
@wg.stem_length = 5
end
def test_that_wine_glasses_have_volume
assert_respond_to @wg, :volume
end
def test_that_wg_has_a_pretty_print_for_material
assert_equal "Material : #{@wg.material}", @wg.pretty_print_material
end
def test_wg_pretty_prints_stem_length_and_volume
assert_equal "This wine glass is cool. It has a stem length of 5 and a volume of 650ml", @wg.pretty_print_stuff
end
end
@betsy-nird
Copy link

Make the existing tests pass.

Add 2 more tests and methods for:

1. Another print method for material, volume, and stem_length all together

2. A method that calculates and returns the percent of the glass that is full when you pass in the

volume of liquid in the glass.

This calculation is: (volume_passed_to_method / volume_of_wine_glass) * 100

class WineGlass
attr_accessor :material, :volume, :stem_length, :volume_of_wine
def pretty_print_material
"Material : #{self.material}"
end

def pretty_print_stuff 
    "This wine glass is cool. It has a stem length of #{self.stem_length} and a volume of #{self.volume}ml" 
end

def pretty_print_all
    "This is a #{self.material} wine glass with a stem length of #{self.stem_length} and a volume of #{self.volume}ml"
end

def pretty_print_wine_remaining
    "Amount of wine remaining : #{(self.volume_of_wine.to_f / self.volume.to_f * 100).to_i}%"
end

end

require 'minitest/autorun'

class TestWineGlass < MiniTest::Unit::TestCase

def setup
    @wg = WineGlass.new
            @wg.material = 'wood'
            @wg.volume = 650
            @wg.stem_length = 5
            @wg.volume_of_wine = 300
end

def test_that_wine_glasses_have_volume
    assert_respond_to @wg, :volume
end

def test_that_wg_has_a_pretty_print_for_material
    assert_equal "Material : #{@wg.material}", @wg.pretty_print_material
end

def test_wg_pretty_prints_stem_length_and_volume
    assert_equal "This wine glass is cool. It has a stem length of 5 and a volume of 650ml", @wg.pretty_print_stuff
end

def test_that_wg_has_a_pretty_print_method_for_material_volume_and_stem_length
    assert_equal "This is a wood wine glass with a stem length of 5 and a volume of 650ml", @wg.pretty_print_all 
end

def test_how_much_wine_is_left_in_the_glass
    assert_equal "Amount of wine remaining : #{(@wg.volume_of_wine.to_f / @wg.volume.to_f * 100).to_i}%", @wg.pretty_print_wine_remaining
end

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment