forked from kanwei/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuffix_array_spec.rb
40 lines (35 loc) · 1.39 KB
/
suffix_array_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
$: << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
require 'algorithms'
describe "empty suffix array" do
it "should not initialize with empty string" do
lambda { Containers::SuffixArray.new("") }.should raise_error
end
end
describe "non-empty suffix array" do
before(:each) do
@s_array = Containers::SuffixArray.new("abracadabra")
end
it "should has_substring? each possible substring" do
@s_array.has_substring?("a").should be_true
@s_array.has_substring?("abra").should be_true
@s_array.has_substring?("abracadabra").should be_true
@s_array.has_substring?("acadabra").should be_true
@s_array.has_substring?("adabra").should be_true
@s_array.has_substring?("bra").should be_true
@s_array.has_substring?("bracadabra").should be_true
@s_array.has_substring?("cadabra").should be_true
@s_array.has_substring?("dabra").should be_true
@s_array.has_substring?("ra").should be_true
@s_array.has_substring?("racadabra").should be_true
end
it "should not has_substring? substrings it does not have" do
@s_array.has_substring?("nope").should be_false
@s_array.has_substring?(nil).should be_false
end
it "should work with numbers (calls to_s)" do
number = Containers::SuffixArray.new(123456789)
number[1].should be_true
number.has_substring?(12).should be_true
number.has_substring?(13).should be_false
end
end