forked from AdaGold/array-string-practice
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathpractice_exercises_test.rb
43 lines (31 loc) · 1.1 KB
/
practice_exercises_test.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
require_relative "test_helper"
describe "Practice Exercises" do
describe "remove duplicates" do
it "works for 1 element strings" do
expect(remove_duplicates([1])).must_equal [1]
end
it "works for empty arrays" do
expect(remove_duplicates([])).must_equal []
end
it "will remove duplicates for longer arrays" do
expect(remove_duplicates([1, 2, 2, 3, 3, 4]).reject{|num| num == nil }).must_equal [1, 2, 3, 4]
end
end
describe "Longest valid substring" do
it "will work for the README strings" do
strings = ["flower","flow","flight"]
output = longest_prefix(strings)
expect(output).must_equal "fl"
end
it "will work for the strings with the common prefix in the rear" do
strings = ["flower","flow","flight", "fpastafl"]
output = longest_prefix(strings)
expect(output).must_equal "f"
end
it "will work for the README strings" do
strings = ["dog","racecar","car"]
output = longest_prefix(strings)
expect(output).must_equal ""
end
end
end