datastructures 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/datastructures/version.rb +1 -1
- data/test/test_datastructures.rb +10 -3
- data/test/test_queue.rb +61 -28
- metadata +33 -1
data/README.md
CHANGED
@@ -13,7 +13,7 @@ A collection of data structures in Ruby, made for my [data structures challenge]
|
|
13
13
|
[travis]: https://travis-ci.org/Blahah/datastructures
|
14
14
|
[gemnasium]: https://gemnasium.com/Blahah/datastructures
|
15
15
|
[codeclimate]: https://codeclimate.com/github/Blahah/datastructures
|
16
|
-
[coveralls]: https://coveralls.io/
|
16
|
+
[coveralls]: https://coveralls.io/r/Blahah/datastructures
|
17
17
|
|
18
18
|
## Installation
|
19
19
|
|
data/test/test_datastructures.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
-
require '
|
2
|
-
require 'datastructures'
|
1
|
+
require 'simplecov'
|
3
2
|
require 'coveralls'
|
4
3
|
|
5
|
-
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
SimpleCov.start
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
require 'datastructures'
|
data/test/test_queue.rb
CHANGED
@@ -1,43 +1,76 @@
|
|
1
|
-
require '
|
2
|
-
require 'datastructures'
|
1
|
+
require 'test_datastructures'
|
3
2
|
|
4
3
|
class TestQueue < Test::Unit::TestCase
|
5
4
|
|
6
|
-
|
5
|
+
context "Queue" do
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
setup do
|
8
|
+
@queue = DataStructures::Queue.new
|
9
|
+
end
|
10
|
+
|
11
|
+
should "be able to create a new instance" do
|
12
|
+
@queue = DataStructures::Queue.new
|
13
|
+
end
|
14
|
+
|
15
|
+
should "begin empty" do
|
16
|
+
assert @queue.empty?
|
17
|
+
assert @queue.size == 0
|
18
|
+
end
|
19
|
+
|
20
|
+
should "raise an error on underflow" do
|
21
|
+
assert_raise RuntimeError, "Queue underflow: nothing to dequeue" do
|
22
|
+
@queue.dequeue
|
23
|
+
end
|
24
|
+
end
|
10
25
|
|
11
|
-
|
12
|
-
|
13
|
-
|
26
|
+
should "stop being empty when first item added" do
|
27
|
+
@queue.enqueue('first')
|
28
|
+
assert !@queue.empty?
|
29
|
+
assert @queue.size == 1
|
30
|
+
end
|
14
31
|
|
15
|
-
|
16
|
-
|
17
|
-
queue.
|
32
|
+
should "increment size on enqueueing" do
|
33
|
+
@queue.enqueue('first')
|
34
|
+
@queue.enqueue('second')
|
35
|
+
assert @queue.size == 2
|
18
36
|
end
|
19
37
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
38
|
+
should "respond to size and length" do
|
39
|
+
@queue.enqueue('first')
|
40
|
+
assert @queue.size == @queue.length
|
41
|
+
end
|
24
42
|
|
25
|
-
|
26
|
-
|
27
|
-
|
43
|
+
should "have first item in at the front" do
|
44
|
+
@queue.enqueue('first')
|
45
|
+
@queue.enqueue('second')
|
46
|
+
assert @queue.front == 'first'
|
47
|
+
end
|
28
48
|
|
29
|
-
|
30
|
-
|
31
|
-
|
49
|
+
should "have last item in at the back" do
|
50
|
+
@queue.enqueue('first')
|
51
|
+
@queue.enqueue('second')
|
52
|
+
assert @queue.back == 'second'
|
53
|
+
end
|
32
54
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
55
|
+
should "return first in queue and get smaller on dequeueing" do
|
56
|
+
@queue.enqueue('first')
|
57
|
+
@queue.enqueue('second')
|
58
|
+
assert @queue.dequeue == 'first'
|
59
|
+
assert @queue.size == 1
|
60
|
+
end
|
61
|
+
|
62
|
+
should "have first and last items equal when length is one" do
|
63
|
+
@queue.enqueue('first')
|
64
|
+
assert @queue.size == 1
|
65
|
+
assert @queue.front == @queue.back
|
66
|
+
end
|
37
67
|
|
38
|
-
|
39
|
-
|
40
|
-
queue.
|
68
|
+
should "become empty when last item dequeued" do
|
69
|
+
@queue.enqueue('first')
|
70
|
+
@queue.enqueue('second')
|
71
|
+
2.times{ @queue.dequeue }
|
72
|
+
assert @queue.size == 0
|
73
|
+
assert @queue.empty?
|
41
74
|
end
|
42
75
|
|
43
76
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datastructures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,38 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: simplecov
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.7.1
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.7.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: shoulda
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.5.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.5.0
|
30
62
|
- !ruby/object:Gem::Dependency
|
31
63
|
name: coveralls
|
32
64
|
requirement: !ruby/object:Gem::Requirement
|