wdatastructure 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 18810cf51e20bd88fea609bcdc76d01c81c4294dbb8d7c99eed3a635aedd22be
4
+ data.tar.gz: 152f7933687c3c3901eeaaacfdea680ec19cc02030ecf32d2a0bb90194fa2f2d
5
+ SHA512:
6
+ metadata.gz: 7336c5649f7f3c643d7c27f6bc517d7066ebc060de61c36da9666516878315f6521552be9fe7bbe3092e46ab1eb8619157dbac7b04228da9950a6bc66dd8e8fa
7
+ data.tar.gz: a67d36713553fd837465dd50130dec0a89cba3040d32e2af72be8fa8cc33f93a513e429bcd3f286a66728d3b3f6090ccb1ee22d01003bbd6ddb3a127a56c895a
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # Gemfile
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify your gemspec to include the gem dependencies for your gem
5
+ gemspec
6
+
7
+ # Add development dependencies
8
+ group :development, :test do
9
+ gem 'rspec' # For running tests
10
+ end
@@ -0,0 +1,77 @@
1
+ # lib/data_types/linked_list.rb
2
+ require_relative "node"
3
+
4
+ module DataTypes
5
+ class LinkedList
6
+ include Enumerable
7
+
8
+ def initialize
9
+ @head = nil
10
+ @tail = nil
11
+ end
12
+
13
+ # Append to the end of the list
14
+ def append(value)
15
+ new_node = Node.new(value)
16
+
17
+ if @head.nil?
18
+ @head = new_node
19
+ @tail = new_node
20
+ else
21
+ @tail.next = new_node
22
+ @tail = new_node
23
+ end
24
+ end
25
+
26
+ # Insert a new element at the beginning
27
+ def prepend(value)
28
+ new_node = Node.new(value)
29
+ if @head.nil?
30
+ @head = new_node
31
+ @tail = new_node
32
+ else
33
+ new_node.next = @head
34
+ @head = new_node
35
+ end
36
+ end
37
+
38
+ # Find an element by value
39
+ def find(value)
40
+ current = @head
41
+ while current
42
+ return current if current.value == value
43
+ current = current.next
44
+ end
45
+ nil
46
+ end
47
+
48
+ # Implement the `each` method to make LinkedList Enumerable
49
+ def each
50
+ current = @head
51
+ while current
52
+ yield current.value
53
+ current = current.next
54
+ end
55
+ end
56
+
57
+ # Convert linked list to an array
58
+ def to_a
59
+ map { |value| value }
60
+ end
61
+
62
+ # Check if the list is empty
63
+ def empty?
64
+ @head.nil?
65
+ end
66
+
67
+ # Get size of the linked list
68
+ def size
69
+ count
70
+ end
71
+
72
+ # Print the list elements
73
+ def display
74
+ each { |value| puts value }
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,10 @@
1
+ module DataTypes
2
+ class Node
3
+ attr_accessor :value, :next
4
+
5
+ def initialize(value)
6
+ @value = value
7
+ @next = nil
8
+ end
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ require 'data_types/linked_list/linked_list'
@@ -0,0 +1,107 @@
1
+ require_relative '../lib/data_types/linked_list/linked_list'
2
+
3
+ RSpec.describe DataTypes::LinkedList do
4
+ let(:list) { DataTypes::LinkedList.new }
5
+
6
+ describe '#append' do
7
+ it 'appends elements to the end of the list' do
8
+ list.append(1)
9
+ list.append(2)
10
+ list.append(3)
11
+
12
+ expect(list.to_a).to eq([1, 2, 3])
13
+ end
14
+
15
+ it 'appends an element to an empty list' do
16
+ list.append(42)
17
+ expect(list.to_a).to eq([42])
18
+ end
19
+ end
20
+
21
+ describe '#prepend' do
22
+ it 'prepends elements to the beginning of the list' do
23
+ list.append(2)
24
+ list.prepend(1)
25
+
26
+ expect(list.to_a).to eq([1, 2])
27
+ end
28
+
29
+ it 'prepends to an empty list' do
30
+ list.prepend(42)
31
+ expect(list.to_a).to eq([42])
32
+ end
33
+ end
34
+
35
+ describe '#find' do
36
+ it 'finds an element in the list' do
37
+ list.append(10)
38
+ node = list.find(10)
39
+
40
+ expect(node.value).to eq(10)
41
+ end
42
+
43
+ it 'returns nil if element is not in the list' do
44
+ list.append(10)
45
+ list.append(20)
46
+
47
+ expect(list.find(30)).to be_nil
48
+ end
49
+ end
50
+
51
+ describe '#each' do
52
+ it 'iterates over each element in the list' do
53
+ list.append(1)
54
+ list.append(2)
55
+ list.append(3)
56
+
57
+ result = []
58
+ list.each { |value| result << value }
59
+
60
+ expect(result).to eq([1, 2, 3])
61
+ end
62
+ end
63
+
64
+ describe '#to_a' do
65
+ it 'converts the linked list to an array' do
66
+ list.append(5)
67
+ list.append(10)
68
+
69
+ expect(list.to_a).to eq([5, 10])
70
+ end
71
+ end
72
+
73
+ describe '#empty?' do
74
+ it 'returns true for an empty list' do
75
+ expect(list.empty?).to be true
76
+ end
77
+
78
+ it 'returns false for a non-empty list' do
79
+ list.append(1)
80
+ expect(list.empty?).to be false
81
+ end
82
+ end
83
+
84
+ describe '#size' do
85
+ it 'returns the size of the list' do
86
+ list.append(1)
87
+ list.append(2)
88
+ list.append(3)
89
+
90
+ expect(list.size).to eq(3)
91
+ end
92
+
93
+ it 'returns 0 for an empty list' do
94
+ expect(list.size).to eq(0)
95
+ end
96
+ end
97
+
98
+ describe '#display' do
99
+ it 'prints each element in the list' do
100
+ list.append(1)
101
+ list.append(2)
102
+ list.append(3)
103
+
104
+ expect { list.display }.to output("1\n2\n3\n").to_stdout
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,98 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ end
30
+
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
38
+ end
39
+
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # This allows you to limit a spec run to individual examples or groups
51
+ # you care about by tagging them with `:focus` metadata. When nothing
52
+ # is tagged with `:focus`, all examples get run. RSpec also provides
53
+ # aliases for `it`, `describe`, and `context` that include `:focus`
54
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55
+ config.filter_run_when_matching :focus
56
+
57
+ # Allows RSpec to persist some state between runs in order to support
58
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
59
+ # you configure your source control system to ignore this file.
60
+ config.example_status_persistence_file_path = "spec/examples.txt"
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
65
+ config.disable_monkey_patching!
66
+
67
+ # This setting enables warnings. It's recommended, but in some cases may
68
+ # be too noisy due to issues in dependencies.
69
+ config.warnings = true
70
+
71
+ # Many RSpec users commonly either run the entire suite or an individual
72
+ # file, and it's useful to allow more verbose output when running an
73
+ # individual spec file.
74
+ if config.files_to_run.one?
75
+ # Use the documentation formatter for detailed output,
76
+ # unless a formatter has already been configured
77
+ # (e.g. via a command-line flag).
78
+ config.default_formatter = "doc"
79
+ end
80
+
81
+ # Print the 10 slowest examples and example groups at the
82
+ # end of the spec run, to help surface which specs are running
83
+ # particularly slow.
84
+ config.profile_examples = 10
85
+
86
+ # Run specs in random order to surface order dependencies. If you find an
87
+ # order dependency and want to debug it, you can fix the order by providing
88
+ # the seed, which is printed after each run.
89
+ # --seed 1234
90
+ config.order = :random
91
+
92
+ # Seed global randomization in this process using the `--seed` CLI option.
93
+ # Setting this allows you to use `--seed` to deterministically reproduce
94
+ # test failures related to randomization by passing the same `--seed` value
95
+ # as the one that triggered the failure.
96
+ Kernel.srand config.seed
97
+ =end
98
+ end
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "wdatastructure"
3
+ s.version = "0.0.1"
4
+ s.summary = "datastructure collection"
5
+ s.description = "A collection datastructure implementation"
6
+ s.authors = ["Wilder 'W1ldr' Ribeiro"]
7
+ s.email = "dewillribeiro@gmail.com"
8
+ s.files = Dir["lib/**/*.rb", "spec/**/*.rb", "*.gemspec", "Gemfile", ".rspec", "spec/spec_helper.rb"]
9
+ s.homepage = "https://rubygems.org/gems/math_wild"
10
+ s.license = "MIT"
11
+ s.required_ruby_version = ">= 3.0.0"
12
+ #s.add_development_dependency = "rspec"
13
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wdatastructure
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Wilder 'W1ldr' Ribeiro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-10-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A collection datastructure implementation
14
+ email: dewillribeiro@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".rspec"
20
+ - Gemfile
21
+ - lib/data_types/linked_list/linked_list.rb
22
+ - lib/data_types/linked_list/node.rb
23
+ - lib/wdatastructure.rb
24
+ - spec/linked_list_spec.rb
25
+ - spec/spec_helper.rb
26
+ - wdatastructure.gemspec
27
+ homepage: https://rubygems.org/gems/math_wild
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.0.0
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.5.16
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: datastructure collection
50
+ test_files: []