algorithms 0.6.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/sort_spec.rb CHANGED
@@ -4,17 +4,18 @@ include Algorithms
4
4
 
5
5
  describe "sort algorithms" do
6
6
  before(:each) do
7
- @sorts = %w(bubble_sort comb_sort selection_sort heapsort insertion_sort shell_sort quicksort mergesort)
7
+ @sorts = %w(bubble_sort comb_sort selection_sort heapsort insertion_sort
8
+ shell_sort quicksort mergesort dualpivotquicksort)
8
9
  end
9
10
 
10
11
  it "should work for empty containers" do
11
12
  empty_array = []
12
- @sorts.each { |sort| Sort.send(sort, empty_array).should eql([]) }
13
+ @sorts.each { |sort| expect(Sort.send(sort, empty_array)).to eql([]) }
13
14
  end
14
15
 
15
16
  it "should work for a container of size 1" do
16
17
  one_array = [1]
17
- @sorts.each { |sort| Sort.send(sort, one_array).should eql(one_array) }
18
+ @sorts.each { |sort| expect(Sort.send(sort, one_array)).to eql([1]) }
18
19
  end
19
20
 
20
21
  it "should work for random arrays of numbers" do
@@ -22,7 +23,7 @@ describe "sort algorithms" do
22
23
  rand_array = Array.new(n) { rand(n) }
23
24
  sorted_array = rand_array.sort
24
25
 
25
- @sorts.each { |sort| Sort.send(sort, rand_array.dup).should eql(sorted_array) }
26
+ @sorts.each { |sort| expect(Sort.send(sort, rand_array.dup)).to eql(sorted_array) }
26
27
  end
27
28
 
28
- end
29
+ end
@@ -4,24 +4,24 @@ require 'algorithms'
4
4
  shared_examples "empty splaytree" do
5
5
  it "should let you push stuff in" do
6
6
  100.times { |x| @tree[x] = x }
7
- @tree.size.should eql(100)
7
+ expect(@tree.size).to eql(100)
8
8
  end
9
9
 
10
10
  it "should return 0 for size" do
11
- @tree.size.should eql(0)
11
+ expect(@tree.size).to eql(0)
12
12
  end
13
13
 
14
14
  it "should return nil for #min and #max" do
15
- @tree.min.should be_nil
16
- @tree.max.should be_nil
15
+ expect(@tree.min).to be_nil
16
+ expect(@tree.max).to be_nil
17
17
  end
18
18
 
19
19
  it "should return nil for #delete" do
20
- @tree.delete(:non_existing).should be_nil
20
+ expect(@tree.delete(:non_existing)).to be_nil
21
21
  end
22
22
 
23
23
  it "should return nil for #get" do
24
- @tree[4235].should be_nil
24
+ expect(@tree[4235]).to be_nil
25
25
  end
26
26
  end
27
27
 
@@ -34,40 +34,40 @@ shared_examples "non-empty splaytree" do
34
34
  end
35
35
 
36
36
  it "should return correct size (uniqify items first)" do
37
- @tree.size.should eql(@random_array.uniq.size)
37
+ expect(@tree.size).to eql(@random_array.uniq.size)
38
38
  end
39
39
 
40
40
  it "should have correct height (worst case is when items are inserted in order, and height = num items inserted)" do
41
41
  @tree.clear
42
42
  10.times { |x| @tree[x] = x }
43
- @tree.height.should eql(10)
43
+ expect(@tree.height).to eql(10)
44
44
  end
45
45
 
46
46
  it "should return correct max and min keys" do
47
- @tree.min[0].should eql(@random_array.min)
48
- @tree.max[0].should eql(@random_array.max)
47
+ expect(@tree.min[0]).to eql(@random_array.min)
48
+ expect(@tree.max[0]).to eql(@random_array.max)
49
49
  end
50
50
 
51
51
  it "should not #has_key? keys it doesn't have" do
52
- @tree.has_key?(10000).should be_false
52
+ expect(@tree.has_key?(10000)).to be false
53
53
  end
54
54
 
55
55
  it "should #has_key? keys it does have" do
56
- @tree.has_key?(@random_array[0]).should be_true
56
+ expect(@tree.has_key?(@random_array[0])).to be true
57
57
  end
58
58
 
59
59
  it "should remove any key" do
60
60
  random_key = @random_array[rand(@num_items)]
61
- @tree.has_key?(random_key).should be_true
62
- @tree.delete(random_key).should eql(random_key)
63
- @tree.has_key?(random_key).should be_false
61
+ expect(@tree.has_key?(random_key)).to be true
62
+ expect(@tree.delete(random_key)).to eql(random_key)
63
+ expect(@tree.has_key?(random_key)).to be false
64
64
  end
65
65
 
66
66
  it "should let you iterate with #each" do
67
67
  counter = 0
68
68
  sorted_array = @random_array.uniq.sort
69
69
  @tree.each do |key, val|
70
- key.should eql(sorted_array[counter])
70
+ expect(key).to eql(sorted_array[counter])
71
71
  counter += 1
72
72
  end
73
73
  end
data/spec/stack_spec.rb CHANGED
@@ -7,20 +7,20 @@ describe "empty stack" do
7
7
  end
8
8
 
9
9
  it "should return nil when sent #pop" do
10
- @stack.pop.should be_nil
10
+ expect(@stack.pop).to be_nil
11
11
  end
12
12
 
13
13
  it "should return a size of 1 when sent #push" do
14
14
  @stack.push(1)
15
- @stack.size.should eql(1)
15
+ expect(@stack.size).to eql(1)
16
16
  end
17
17
 
18
18
  it "should return nil when sent #next" do
19
- @stack.next.should be_nil
19
+ expect(@stack.next).to be_nil
20
20
  end
21
21
 
22
22
  it "should return empty?" do
23
- @stack.empty?.should be_true
23
+ expect(@stack.empty?).to be true
24
24
  end
25
25
  end
26
26
 
@@ -32,29 +32,29 @@ describe "non-empty stack" do
32
32
  end
33
33
 
34
34
  it "should return last pushed object" do
35
- @stack.pop.should eql("10")
35
+ expect(@stack.pop).to eql("10")
36
36
  end
37
37
 
38
38
  it "should return the size" do
39
- @stack.size.should eql(2)
39
+ expect(@stack.size).to eql(2)
40
40
  end
41
41
 
42
42
  it "should not return empty?" do
43
- @stack.empty?.should be_false
43
+ expect(@stack.empty?).to be false
44
44
  end
45
45
 
46
46
 
47
47
  it "should iterate in LIFO order" do
48
48
  arr = []
49
49
  @stack.each { |obj| arr << obj }
50
- arr.should eql(["10", 10])
50
+ expect(arr).to eql(["10", 10])
51
51
  end
52
52
 
53
53
  it "should return nil after all pops" do
54
54
  @stack.pop
55
55
  @stack.pop
56
- @stack.pop.should be_nil
57
- @stack.next.should be_nil
56
+ expect(@stack.pop).to be_nil
57
+ expect(@stack.next).to be_nil
58
58
  end
59
59
 
60
60
  end
data/spec/string_spec.rb CHANGED
@@ -4,12 +4,12 @@ require 'algorithms'
4
4
  if defined? Algorithms::String
5
5
  describe "string algorithms" do
6
6
  it "should do levenshtein distance" do
7
- Algorithms::String.levenshtein_dist("Hello", "Hel").should eql(2)
8
- Algorithms::String.levenshtein_dist("Hello", "").should eql(5)
9
- Algorithms::String.levenshtein_dist("", "Hello").should eql(5)
10
- Algorithms::String.levenshtein_dist("Hello", "Hello").should eql(0)
11
- Algorithms::String.levenshtein_dist("Hello", "ello").should eql(1)
12
- Algorithms::String.levenshtein_dist("Hello", "Mello").should eql(1)
7
+ expect(Algorithms::String.levenshtein_dist("Hello", "Hel")).to eql(2)
8
+ expect(Algorithms::String.levenshtein_dist("Hello", "")).to eql(5)
9
+ expect(Algorithms::String.levenshtein_dist("", "Hello")).to eql(5)
10
+ expect(Algorithms::String.levenshtein_dist("Hello", "Hello")).to eql(0)
11
+ expect(Algorithms::String.levenshtein_dist("Hello", "ello")).to eql(1)
12
+ expect(Algorithms::String.levenshtein_dist("Hello", "Mello")).to eql(1)
13
13
  end
14
14
  end
15
15
  end
@@ -3,7 +3,7 @@ require 'algorithms'
3
3
 
4
4
  describe "empty suffix array" do
5
5
  it "should not initialize with empty string" do
6
- lambda { Containers::SuffixArray.new("") }.should raise_error
6
+ expect { Containers::SuffixArray.new("") }.to raise_error(ArgumentError)
7
7
  end
8
8
  end
9
9
 
@@ -13,28 +13,28 @@ describe "non-empty suffix array" do
13
13
  end
14
14
 
15
15
  it "should has_substring? each possible substring" do
16
- @s_array.has_substring?("a").should be_true
17
- @s_array.has_substring?("abra").should be_true
18
- @s_array.has_substring?("abracadabra").should be_true
19
- @s_array.has_substring?("acadabra").should be_true
20
- @s_array.has_substring?("adabra").should be_true
21
- @s_array.has_substring?("bra").should be_true
22
- @s_array.has_substring?("bracadabra").should be_true
23
- @s_array.has_substring?("cadabra").should be_true
24
- @s_array.has_substring?("dabra").should be_true
25
- @s_array.has_substring?("ra").should be_true
26
- @s_array.has_substring?("racadabra").should be_true
16
+ expect(@s_array.has_substring?("a")).to be true
17
+ expect(@s_array.has_substring?("abra")).to be true
18
+ expect(@s_array.has_substring?("abracadabra")).to be true
19
+ expect(@s_array.has_substring?("acadabra")).to be true
20
+ expect(@s_array.has_substring?("adabra")).to be true
21
+ expect(@s_array.has_substring?("bra")).to be true
22
+ expect(@s_array.has_substring?("bracadabra")).to be true
23
+ expect(@s_array.has_substring?("cadabra")).to be true
24
+ expect(@s_array.has_substring?("dabra")).to be true
25
+ expect(@s_array.has_substring?("ra")).to be true
26
+ expect(@s_array.has_substring?("racadabra")).to be true
27
27
  end
28
28
 
29
29
  it "should not has_substring? substrings it does not have" do
30
- @s_array.has_substring?("nope").should be_false
31
- @s_array.has_substring?(nil).should be_false
30
+ expect(@s_array.has_substring?("nope")).to be false
31
+ expect(@s_array.has_substring?(nil)).to be false
32
32
  end
33
33
 
34
34
  it "should work with numbers (calls to_s)" do
35
35
  number = Containers::SuffixArray.new(123456789)
36
- number[1].should be_true
37
- number.has_substring?(12).should be_true
38
- number.has_substring?(13).should be_false
36
+ expect(number[1]).to be true
37
+ expect(number.has_substring?(12)).to be true
38
+ expect(number.has_substring?(13)).to be false
39
39
  end
40
40
  end
data/spec/trie_spec.rb CHANGED
@@ -7,13 +7,13 @@ describe "empty trie" do
7
7
  end
8
8
 
9
9
  it "should not get or has_key?" do
10
- @trie.get("anything").should be_nil
11
- @trie.has_key?("anything").should be_false
10
+ expect(@trie.get("anything")).to be_nil
11
+ expect(@trie.has_key?("anything")).to be false
12
12
  end
13
13
 
14
14
  it "should not have longest_prefix or match wildcards" do
15
- @trie.wildcard("an*thing").should eql([])
16
- @trie.longest_prefix("an*thing").should eql("")
15
+ expect(@trie.wildcard("an*thing")).to eql([])
16
+ expect(@trie.longest_prefix("an*thing")).to eql("")
17
17
  end
18
18
  end
19
19
 
@@ -27,33 +27,33 @@ describe "non-empty trie" do
27
27
  end
28
28
 
29
29
  it "should has_key? keys it has" do
30
- @trie.has_key?("Hello").should be_true
31
- @trie.has_key?("Hello, brother").should be_true
32
- @trie.has_key?("Hello, bob").should be_true
30
+ expect(@trie.has_key?("Hello")).to be true
31
+ expect(@trie.has_key?("Hello, brother")).to be true
32
+ expect(@trie.has_key?("Hello, bob")).to be true
33
33
  end
34
34
 
35
35
  it "should not has_key? keys it doesn't have" do
36
- @trie.has_key?("Nope").should be_false
36
+ expect(@trie.has_key?("Nope")).to be false
37
37
  end
38
38
 
39
39
  it "should get values" do
40
- @trie.get("Hello").should eql("World")
40
+ expect(@trie.get("Hello")).to eql("World")
41
41
  end
42
42
 
43
43
  it "should overwrite values" do
44
44
  @trie.push("Hello", "John")
45
- @trie.get("Hello").should eql("John")
45
+ expect(@trie.get("Hello")).to eql("John")
46
46
  end
47
47
 
48
48
  it "should return longest prefix" do
49
- @trie.longest_prefix("Hello, brandon").should eql("Hello")
50
- @trie.longest_prefix("Hel").should eql("")
51
- @trie.longest_prefix("Hello").should eql("Hello")
52
- @trie.longest_prefix("Hello, bob").should eql("Hello, bob")
49
+ expect(@trie.longest_prefix("Hello, brandon")).to eql("Hello")
50
+ expect(@trie.longest_prefix("Hel")).to eql("")
51
+ expect(@trie.longest_prefix("Hello")).to eql("Hello")
52
+ expect(@trie.longest_prefix("Hello, bob")).to eql("Hello, bob")
53
53
  end
54
54
 
55
55
  it "should match wildcards" do
56
- @trie.wildcard("H*ll.").should eql(["Hello", "Hilly"])
57
- @trie.wildcard("Hel").should eql([])
56
+ expect(@trie.wildcard("H*ll.")).to eql(["Hello", "Hilly"])
57
+ expect(@trie.wildcard("Hel")).to eql([])
58
58
  end
59
59
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algorithms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kanwei Li
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-22 00:00:00.000000000 Z
11
+ date: 2021-04-04 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Heap, Priority Queue, Deque, Stack, Queue, Red-Black Trees, Splay Trees,
15
14
  sorting algorithms, and more
@@ -23,8 +22,8 @@ extensions:
23
22
  - ext/containers/splaytree_map/extconf.rb
24
23
  extra_rdoc_files: []
25
24
  files:
26
- - Gemfile
27
25
  - CHANGELOG.markdown
26
+ - Gemfile
28
27
  - Manifest
29
28
  - README.markdown
30
29
  - Rakefile
@@ -78,33 +77,31 @@ files:
78
77
  homepage: https://github.com/kanwei/algorithms
79
78
  licenses:
80
79
  - MIT
80
+ metadata: {}
81
81
  post_install_message:
82
82
  rdoc_options:
83
- - --line-numbers
84
- - --inline-source
85
- - --title
83
+ - "--line-numbers"
84
+ - "--inline-source"
85
+ - "--title"
86
86
  - Algorithms
87
- - --main
87
+ - "--main"
88
88
  - README.markdown
89
89
  require_paths:
90
90
  - lib
91
91
  - ext
92
92
  required_ruby_version: !ruby/object:Gem::Requirement
93
- none: false
94
93
  requirements:
95
- - - ! '>='
94
+ - - ">="
96
95
  - !ruby/object:Gem::Version
97
96
  version: '0'
98
97
  required_rubygems_version: !ruby/object:Gem::Requirement
99
- none: false
100
98
  requirements:
101
- - - ! '>='
99
+ - - ">="
102
100
  - !ruby/object:Gem::Version
103
101
  version: '0'
104
102
  requirements: []
105
- rubyforge_project: algorithms
106
- rubygems_version: 1.8.23
103
+ rubygems_version: 3.1.2
107
104
  signing_key:
108
- specification_version: 3
105
+ specification_version: 4
109
106
  summary: Useful algorithms and data structures for Ruby. Optional C extensions.
110
107
  test_files: []