forked from AdaGold/reverse-words
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathreverse_words_spec.rb
69 lines (49 loc) · 1.67 KB
/
reverse_words_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'minitest/autorun'
require 'minitest/reporters'
require_relative '../lib/reverse_words'
require 'pry'
describe "reverse words" do
describe "basic tests" do
it "reverse each word in a sentence with one word" do
test_string = "Engineer"
reverse_words(test_string)
test_string.must_equal "reenignE"
end
it "reverse each word in a sentence with two words" do
test_string = "hello, world"
reverse_words(test_string)
# binding.pry
test_string.must_equal ",olleh dlrow"
end
end
# check for edge cases
describe "edge cases" do
# if it's a string parameter, check for empty
it "reverse each word in an empty sentence" do
test_string = ""
reverse_words(test_string)
test_string.must_be_empty
end
# if the parameter is an object, check for nil
it "nil object passed to reverse words" do
test_string = nil
reverse_words(test_string)
test_string.must_be_nil
end
it "reverse each single character word in a sentence with multiple words" do
test_string = "a b c d e f g h ? 1 2 4"
reverse_words(test_string)
test_string.must_equal "a b c d e f g h ? 1 2 4"
end
it "reverse each word in a sentence with multiple words of varying lengths" do
test_string = "I strive to engineer the most efficient solutions."
reverse_words(test_string)
test_string.must_equal "I evirts ot reenigne eht tsom tneiciffe .snoitulos"
end
it "reverse words in a sentence with preceeding and trailing white spaces" do
test_string = " evol "
reverse_words(test_string)
test_string.must_equal " love "
end
end
end