-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e5df5a
commit 86602c3
Showing
20 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,9 @@ | ||
def check_codeword(codeword) | ||
if codeword == "horse" | ||
return "Correct! Come in." | ||
elsif codeword.chars.first == "h" && codeword.chars.last == "e" | ||
return "Close, but nope." | ||
else | ||
return "WRONG!" | ||
end | ||
end |
This file contains 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,13 @@ | ||
class Counter | ||
def initialize | ||
@count = 0 | ||
end | ||
|
||
def add(num) | ||
@count += num | ||
end | ||
|
||
def report | ||
return "Counted to #{@count} so far." | ||
end | ||
end |
This file contains 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 Gratitudes | ||
def initialize | ||
@gratitudes = [] | ||
end | ||
|
||
def add(gratitude) | ||
@gratitudes.push(gratitude) | ||
end | ||
|
||
def format | ||
formatted = "Be grateful for: " | ||
formatted += @gratitudes.join(", ") | ||
end | ||
end | ||
|
This file contains 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,5 @@ | ||
def greet(name) | ||
return "Hello, #{name}!" | ||
end | ||
|
||
|
This file contains 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,9 @@ | ||
class PasswordChecker | ||
def check(password) | ||
if password.length >= 8 | ||
return true | ||
else | ||
fail "Invalid password, must be 8+ characters." | ||
end | ||
end | ||
end |
This file contains 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,21 @@ | ||
class Present | ||
def wrap(contents) | ||
fail "A contents has already been wrapped." unless @contents.nil? | ||
@contents = contents | ||
end | ||
|
||
def unwrap | ||
fail "No contents have been wrapped." if @contents.nil? | ||
return @contents | ||
end | ||
end | ||
|
||
# require 'reminder' | ||
# RSpec.describe Reminder do | ||
# context "when no task is set" do | ||
# it "fails" do | ||
# reminder = Reminder.new("Kay") | ||
# expect { reminder.remind() }.to raise_error "No reminder set!" | ||
# end | ||
# end | ||
# end |
This file contains 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,13 @@ | ||
class Reminder | ||
def initialize(name) | ||
@name = name | ||
end | ||
|
||
def remind_me_to(task) | ||
@task = task | ||
end | ||
|
||
def remind() | ||
return "#{@task}, #{@name}!" | ||
end | ||
end |
This file contains 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,4 @@ | ||
def report_length(str) | ||
length = str.length | ||
return "This string was #{length} characters long." | ||
end |
This file contains 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,17 @@ | ||
class StringBuilder | ||
def initialize | ||
@str = "" | ||
end | ||
|
||
def add(str) | ||
@str += str | ||
end | ||
|
||
def size | ||
return @str.length | ||
end | ||
|
||
def output | ||
return @str | ||
end | ||
end |
This file contains 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,19 @@ | ||
require "check_codeword" | ||
|
||
RSpec.describe "check_codeword method" do | ||
it "takes 'horse' and returns 'Correct! Come in.'" do | ||
result = check_codeword("horse") | ||
expect(result).to eq "Correct! Come in." | ||
end | ||
|
||
it "takes codeword.chars.first == 'h' && codeword.chars.last == 'e' | ||
and returns 'Close, but nope.'" do | ||
result = check_codeword("home") | ||
expect(result).to eq "Close, but nope." | ||
end | ||
|
||
it "takes the incorrect input and returns 'WRONG!'" do | ||
result = check_codeword("chair") | ||
expect(result).to eq "WRONG!" | ||
end | ||
end |
This file contains 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,11 @@ | ||
require "counter" | ||
|
||
RSpec.describe Counter do | ||
it "add the num to the count variable" do | ||
counter = Counter.new | ||
counter.add(5) | ||
result = counter.report | ||
expect(result).to eq "Counted to 5 so far." | ||
end | ||
|
||
end |
This file contains 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,11 @@ | ||
require "gratitudes" | ||
|
||
RSpec.describe Gratitudes do | ||
it "takes the input gratitude and it pushes to the array. It also formates it" do | ||
gratitudes = Gratitudes.new | ||
gratitudes.add("thank you") | ||
result = gratitudes.format | ||
expect(result).to eq "Be grateful for: thank you" | ||
end | ||
|
||
end |
This file contains 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,8 @@ | ||
require "greet" | ||
|
||
RSpec.describe "greet method" do | ||
it "takes the input and returns Hello, Nagore" do | ||
result = greet("Nagore") | ||
expect(result).to eq "Hello, Nagore!" | ||
end | ||
end |
This file contains 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,14 @@ | ||
require "password_checker" | ||
|
||
RSpec.describe PasswordChecker do | ||
it "sees the password and returns true if it has 8+ characters." do | ||
password_checker = PasswordChecker.new | ||
result = password_checker.check("carrotss") | ||
expect(result).to eq true | ||
end | ||
|
||
it "fails if the password has less that 8 chars" do | ||
password_checker = PasswordChecker.new | ||
expect{ password_checker.check("cat") }.to raise_error "Invalid password, must be 8+ characters." | ||
end | ||
end |
This file contains 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,21 @@ | ||
require "present" | ||
|
||
RSpec.describe Present do | ||
|
||
it "wraps and unwraps a value" do | ||
present = Present.new | ||
present.wrap(10) | ||
expect(present.unwrap).to eq 10 | ||
end | ||
|
||
it "fails if we unwrap without wrapping first" do | ||
present = Present.new | ||
expect { present.unwrap }.to raise_error "No contents have been wrapped." | ||
end | ||
|
||
it "fails if we wrap if we've already wrapped" do | ||
present = Present.new | ||
present.wrap(10) | ||
expect { present.wrap (11) }.to raise_error "A contents has already been wrapped." | ||
end | ||
end |
Empty file.
This file contains 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,13 @@ | ||
require 'reminder' | ||
|
||
# We use the class name here rather than a string | ||
RSpec.describe Reminder do | ||
it "reminds the user to do a task" do | ||
reminder = Reminder.new("Kay") | ||
reminder.remind_me_to("Walk the dog") | ||
result = reminder.remind() | ||
expect(result).to eq "Walk the dog, Kay!" | ||
end | ||
|
||
# We would typically have a number of these examples. | ||
end |
This file contains 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,9 @@ | ||
require "report_length" | ||
|
||
RSpec.describe "report_length method" do | ||
|
||
it "given string 'hello' returns 'This string was 5 characters long.'" do | ||
result = report_length("hello") | ||
expect(result). to eq "This string was 5 characters long." | ||
end | ||
end |
This file contains 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,11 @@ | ||
require "string_builder" | ||
|
||
RSpec.describe StringBuilder do | ||
it "takes the input, add it to the string and it counts the string characters" do | ||
string_builder = StringBuilder.new | ||
string_builder.add("Hello") | ||
string_builder.size | ||
result = string_builder.output | ||
expect(result).to eq "Hello" | ||
end | ||
end |