Created
April 20, 2018 17:05
-
-
Save rodloboz/d62879baaf5e61367411fac2af5b351e to your computer and use it in GitHub Desktop.
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
# #frequencies method | |
# should return and empty hash when passed an empty string | |
# should count words | |
# should count multiple words | |
# should be case insensitive | |
# should ignore short words and punctuation (. ! ? ,) | |
# #read_file method | |
# should read the dummy file | |
require_relative '../frequencies.rb' | |
describe "#frequencies" do | |
it "should return and empty hash when passed an empty string" do | |
result = frequencies("") | |
expect(result).to eq({}) | |
end | |
it "should count words" do | |
result = frequencies("wagon wagon wagon") | |
expect(result["wagon"]).to eq(3) | |
end | |
it "should count multiple words" do | |
result = frequencies("the lazy dog jumped over the brown fox") | |
expect(result["the"]).to eq(2) | |
expect(result["dog"]).to eq(1) | |
expect(result["cat"]).to eq(0) | |
end | |
it "should be case insensitive" do | |
result = frequencies("wagon WAGON wagon") | |
expect(result["wagon"]).to eq(3) | |
end | |
it "should ignore short words" do | |
result = frequencies("a") | |
expect(result).to eq({}) | |
end | |
it "should ignore punctuation" do | |
result = frequencies("wagon! wagon? wagon. wagon,") | |
expect(result["wagon"]).to eq(4) | |
end | |
end | |
describe "#read_file" do | |
it "should read the dummy file" do | |
text = read_file("dummy.txt") | |
expect(text).to eq("the lazy dog jumped over the brown fox") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment