diff --git a/2024/ruby/.rubocop.yml b/2024/ruby/.rubocop.yml index b060ad6..eb7e48e 100644 --- a/2024/ruby/.rubocop.yml +++ b/2024/ruby/.rubocop.yml @@ -1,17 +1,16 @@ -require: rubocop-rspec +require: + - rubocop-rspec + - rubocop-rake AllCops: Exclude: - bin/**/* - spec/spec_helper.rb - vendor/**/* - Style/Documentation: Enabled: false Style/FrozenStringLiteralComment: Enabled: false -Style/StringLiterals: - Enabled: false Style/TrailingCommaInHashLiteral: Enabled: false Style/NumericPredicate: @@ -20,4 +19,10 @@ Metrics/BlockLength: Exclude: - spec/**/* + +RSpec/ExampleLength: + Max: 20 +RSpec/MultipleExpectations: + Enabled: false + inherit_from: .rubocop_todo.yml diff --git a/2024/ruby/.rubocop_todo.yml b/2024/ruby/.rubocop_todo.yml index 81668af..0d0b31c 100644 --- a/2024/ruby/.rubocop_todo.yml +++ b/2024/ruby/.rubocop_todo.yml @@ -1,7 +1,50 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-12-01 17:39:10 UTC using RuboCop version 1.69.0. +# on 2024-12-05 02:17:24 UTC using RuboCop version 1.69.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 24 + +# Offense count: 5 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 161 + +# Offense count: 1 +# Configuration parameters: CountComments, CountAsOne. +Metrics/ClassLength: + Max: 120 + +# Offense count: 2 +# Configuration parameters: EnforcedStyle, AllowedPatterns. +# SupportedStyles: snake_case, camelCase +Naming/MethodName: + Exclude: + - 'lib/advent_04_ceres_search.rb' + - 'test.rb' + +# Offense count: 2 +# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. +# SupportedStyles: snake_case, normalcase, non_integer +# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 +Naming/VariableNumber: + Exclude: + - 'lib/advent_04_ceres_search.rb' + +# Offense count: 4 +# Configuration parameters: AllowedConstants. +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'lib/advent_01_hystorian_hysteria.rb' + - 'lib/advent_02_red_nosed_reports.rb' + - 'lib/advent_03_mull_it_over.rb' + - 'lib/advent_04_ceres_search.rb' diff --git a/2024/ruby/Gemfile b/2024/ruby/Gemfile index d42529d..6a8e48d 100644 --- a/2024/ruby/Gemfile +++ b/2024/ruby/Gemfile @@ -5,7 +5,14 @@ source 'https://rubygems.org' ruby File.open('.ruby-version', 'rb') { |f| f.read.chomp } gem 'awesome_print' + +gem 'guard' +gem 'guard-rspec', require: false + gem 'pry', '~> 0.15.0' + +gem 'rake', '~> 13.2' gem 'rspec', '~> 3.13.0' gem 'rubocop', '~> 1.69.0' +gem 'rubocop-rake', '0.6.0', require: false gem 'rubocop-rspec', '3.2.0', require: false diff --git a/2024/ruby/Gemfile.lock b/2024/ruby/Gemfile.lock index 9779c70..750efed 100644 --- a/2024/ruby/Gemfile.lock +++ b/2024/ruby/Gemfile.lock @@ -5,9 +5,34 @@ GEM awesome_print (1.9.2) coderay (1.1.3) diff-lcs (1.5.1) + ffi (1.17.0) + ffi (1.17.0-arm64-darwin) + formatador (1.1.0) + guard (2.19.0) + formatador (>= 0.2.4) + listen (>= 2.7, < 4.0) + lumberjack (>= 1.0.12, < 2.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.13.0) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-compat (1.2.1) + guard-rspec (4.7.3) + guard (~> 2.1) + guard-compat (~> 1.1) + rspec (>= 2.99.0, < 4.0) json (2.8.2) language_server-protocol (3.17.0.3) + listen (3.9.0) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) + lumberjack (1.2.10) method_source (1.1.0) + nenv (0.3.0) + notiffany (0.1.3) + nenv (~> 0.1) + shellany (~> 0.0) parallel (1.26.3) parser (3.3.6.0) ast (~> 2.4.1) @@ -17,6 +42,10 @@ GEM method_source (~> 1.0) racc (1.8.1) rainbow (3.1.1) + rake (13.2.1) + rb-fsevent (0.11.2) + rb-inotify (0.11.1) + ffi (~> 1.0) regexp_parser (2.9.3) rspec (3.13.0) rspec-core (~> 3.13.0) @@ -43,9 +72,13 @@ GEM unicode-display_width (>= 2.4.0, < 4.0) rubocop-ast (1.36.2) parser (>= 3.3.1.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) rubocop-rspec (3.2.0) rubocop (~> 1.61) ruby-progressbar (1.13.0) + shellany (0.0.1) + thor (1.3.2) unicode-display_width (3.1.2) unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) @@ -56,9 +89,13 @@ PLATFORMS DEPENDENCIES awesome_print + guard + guard-rspec pry (~> 0.15.0) + rake (~> 13.2) rspec (~> 3.13.0) rubocop (~> 1.69.0) + rubocop-rake (= 0.6.0) rubocop-rspec (= 3.2.0) RUBY VERSION diff --git a/2024/ruby/Guardfile b/2024/ruby/Guardfile new file mode 100644 index 0000000..5a83809 --- /dev/null +++ b/2024/ruby/Guardfile @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +## Uncomment and set this to only include directories you want to watch +# directories %w(app lib config test spec features) \ +# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")} + +## Note: if you are using the `directories` clause above and you are not +## watching the project directory ('.'), then you will want to move +## the Guardfile to a watched dir and symlink it back, e.g. +# +# $ mkdir config +# $ mv Guardfile config/ +# $ ln -s config/Guardfile . +# +# and, you'll have to watch "config/Guardfile" instead of "Guardfile" + +# NOTE: The cmd option is now required due to the increasing number of ways +# rspec may be run, below are examples of the most common uses. +# * bundler: 'bundle exec rspec' +# * bundler binstubs: 'bin/rspec' +# * spring: 'bin/rspec' (This will use spring if running and you have +# installed the spring binstubs per the docs) +# * zeus: 'zeus rspec' (requires the server to be started separately) +# * 'just' rspec: 'rspec' + +guard :rspec, cmd: 'bundle exec rspec' do + require 'guard/rspec/dsl' + dsl = Guard::RSpec::Dsl.new(self) + + # Feel free to open issues for suggestions and improvements + + # RSpec files + rspec = dsl.rspec + watch(rspec.spec_helper) { rspec.spec_dir } + watch(rspec.spec_support) { rspec.spec_dir } + watch(rspec.spec_files) + + # Ruby files + ruby = dsl.ruby + dsl.watch_spec_files_for(ruby.lib_files) + + # Rails files + rails = dsl.rails(view_extensions: %w[erb haml slim]) + dsl.watch_spec_files_for(rails.app_files) + dsl.watch_spec_files_for(rails.views) + + watch(rails.controllers) do |m| + [ + rspec.spec.call("routing/#{m[1]}_routing"), + rspec.spec.call("controllers/#{m[1]}_controller"), + rspec.spec.call("acceptance/#{m[1]}") + ] + end + + # Rails config changes + watch(rails.spec_helper) { rspec.spec_dir } + watch(rails.routes) { "#{rspec.spec_dir}/routing" } + watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" } + + # Capybara features specs + watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") } + watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") } + + # Turnip features and steps + watch(%r{^spec/acceptance/(.+)\.feature$}) + watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m| + Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' + end +end diff --git a/2024/ruby/Rakefile b/2024/ruby/Rakefile new file mode 100644 index 0000000..0a25846 --- /dev/null +++ b/2024/ruby/Rakefile @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'fileutils' + +def next_advent_number + latest = Dir['./lib/advent*.rb'].map { |p| p.match(/\d{2}/)&.[](0)&.to_i }.compact.max || 0 + latest + 1 +end + +desc 'create class and spec file for DAY' +task :new do + day = ENV['DAY'].nil? ? next_advent_number : ENV['DAY'].to_i + + raise 'invalid DAY' unless day.between?(1, 31) + + formatted_day = day.to_s.rjust(2, '0') + + FileUtils.touch("./lib/advent_#{formatted_day}.rb") + FileUtils.touch("./spec/advent_#{formatted_day}_spec.rb") + FileUtils.touch("./spec/fixtures/advent-#{formatted_day}.txt") + FileUtils.touch("./spec/fixtures/advent-#{formatted_day}-sample.txt") +end diff --git a/2024/ruby/lib/advent_02_red_nosed_reports.rb b/2024/ruby/lib/advent_02_red_nosed_reports.rb index 2a75ed6..b64d901 100644 --- a/2024/ruby/lib/advent_02_red_nosed_reports.rb +++ b/2024/ruby/lib/advent_02_red_nosed_reports.rb @@ -26,7 +26,7 @@ def safe_with_dampener? def safe_levels(direction, levels) levels.each_index do |i| - next if i == 0 + next if i.zero? current = levels[i] prev = levels[i - 1] diff --git a/2024/ruby/lib/advent_03_mull_it_over.rb b/2024/ruby/lib/advent_03_mull_it_over.rb index e749462..cc0d827 100644 --- a/2024/ruby/lib/advent_03_mull_it_over.rb +++ b/2024/ruby/lib/advent_03_mull_it_over.rb @@ -25,7 +25,7 @@ def uncorrupted_pieces end def process_piece(str) - splits = str.tr("^0123456789,", "").split(",") + splits = str.tr('^0123456789,', '').split(',') splits[0].to_i * splits[1].to_i end diff --git a/2024/ruby/lib/advent_04_ceres_search.rb b/2024/ruby/lib/advent_04_ceres_search.rb index ef2ce57..f5e3aa8 100644 --- a/2024/ruby/lib/advent_04_ceres_search.rb +++ b/2024/ruby/lib/advent_04_ceres_search.rb @@ -1,7 +1,7 @@ class WordSearch attr_reader :data, :word - def initialize(data, word = "XMAS") + def initialize(data, word = 'XMAS') @data = data @word = word end @@ -19,14 +19,14 @@ def count_at(row, col) end def letter_at(row, col) - in_bounds?(row, col) ? data[row][col] : "" + in_bounds?(row, col) ? data[row][col] : '' end def horizontal_word(row, col) first = col last = col + word.length - 1 - return "" unless in_bounds?(first, last) + return '' unless in_bounds?(first, last) data[row][first..last] * '' end @@ -36,7 +36,7 @@ def horizontal?(row, col) end def vertical_word(row, col) - (row..row+word.length-1).map do |pos| + (row..row + word.length - 1).map do |pos| letter_at(pos, col) end * '' end @@ -47,25 +47,25 @@ def vertical?(row, col) def diagonal_top_left_word(row, col) (0..word.length - 1).map do |pos| - letter_at(row-pos, col-pos) + letter_at(row - pos, col - pos) end * '' end def diagonal_top_right_word(row, col) (0..word.length - 1).map do |pos| - letter_at(row-pos, col+pos) - end * "" + letter_at(row - pos, col + pos) + end * '' end def diagonal_bottom_right_word(row, col) (0..word.length - 1).map do |pos| - letter_at(row+pos, col+pos) + letter_at(row + pos, col + pos) end * '' end def diagonal_bottom_left_word(row, col) (0..word.length - 1).map do |pos| - letter_at(row+pos, col-pos) + letter_at(row + pos, col - pos) end * '' end @@ -74,10 +74,10 @@ def match?(str) end def cross_word_at?(row, col) - cross_word = "MAS" + cross_word = 'MAS' - diag_1 = letter_at(row-1, col-1) + letter_at(row, col) + letter_at(row+1, col+1) - diag_2 = letter_at(row+1, col-1) + letter_at(row, col) + letter_at(row-1, col+1) + diag_1 = letter_at(row - 1, col - 1) + letter_at(row, col) + letter_at(row + 1, col + 1) + diag_2 = letter_at(row + 1, col - 1) + letter_at(row, col) + letter_at(row - 1, col + 1) diag_1_match = [cross_word, cross_word.reverse].any? { |str| str == diag_1 } diag_2_match = [cross_word, cross_word.reverse].any? { |str| str == diag_2 } @@ -122,8 +122,8 @@ def diagonal_count_at(row, col) diagonal_top_right_word(row, col), diagonal_top_left_word(row, col), diagonal_bottom_right_word(row, col), - diagonal_bottom_left_word(row, col), - ].sum { |str| str == word ? 1 : 0} + diagonal_bottom_left_word(row, col) + ].sum { |str| str == word ? 1 : 0 } end def diagonal_count @@ -147,3 +147,9 @@ def render end end end + +def badName + return unless something + + test +end diff --git a/2024/ruby/spec/advent_02_spec.rb b/2024/ruby/spec/advent_02_spec.rb index 6d9aec7..0947a14 100644 --- a/2024/ruby/spec/advent_02_spec.rb +++ b/2024/ruby/spec/advent_02_spec.rb @@ -2,8 +2,8 @@ require 'pry' require 'advent_02_red_nosed_reports' -describe "Report" do - context "with safe increasing levels" do +describe 'Report' do + context 'with safe increasing levels' do let(:levels) { [5, 6, 7, 8, 9, 10] } it 'is safe' do @@ -13,7 +13,7 @@ end end - context "with safe decreasing levels" do + context 'with safe decreasing levels' do let(:levels) { [5, 4, 3, 2, 1] } it 'is safe' do @@ -23,7 +23,7 @@ end end - context "with mixed levels" do + context 'with mixed levels' do let(:levels) { [5, 4, 6] } it 'is not safe' do @@ -33,7 +33,7 @@ end end - context "with bad adjacent levels" do + context 'with bad adjacent levels' do let(:levels) { [1, 2, 4, 8, 9] } it 'is not safe' do @@ -43,40 +43,40 @@ end end - context "with sample data" do + context 'with sample data' do let(:data) do File.readlines('spec/fixtures/advent-02-sample.txt').map do |e| e.chomp.split(' ').map(&:to_i) end end - it "calculates how many are safe" do + it 'calculates how many are safe' do safe = data.select { |levels| Report.new(levels).safe? } expect(safe.length).to be(2) end - it "calculates how many are safe with a dampener of 1" do + it 'calculates how many are safe with a dampener of 1' do safe = data.select { |levels| Report.new(levels).safe_with_dampener? } expect(safe.length).to be(4) end end - context "with puzzle data" do + context 'with puzzle data' do let(:data) do File.readlines('spec/fixtures/advent-02.txt').map do |e| e.chomp.split(' ').map(&:to_i) end end - it "calculates how many are safe" do + it 'calculates how many are safe' do safe = data.select { |levels| Report.new(levels).safe? } expect(safe.length).to be(660) end - it "calculates how many are safe with a dampener of 1" do + it 'calculates how many are safe with a dampener of 1' do safe = data.select { |levels| Report.new(levels).safe_with_dampener? } expect(safe.length).to be(689) diff --git a/2024/ruby/spec/advent_03_spec.rb b/2024/ruby/spec/advent_03_spec.rb index 5554323..710e902 100644 --- a/2024/ruby/spec/advent_03_spec.rb +++ b/2024/ruby/spec/advent_03_spec.rb @@ -2,14 +2,14 @@ require 'pry' require 'advent_03_mull_it_over' -describe "Muller" do - context "with uncorrupted pieces" do +describe 'Muller' do + context 'with uncorrupted pieces' do let(:data) { File.read('./spec/fixtures/advent-03-sample-ii.txt').chomp } it 'parses uncorrupted pieces' do muller = Muller.new(data) - expect(muller.uncorrupted_pieces).to eq(["mul(2,4)", "mul(8,5)"]) + expect(muller.uncorrupted_pieces).to eq(['mul(2,4)', 'mul(8,5)']) end it 'mulls uncorrupted data' do @@ -19,13 +19,13 @@ end end - context "with sample data" do + context 'with sample data' do let(:data) { File.read('./spec/fixtures/advent-03-sample.txt').chomp } it 'parses the pieces' do muller = Muller.new(data) - expect(muller.pieces).to eq(["mul(2,4)", "mul(5,5)", "mul(11,8)", "mul(8,5)"]) + expect(muller.pieces).to eq(['mul(2,4)', 'mul(5,5)', 'mul(11,8)', 'mul(8,5)']) end it 'mulls the data' do @@ -35,7 +35,7 @@ end end - context "with puzzle data" do + context 'with puzzle data' do let(:data) { File.read('./spec/fixtures/advent-03.txt').chomp } it 'mulls the data' do diff --git a/2024/ruby/spec/advent_04_spec.rb b/2024/ruby/spec/advent_04_spec.rb index d737029..fc222b2 100644 --- a/2024/ruby/spec/advent_04_spec.rb +++ b/2024/ruby/spec/advent_04_spec.rb @@ -1,25 +1,25 @@ require 'spec_helper' require 'advent_04_ceres_search' -describe "WordSearch" do - it "counts horizontal" do +describe 'WordSearch' do + it 'counts horizontal' do data = [ - ["X", "M", "A", "S"], - [".", ".", ".", "."], - [".", ".", ".", "."], - [".", ".", ".", "."] + ['X', 'M', 'A', 'S'], + ['.', '.', '.', '.'], + ['.', '.', '.', '.'], + ['.', '.', '.', '.'] ] search = WordSearch.new(data) expect(search.horizonal_count).to eq(1) end - it "counts horizontal in reverse" do + it 'counts horizontal in reverse' do data = [ - ["S", "A", "M", "X"], - [".", ".", ".", "."], - [".", ".", ".", "."], - [".", ".", ".", "."] + ['S', 'A', 'M', 'X'], + ['.', '.', '.', '.'], + ['.', '.', '.', '.'], + ['.', '.', '.', '.'] ] search = WordSearch.new(data) @@ -27,12 +27,12 @@ expect(search.horizonal_count).to eq(1) end - it "counts vertical" do + it 'counts vertical' do data = [ - ["X", ".", ".", "."], - ["M", ".", ".", "."], - ["A", ".", ".", "."], - ["S", ".", ".", "."] + ['X', '.', '.', '.'], + ['M', '.', '.', '.'], + ['A', '.', '.', '.'], + ['S', '.', '.', '.'] ] search = WordSearch.new(data) @@ -40,12 +40,12 @@ expect(search.vertical_count).to eq(1) end - it "counts vertical in reverse" do + it 'counts vertical in reverse' do data = [ - ["S", ".", ".", "."], - ["A", ".", ".", "."], - ["M", ".", ".", "."], - ["X", ".", ".", "."] + ['S', '.', '.', '.'], + ['A', '.', '.', '.'], + ['M', '.', '.', '.'], + ['X', '.', '.', '.'] ] search = WordSearch.new(data) @@ -53,12 +53,12 @@ expect(search.vertical_count).to eq(1) end - it "counts downward diagonal" do + it 'counts downward diagonal' do data = [ - ["X", ".", ".", "."], - [".", "M", ".", "."], - [".", ".", "A", "."], - [".", ".", ".", "S"] + ['X', '.', '.', '.'], + ['.', 'M', '.', '.'], + ['.', '.', 'A', '.'], + ['.', '.', '.', 'S'] ] search = WordSearch.new(data) @@ -66,12 +66,12 @@ expect(search.diagonal_count).to eq(1) end - it "counts downward reverse diagonal" do + it 'counts downward reverse diagonal' do data = [ - ["S", ".", ".", "."], - [".", "A", ".", "."], - [".", ".", "M", "."], - [".", ".", ".", "X"] + ['S', '.', '.', '.'], + ['.', 'A', '.', '.'], + ['.', '.', 'M', '.'], + ['.', '.', '.', 'X'] ] search = WordSearch.new(data) @@ -79,12 +79,12 @@ expect(search.diagonal_count).to eq(1) end - it "counts upward diagonal" do + it 'counts upward diagonal' do data = [ - [".", ".", ".", "S"], - [".", ".", "A", "."], - [".", "M", ".", "."], - ["X", ".", ".", "."] + ['.', '.', '.', 'S'], + ['.', '.', 'A', '.'], + ['.', 'M', '.', '.'], + ['X', '.', '.', '.'] ] search = WordSearch.new(data) @@ -92,12 +92,12 @@ expect(search.diagonal_count).to eq(1) end - it "counts upward reverse diagonal" do + it 'counts upward reverse diagonal' do data = [ - [".", ".", ".", "X"], - [".", ".", "M", "."], - [".", "A", ".", "."], - ["S", ".", ".", "."] + ['.', '.', '.', 'X'], + ['.', '.', 'M', '.'], + ['.', 'A', '.', '.'], + ['S', '.', '.', '.'] ] search = WordSearch.new(data) @@ -105,12 +105,12 @@ expect(search.diagonal_count).to eq(1) end - it "counts crossing diagonals" do + it 'counts crossing diagonals' do data = [ - ["X", ".", ".", "S"], - [".", "M", "A", "."], - [".", "M", "A", "."], - ["X", ".", ".", "S"] + ['X', '.', '.', 'S'], + ['.', 'M', 'A', '.'], + ['.', 'M', 'A', '.'], + ['X', '.', '.', 'S'] ] search = WordSearch.new(data) @@ -118,12 +118,12 @@ expect(search.diagonal_count).to eq(2) end - it "counts cross diagonals" do + it 'counts cross diagonals' do data = [ - ["S", ".", ".", "S"], - [".", "A", "A", "."], - [".", "M", "M", "."], - ["X", ".", ".", "X"] + ['S', '.', '.', 'S'], + ['.', 'A', 'A', '.'], + ['.', 'M', 'M', '.'], + ['X', '.', '.', 'X'] ] search = WordSearch.new(data) @@ -131,13 +131,13 @@ expect(search.diagonal_count).to eq(2) end - it "finds no matches" do + it 'finds no matches' do data = [ - ["X", "X", "X", "X"], - ["X", "X", "X", "M"], - ["X", "X", "X", "X"], - ["A", "X", "X", "X"], - ["X", "S", "X", "X"], + %w[X X X X], + %w[X X X M], + %w[X X X X], + %w[A X X X], + %w[X S X X] ] search = WordSearch.new(data) @@ -145,65 +145,65 @@ expect(search.diagonal_count).to eq(0) end - it "counts diagonals" do - data =[ - [".", "S", ".", ".", ".", ".", ".", "S", ".", "."], - [".", ".", "A", ".", ".", ".", "A", ".", ".", "."], - [".", ".", ".", "M", ".", "M", ".", ".", ".", "."], - [".", ".", ".", ".", "X", ".", ".", ".", ".", "."], - [".", ".", ".", "M", ".", "M", ".", ".", ".", "."], - [".", ".", "A", ".", ".", ".", "A", ".", ".", "."], - [".", "S", ".", ".", ".", ".", ".", "S", ".", "."], + it 'counts diagonals' do + data = [ + ['.', 'S', '.', '.', '.', '.', '.', 'S', '.', '.'], + ['.', '.', 'A', '.', '.', '.', 'A', '.', '.', '.'], + ['.', '.', '.', 'M', '.', 'M', '.', '.', '.', '.'], + ['.', '.', '.', '.', 'X', '.', '.', '.', '.', '.'], + ['.', '.', '.', 'M', '.', 'M', '.', '.', '.', '.'], + ['.', '.', 'A', '.', '.', '.', 'A', '.', '.', '.'], + ['.', 'S', '.', '.', '.', '.', '.', 'S', '.', '.'] ] search = WordSearch.new(data) - expect(search.diagonal_top_left_word(3, 4)).to eq("XMAS") - expect(search.diagonal_top_right_word(3, 4)).to eq("XMAS") - expect(search.diagonal_bottom_right_word(3, 4)).to eq("XMAS") - expect(search.diagonal_bottom_left_word(3, 4)).to eq("XMAS") + expect(search.diagonal_top_left_word(3, 4)).to eq('XMAS') + expect(search.diagonal_top_right_word(3, 4)).to eq('XMAS') + expect(search.diagonal_bottom_right_word(3, 4)).to eq('XMAS') + expect(search.diagonal_bottom_left_word(3, 4)).to eq('XMAS') expect(search.diagonal_count).to eq(4) expect(search.word_count).to eq(4) end - it "counts cross words" do + it 'counts cross words' do data = [ - ["M", ".", "S"], - [".", "A", "."], - ["M", ".", "S"], - ] + ['M', '.', 'S'], + ['.', 'A', '.'], + ['M', '.', 'S'] + ] search = WordSearch.new(data) - expect(search.cross_word_at?(1,1)).to eq(true) + expect(search.cross_word_at?(1, 1)).to be(true) expect(search.cross_word_count).to eq(1) end - context "with sample data" do + context 'with sample data' do let(:data) do File.readlines('./spec/fixtures/advent-04-sample.txt').map { |l| l.chomp.chars } end - it "finds counts of XMAS" do + it 'finds counts of XMAS' do search = WordSearch.new(data) expect(search.word_count).to eq(18) end end - context "with puzzle data" do + context 'with puzzle data' do let(:data) do File.readlines('./spec/fixtures/advent-04.txt').map { |l| l.chomp.chars } end - it "finds counts of XMAS" do + it 'finds counts of XMAS' do search = WordSearch.new(data) expect(search.word_count).to eq(2447) end - it "finds cross word counts" do + it 'finds cross word counts' do search = WordSearch.new(data) expect(search.cross_word_count).to eq(1868)