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
1 change: 1 addition & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--- {}
6 changes: 6 additions & 0 deletions .replit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


run="git status \n git checkout -b adding-unit-tests \n git add . \n git commit -m 'adding some unit tests' \n git push origin adding-unit-tests"



2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
9 changes: 9 additions & 0 deletions 00_hello/hello.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#write your code here
def hello
return "Hello!"
end


def greet(who)
return "Hello, #{who}!"
end
18 changes: 2 additions & 16 deletions 00_hello/hello_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,15 @@
#
# cd 00_hello
#
# This directory is the starting point for this exercise. It contains a spec file and you'll be adding a ruby file to (eventually) make the specs pass.
# This directory is the starting point for this exercise. It contains a spec file and a ruby file to (eventually) make the specs pass.
#
# ## Run the test
#
# rake
#
# ## Watch it fail
#
# You should see an error. **Don't get scared!** Try to read it and figure out what the computer wants to tell you. Somewhere on the first line it should say something like
#
# cannot load such file -- test-first-teaching/hello/hello (LoadError)
#
# That means that it is looking for a file called `hello.rb` and can't find it.
#
# ## Create hello.rb
#
# Open up `hello.rb` in a text editor. Save it. Run the test again.
#
# rake
#
# ## Watch it fail
#
# Now you should see an error like this:
# you should see an error like this:
#
# the hello function
# says hello (FAILED - 1)
Expand Down
33 changes: 4 additions & 29 deletions 00_hello/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ <h2><a href="../index.html">learn_ruby</a></h2>
<li><a href="../02_calculator/index.html">02 Calculator</a></li>
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li>
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li>
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li>
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li>
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li>
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li>
<li><a href="../09_timer/index.html">09 Timer</a></li>
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li>
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li>
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li>
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li>
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li>
<li><a href="../15_in_words/index.html">15 In Words</a></li>
<li><a href="../05_book_titles/index.html">05 Book Titles</a></li>
<li><a href="../06_timer/index.html">06 Timer</a></li>
</ul>
</div>
<h1>hello</h1>
Expand All @@ -40,7 +31,7 @@ <h2>Open a terminal in this directory</h2>
<pre><code>cd 00_hello
</code></pre>

<p>This directory is the starting point for this exercise. It contains a spec file and you'll be adding a ruby file to (eventually) make the specs pass.</p>
<p>This directory is the starting point for this exercise. It contains a spec file and a ruby file to (eventually) make the specs pass.</p>

<h2>Run the test</h2>

Expand All @@ -49,23 +40,7 @@ <h2>Run the test</h2>

<h2>Watch it fail</h2>

<p>You should see an error. <strong>Don't get scared!</strong> Try to read it and figure out what the computer wants to tell you. Somewhere on the first line it should say something like</p>

<pre><code>cannot load such file -- test-first-teaching/hello/hello (LoadError)
</code></pre>

<p>That means that it is looking for a file called <code>hello.rb</code> and can't find it.</p>

<h2>Create hello.rb</h2>

<p>Open up <code>hello.rb</code> in a text editor. Save it. Run the test again.</p>

<pre><code>rake
</code></pre>

<h2>Watch it fail</h2>

<p>Now you should see an error like this:</p>
<p>you should see an error like this:</p>

<pre><code>the hello function
says hello (FAILED - 1)
Expand Down
13 changes: 2 additions & 11 deletions 01_temperature/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ <h2><a href="../index.html">learn_ruby</a></h2>
<li><a href="../02_calculator/index.html">02 Calculator</a></li>
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li>
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li>
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li>
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li>
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li>
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li>
<li><a href="../09_timer/index.html">09 Timer</a></li>
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li>
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li>
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li>
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li>
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li>
<li><a href="../15_in_words/index.html">15 In Words</a></li>
<li><a href="../05_book_titles/index.html">05 Book Titles</a></li>
<li><a href="../06_timer/index.html">06 Timer</a></li>
</ul>
</div>
<h1>temperature</h1>
Expand Down
8 changes: 8 additions & 0 deletions 01_temperature/temperature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def ftoc (temp)

return ((temp - 32) * 5/9).to_f
end

def ctof (temp)
return (temp.to_f * 9/5 + 32.0)
end
6 changes: 0 additions & 6 deletions 01_temperature/temperature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
require "temperature"

describe "temperature conversion functions" do

describe "#ftoc" do

it "converts freezing temperature" do
expect(ftoc(32)).to eq(0)
end
Expand All @@ -36,11 +34,9 @@
it "converts arbitrary temperature" do
expect(ftoc(68)).to eq(20)
end

end

describe "#ctof" do

it "converts freezing temperature" do
expect(ctof(0)).to eq(32)
end
Expand All @@ -61,7 +57,5 @@
# and http://en.wikipedia.org/wiki/Double_precision_floating-point_format
# Also, try "puts 0.5 - 0.4 - 0.1" -- pretty crazy, right?
end

end

end
39 changes: 39 additions & 0 deletions 02_calculator/calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
def add (num1, num2)
return num1 + num2
end

def subtract (num1, num2)
return num1 - num2
end

def sum (arr)
total = 0
arr.each do | item |
total += item
end
return total
end

def multiply(arr)
product = 1
arr.each do |item|
product *= item
end
return product
end

def power(num1, num2)
return num1 ** num2
end

def factorial (num)
fact = 1


while num > 0
fact *= num
num -= 1
end

return fact
end
49 changes: 32 additions & 17 deletions 02_calculator/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#
# you will build a simple calculator script with the following methods:
#
# `add` takes two parameters and adds them
# `add` takes two parameters and adds them I
#
# `subtract` takes two parameters and subtracts the second from the first
#
Expand Down Expand Up @@ -37,21 +37,21 @@

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

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

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

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

Expand All @@ -65,11 +65,11 @@
end

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

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

Expand All @@ -78,22 +78,37 @@
# write tests and code for the following:

describe "#multiply" do
it "multiplies two numbers" do
expect(multiply([2, 3])).to eq(6)
end

it "multiplies two numbers"

it "multiplies several numbers"

it "multiplies several numbers" do expect(multiply([5, 3, 4, 2, 1])).to eq(120) end
end

describe "#power" do
it "raises one number to the power of another number"
it "raises one number to the power of another number" do
expect(power(3, 2)).to eq(9)
end
end

# http://en.wikipedia.org/wiki/Factorial
describe "#factorial" do
it "computes the factorial of 0"
it "computes the factorial of 1"
it "computes the factorial of 2"
it "computes the factorial of 5"
it "computes the factorial of 10"
it "computes the factorial of 0" do
expect(factorial(0)).to eq(1)
end

it "computes the factorial of 1" do
expect(factorial(1)) .to eq(1)
end

it "computes the factorial of 2" do
expect(factorial(2)) .to eq(2)
end
it "computes the factorial of 5" do
expect(factorial(5))
.to eq(120)
end
it "computes the factorial of 10" do
expect(factorial(10)) .to eq(3628800)
end
end
13 changes: 2 additions & 11 deletions 02_calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ <h2><a href="../index.html">learn_ruby</a></h2>
<li>02 Calculator</li>
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li>
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li>
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li>
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li>
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li>
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li>
<li><a href="../09_timer/index.html">09 Timer</a></li>
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li>
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li>
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li>
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li>
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li>
<li><a href="../15_in_words/index.html">15 In Words</a></li>
<li><a href="../05_book_titles/index.html">05 Book Titles</a></li>
<li><a href="../06_timer/index.html">06 Timer</a></li>
</ul>
</div>
<h1>calculator</h1>
Expand Down
13 changes: 2 additions & 11 deletions 03_simon_says/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ <h2><a href="../index.html">learn_ruby</a></h2>
<li><a href="../02_calculator/index.html">02 Calculator</a></li>
<li>03 Simon Says</li>
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li>
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li>
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li>
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li>
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li>
<li><a href="../09_timer/index.html">09 Timer</a></li>
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li>
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li>
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li>
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li>
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li>
<li><a href="../15_in_words/index.html">15 In Words</a></li>
<li><a href="../05_book_titles/index.html">05 Book Titles</a></li>
<li><a href="../06_timer/index.html">06 Timer</a></li>
</ul>
</div>
<h1>simon_says</h1>
Expand Down
1 change: 1 addition & 0 deletions 03_simon_says/simon_says.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#write your code here
13 changes: 2 additions & 11 deletions 04_pig_latin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ <h2><a href="../index.html">learn_ruby</a></h2>
<li><a href="../02_calculator/index.html">02 Calculator</a></li>
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li>
<li>04 Pig Latin</li>
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li>
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li>
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li>
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li>
<li><a href="../09_timer/index.html">09 Timer</a></li>
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li>
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li>
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li>
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li>
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li>
<li><a href="../15_in_words/index.html">15 In Words</a></li>
<li><a href="../05_book_titles/index.html">05 Book Titles</a></li>
<li><a href="../06_timer/index.html">06 Timer</a></li>
</ul>
</div>
<h1>pig_latin</h1>
Expand Down
1 change: 1 addition & 0 deletions 04_pig_latin/pig_latin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#write your code here
3 changes: 3 additions & 0 deletions 05_book_titles/book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Book
# write your code here
end
File renamed without changes.
13 changes: 2 additions & 11 deletions 08_book_titles/index.html → 05_book_titles/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ <h2><a href="../index.html">learn_ruby</a></h2>
<li><a href="../02_calculator/index.html">02 Calculator</a></li>
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li>
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li>
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li>
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li>
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li>
<li>08 Book Titles</li>
<li><a href="../09_timer/index.html">09 Timer</a></li>
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li>
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li>
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li>
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li>
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li>
<li><a href="../15_in_words/index.html">15 In Words</a></li>
<li>05 Book Titles</li>
<li><a href="../06_timer/index.html">06 Timer</a></li>
</ul>
</div>
<h1>book_titles</h1>
Expand Down
Loading