datr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1493680d2d3cde753997ca0f50e61bdb4041480f
4
+ data.tar.gz: 273ee9c399fc41b5b1e6485e08ec08955b85e247
5
+ SHA512:
6
+ metadata.gz: 068bd23646b9f502fbaa68f962dea3eb5e415966b00f911bbd18b2a28ec6f4600a5515333a6e19ee3ca0b85c36a49b821235408a914932e2ad93ba4211d71ead
7
+ data.tar.gz: 1d8901b115705b62bb667a590e23e1151e6bbebc6a26413fda035ad12ceb944843734f9632da845f5933b078736cdf279f4a92fd9e2dc0178f3d9660ef70269c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in datr.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ignacio Contreras Pinilla
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Datr
2
+
3
+ Ruby implementation of some common data structures.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'datr'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install datr
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'datr'
23
+
24
+ s = Datr::Stack.new
25
+ s.push "hi"
26
+ s.top # => "hi"
27
+ s.empty? #=> false
28
+ s.size # => 1
29
+ s.pop # => "hi"
30
+ s.size # => 0
31
+ s.empty? # => true
32
+
33
+ q = Datr::Queue.new
34
+ q.insert "hola"
35
+ q.first # => "hola"
36
+ q.empty? # => false
37
+ q.size # => 1
38
+ q.remove # => "hola"
39
+ q.size # => 0
40
+ q.empty? # => true
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rdoc/task"
3
+ require "rake/testtask"
4
+
5
+ RDoc::Task.new do |rdoc|
6
+ rdoc.main = "README.md"
7
+ rdoc.rdoc_files.include("README.md", "lib /*.rb")
8
+ end
9
+
10
+ Rake::TestTask.new do |test|
11
+ test.libs << "test"
12
+ end
13
+
14
+ task :default => [:test]
data/datr.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'datr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "datr"
8
+ spec.version = Datr::VERSION
9
+ spec.authors = ["Ignacio Contreras Pinilla"]
10
+ spec.email = ["ignacio@ignacio.cat"]
11
+ spec.description = %q{Ruby implementation of some common data structures}
12
+ spec.summary = %q{Common data structures}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/lib/datr.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "datr/version"
2
+ require "datr/stack"
3
+ require "datr/queue"
4
+
5
+ module Datr
6
+ # Your code goes here...
7
+ end
data/lib/datr/queue.rb ADDED
@@ -0,0 +1,31 @@
1
+ module Datr
2
+
3
+ class Queue
4
+
5
+ def initialize
6
+ @elements = []
7
+ end
8
+
9
+ def insert elem
10
+ @elements << elem
11
+ end
12
+
13
+ def remove
14
+ @elements.delete_at(0)
15
+ end
16
+
17
+ def first
18
+ @elements.first
19
+ end
20
+
21
+ def empty?
22
+ @elements.empty?
23
+ end
24
+
25
+ def size
26
+ @elements.size
27
+ end
28
+
29
+ end
30
+
31
+ end
data/lib/datr/stack.rb ADDED
@@ -0,0 +1,31 @@
1
+ module Datr
2
+
3
+ class Stack
4
+
5
+ def initialize
6
+ @elements = []
7
+ end
8
+
9
+ def push elem
10
+ @elements << elem
11
+ end
12
+
13
+ def pop
14
+ @elements.delete_at(@elements.size - 1)
15
+ end
16
+
17
+ def top
18
+ @elements.last
19
+ end
20
+
21
+ def empty?
22
+ @elements.empty?
23
+ end
24
+
25
+ def size
26
+ @elements.size
27
+ end
28
+
29
+ end
30
+
31
+ end
data/lib/datr/tree.rb ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ module Datr
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../lib")
@@ -0,0 +1,55 @@
1
+ require_relative "test_helper"
2
+ require "test/unit"
3
+ require "datr"
4
+
5
+ class TestQueue < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @q = Datr::Queue.new
9
+ end
10
+
11
+ def test_a_new_queue_is_alway_empty
12
+ assert @q.empty?
13
+ end
14
+
15
+ def test_a_queue_is_not_empty_after_an_insert
16
+ @q.insert 1
17
+ assert_equal false, @q.empty?
18
+ end
19
+
20
+ def test_a_queue_is_empty_after_one_insert_and_one_remove
21
+ @q.insert "hola"
22
+ @q.remove
23
+ assert @q.empty?
24
+ end
25
+
26
+ def test_remove_returns_the_first_inserted_element
27
+ @q.insert 1
28
+ @q.insert 2
29
+ assert_equal 1, @q.remove
30
+ end
31
+
32
+ def test_remove_in_an_empty_queue_returns_nil
33
+ assert_nil @q.remove
34
+ end
35
+
36
+ def test_a_new_queue_has_size_0
37
+ assert_equal 0, @q.size
38
+ end
39
+
40
+ def test_insert_increments_the_size_by_1
41
+ size = @q.size
42
+ @q.insert "hola"
43
+ assert_equal size + 1, @q.size
44
+ end
45
+
46
+ def test_insert_and_remove_multiple_elements
47
+ (1..10).each do |i|
48
+ @q.insert i
49
+ end
50
+ (1..10).each do |i|
51
+ assert_equal i, @q.remove
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,55 @@
1
+ require_relative "test_helper"
2
+ require "test/unit"
3
+ require "datr"
4
+
5
+ class TestStack < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @s = Datr::Stack.new
9
+ end
10
+
11
+ def test_a_new_stack_is_alway_empty
12
+ assert @s.empty?
13
+ end
14
+
15
+ def test_a_stack_is_not_empty_after_a_push
16
+ @s.push 1
17
+ assert_equal false, @s.empty?
18
+ end
19
+
20
+ def test_a_stack_is_empty_after_one_push_and_one_pop
21
+ @s.push "hola"
22
+ @s.pop
23
+ assert @s.empty?
24
+ end
25
+
26
+ def test_pop_returns_the_last_pushed_element
27
+ @s.push 1
28
+ @s.push 2
29
+ assert_equal 2, @s.pop
30
+ end
31
+
32
+ def test_pop_in_an_empty_stack_returns_nil
33
+ assert_nil @s.pop
34
+ end
35
+
36
+ def test_a_new_stack_has_size_0
37
+ assert_equal 0, @s.size
38
+ end
39
+
40
+ def test_push_increments_the_size_by_1
41
+ size = @s.size
42
+ @s.push "hola"
43
+ assert_equal size + 1, @s.size
44
+ end
45
+
46
+ def test_push_and_pop_multiple_elements
47
+ (1..10).each do |i|
48
+ @s.push i
49
+ end
50
+ (10..1).each do |i|
51
+ assert_equal i, @s.pop
52
+ end
53
+ end
54
+
55
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ignacio Contreras Pinilla
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Ruby implementation of some common data structures
42
+ email:
43
+ - ignacio@ignacio.cat
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - datr.gemspec
54
+ - lib/datr.rb
55
+ - lib/datr/queue.rb
56
+ - lib/datr/stack.rb
57
+ - lib/datr/tree.rb
58
+ - lib/datr/version.rb
59
+ - test/test_helper.rb
60
+ - test/test_queue.rb
61
+ - test/test_stack.rb
62
+ homepage: ''
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.0.14
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Common data structures
86
+ test_files:
87
+ - test/test_helper.rb
88
+ - test/test_queue.rb
89
+ - test/test_stack.rb