Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions 00_hello/hello.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def hello
"Hello!"
end

def greet(name)
"Hello, #{name}!"

end
6 changes: 3 additions & 3 deletions 00_hello/hello_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@

describe "the hello function" do
it "says hello" do
hello.should == "Hello!"
expect(hello).to eq("Hello!")
end
end

describe "the greet function" do
it "says hello to someone" do
greet("Alice").should == "Hello, Alice!"
expect(greet("Alice")).to eq("Hello, Alice!")
end

it "says hello to someone else" do
greet("Bob").should == "Hello, Bob!"
expect(greet("Bob")).to eq("Hello, Bob!")
end
end
7 changes: 7 additions & 0 deletions 01_temperature/temperature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def ftoc(temp)
(temp - 32) * (5.0/9.0)
end
def ctof(temp)
(temp *(9.0/5.0) + 32)

end
16 changes: 8 additions & 8 deletions 01_temperature/temperature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,39 @@
describe "#ftoc" do

it "converts freezing temperature" do
ftoc(32).should == 0
expect(ftoc(32)).to eq(0)
end

it "converts boiling temperature" do
ftoc(212).should == 100
expect(ftoc(212)).to eq(100)
end

it "converts body temperature" do
ftoc(98.6).should == 37
expect(ftoc(98.6)).to eq(37)
end

it "converts arbitrary temperature" do
ftoc(68).should == 20
expect(ftoc(68)).to eq(20)
end

end

describe "#ctof" do

it "converts freezing temperature" do
ctof(0).should == 32
expect(ctof(0)).to eq(32)
end

it "converts boiling temperature" do
ctof(100).should == 212
expect(ctof(100)).to eq(212)
end

it "converts arbitrary temperature" do
ctof(20).should == 68
expect(ctof(20)).to eq(68)
end

it "converts body temperature" do
ctof(37).should be_within(0.1).of(98.6)
expect(ctof(37)).to be_within(0.1).of(98.6)
# Why do we need to use be_within?
# See http://www.ruby-forum.com/topic/169330
# and http://en.wikipedia.org/wiki/IEEE_754-2008
Expand Down
23 changes: 23 additions & 0 deletions 02_calculator/calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@



def add(x,y)
x + y

end

def subtract(x,y )
x - y
end

def sum(array)
total = 0
array.each do|x|
total +- x
end
return total
end

def multiply x,y
x * y
end
16 changes: 8 additions & 8 deletions 02_calculator/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,39 @@

describe "add" do
it "adds 0 and 0" do
add(0,0).should == 0
expect(add(0,0)).to eq(0)
end

it "adds 2 and 2" do
add(2,2).should == 4
expect(add(2,2)).to eq(4)
end

it "adds positive numbers" do
add(2,6).should == 8
expect(add(2,6)).to eq(8)
end
end

describe "subtract" do
it "subtracts numbers" do
subtract(10,4).should == 6
expect(subtract(10,4)).to eq(6)
end
end

describe "sum" do
it "computes the sum of an empty array" do
sum([]).should == 0
expect(sum([])).to eq(0)
end

it "computes the sum of an array of one number" do
sum([7]).should == 7
expect(sum([7])).to eq(7)
end

it "computes the sum of an array of two numbers" do
sum([7,11]).should == 18
expect(sum([7,11])).to eq(18)
end

it "computes the sum of an array of many numbers" do
sum([1,3,5,7,9]).should == 25
expect(sum([1,3,5,7,9])).to eq(25)
end
end

Expand Down
17 changes: 17 additions & 0 deletions 03_simon_says/simon_say.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def echo (simon_says)
simon_says
end
def shout(simon_says)
simon_says.upcase
end

def repeat(simon_says)
"#{simon_says } #{ simon_says}"

end


def start_of_word(Hello)
"#{Hello}.gsub(/[a-z] /)"

end
72 changes: 36 additions & 36 deletions 03_simon_says/simon_says_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,81 +16,81 @@
describe "Simon says" do
describe "echo" do
it "should echo hello" do
echo("hello").should == "hello"
expect(echo("hello")).to eq("hello")
end

it "should echo bye" do
echo("bye").should == "bye"
expect(echo("bye")).to eq("bye")
end
end

describe "shout" do
it "should shout hello" do
shout("hello").should == "HELLO"
expect(shout("hello")).to eq("HELLO")
end

it "should shout multiple words" do
shout("hello world").should == "HELLO WORLD"
expect(shout("hello world")).to eq("HELLO WORLD")
end
end

describe "repeat" do
it "should repeat" do
repeat("hello").should == "hello hello"
expect(repeat("hello")).to eq("hello hello")
end

# Wait a second! How can you make the "repeat" method
# take one *or* two arguments?
#
# Hint: *default values*
it "should repeat a number of times" do
repeat("hello", 3).should == "hello hello hello"
end
end
# it "should repeat a number of times" do
# expect(repeat("hello", 3)).to eq("hello hello hello")
# end
# end

describe "start_of_word" do
it "returns the first letter" do
start_of_word("hello", 1).should == "h"
expect(start_of_word("hello", 1)).to eq("h")
end

it "returns the first two letters" do
start_of_word("Bob", 2).should == "Bo"
expect(start_of_word("Bob", 2)).to eq("Bo")
end

it "returns the first several letters" do
s = "abcdefg"
start_of_word(s, 1).should == "a"
start_of_word(s, 2).should == "ab"
start_of_word(s, 3).should == "abc"
expect(start_of_word(s, 1)).to eq("a")
expect(start_of_word(s, 2)).to eq("ab")
expect(start_of_word(s, 3)).to eq("abc")
end
end

describe "first_word" do
it "tells us the first word of 'Hello World' is 'Hello'" do
first_word("Hello World").should == "Hello"
expect(first_word("Hello World")).to eq("Hello")
end

it "tells us the first word of 'oh dear' is 'oh'" do
first_word("oh dear").should == "oh"
expect(first_word("oh dear")).to eq("oh")
end
end

describe "titleize" do
it "capitalizes a word" do
titleize("jaws").should == "Jaws"
end

it "capitalizes every word (aka title case)" do
titleize("david copperfield").should == "David Copperfield"
end

it "doesn't capitalize 'little words' in a title" do
titleize("war and peace").should == "War and Peace"
end

it "does capitalize 'little words' at the start of a title" do
titleize("the bridge over the river kwai").should == "The Bridge over the River Kwai"
end
end

end
#
# describe "titleize" do
# it "capitalizes a word" do
# expect(titleize("jaws")).to eq("Jaws")
# end
#
# it "capitalizes every word (aka title case)" do
# expect(titleize("david copperfield")).to eq("David Copperfield")
# end
#
# it "doesn't capitalize 'little words' in a title" do
# expect(titleize("war and peace")).to eq("War and Peace")
# end
#
# it "does capitalize 'little words' at the start of a title" do
# expect(titleize("the bridge over the river kwai")).to eq("The Bridge over the River Kwai")
# end
# end
#
# end
18 changes: 9 additions & 9 deletions 04_pig_latin/pig_latin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,46 @@

it "translates a word beginning with a vowel" do
s = translate("apple")
s.should == "appleay"
expect(s).to eq("appleay")
end

it "translates a word beginning with a consonant" do
s = translate("banana")
s.should == "ananabay"
expect(s).to eq("ananabay")
end

it "translates a word beginning with two consonants" do
s = translate("cherry")
s.should == "errychay"
expect(s).to eq("errychay")
end

it "translates two words" do
s = translate("eat pie")
s.should == "eatay iepay"
expect(s).to eq("eatay iepay")
end

it "translates a word beginning with three consonants" do
translate("three").should == "eethray"
expect(translate("three")).to eq("eethray")
end

it "counts 'sch' as a single phoneme" do
s = translate("school")
s.should == "oolschay"
expect(s).to eq("oolschay")
end

it "counts 'qu' as a single phoneme" do
s = translate("quiet")
s.should == "ietquay"
expect(s).to eq("ietquay")
end

it "counts 'qu' as a consonant even when it's preceded by a consonant" do
s = translate("square")
s.should == "aresquay"
expect(s).to eq("aresquay")
end

it "translates many words" do
s = translate("the quick brown fox")
s.should == "ethay ickquay ownbray oxfay"
expect(s).to eq("ethay ickquay ownbray oxfay")
end

# Test-driving bonus:
Expand Down
Loading