From 464c3ce0681d64b46a675fee62077c1d7820c34c Mon Sep 17 00:00:00 2001 From: Matt McMahand Date: Thu, 5 Dec 2024 13:24:25 -0500 Subject: [PATCH] rubocopness and file renaming --- 2024/ruby/lib/advent_01_hystorian_hysteria.rb | 4 +- 2024/ruby/lib/advent_02_red_nosed_reports.rb | 4 +- 2024/ruby/lib/advent_03_mull_it_over.rb | 2 +- 2024/ruby/lib/advent_04_ceres_search.rb | 20 +- ...b => advent_01_hystorian_hysteria_spec.rb} | 26 +-- ...rb => advent_02_red_nosed_reports_spec.rb} | 43 ++-- 2024/ruby/spec/advent_03_mull_it_over_spec.rb | 52 +++++ 2024/ruby/spec/advent_03_spec.rb | 53 ----- 2024/ruby/spec/advent_04_ceres_search_spec.rb | 212 ++++++++++++++++++ 2024/ruby/spec/advent_04_spec.rb | 212 ------------------ 2024/ruby/spec/spec_helper.rb | 2 +- 11 files changed, 314 insertions(+), 316 deletions(-) rename 2024/ruby/spec/{advent_01_spec.rb => advent_01_hystorian_hysteria_spec.rb} (59%) rename 2024/ruby/spec/{advent_02_spec.rb => advent_02_red_nosed_reports_spec.rb} (56%) create mode 100644 2024/ruby/spec/advent_03_mull_it_over_spec.rb delete mode 100644 2024/ruby/spec/advent_03_spec.rb create mode 100644 2024/ruby/spec/advent_04_ceres_search_spec.rb delete mode 100644 2024/ruby/spec/advent_04_spec.rb diff --git a/2024/ruby/lib/advent_01_hystorian_hysteria.rb b/2024/ruby/lib/advent_01_hystorian_hysteria.rb index 61e061d..a57278f 100644 --- a/2024/ruby/lib/advent_01_hystorian_hysteria.rb +++ b/2024/ruby/lib/advent_01_hystorian_hysteria.rb @@ -1,8 +1,8 @@ -require 'pry' +require "pry" class DistanceCalculator def initialize(list_one, list_two) - raise 'lists must be the same length' if list_one.length != list_two.length + raise "lists must be the same length" if list_one.length != list_two.length @list_one = list_one @list_two = list_two diff --git a/2024/ruby/lib/advent_02_red_nosed_reports.rb b/2024/ruby/lib/advent_02_red_nosed_reports.rb index b64d901..b321504 100644 --- a/2024/ruby/lib/advent_02_red_nosed_reports.rb +++ b/2024/ruby/lib/advent_02_red_nosed_reports.rb @@ -6,7 +6,7 @@ def initialize(levels) end def initial_direction(levels) - levels.length > 1 && levels[0] < levels[1] ? 'increasing' : 'decreasing' + levels.length > 1 && levels[0] < levels[1] ? "increasing" : "decreasing" end def safe_with_dampener? @@ -44,7 +44,7 @@ def safe? end def valid_direction?(direction, level, prev) - (prev < level && direction == 'increasing') || (prev > level && direction == 'decreasing') + (prev < level && direction == "increasing") || (prev > level && direction == "decreasing") end def adjacent_safe?(prev, level) diff --git a/2024/ruby/lib/advent_03_mull_it_over.rb b/2024/ruby/lib/advent_03_mull_it_over.rb index cc0d827..e749462 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 f5e3aa8..412c635 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,16 +19,16 @@ 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] * '' + data[row][first..last] * "" end def horizontal?(row, col) @@ -38,7 +38,7 @@ def horizontal?(row, col) def vertical_word(row, col) (row..row + word.length - 1).map do |pos| letter_at(pos, col) - end * '' + end * "" end def vertical?(row, col) @@ -48,25 +48,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) - end * '' + end * "" end def diagonal_top_right_word(row, col) (0..word.length - 1).map do |pos| letter_at(row - pos, col + pos) - end * '' + end * "" end def diagonal_bottom_right_word(row, col) (0..word.length - 1).map do |pos| letter_at(row + pos, col + pos) - end * '' + end * "" end def diagonal_bottom_left_word(row, col) (0..word.length - 1).map do |pos| letter_at(row + pos, col - pos) - end * '' + end * "" end def match?(str) @@ -74,7 +74,7 @@ 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) diff --git a/2024/ruby/spec/advent_01_spec.rb b/2024/ruby/spec/advent_01_hystorian_hysteria_spec.rb similarity index 59% rename from 2024/ruby/spec/advent_01_spec.rb rename to 2024/ruby/spec/advent_01_hystorian_hysteria_spec.rb index e9c24ab..f6edb88 100644 --- a/2024/ruby/spec/advent_01_spec.rb +++ b/2024/ruby/spec/advent_01_hystorian_hysteria_spec.rb @@ -1,22 +1,22 @@ -require 'spec_helper' -require 'advent_01_hystorian_hysteria' +require "spec_helper" +require "advent_01_hystorian_hysteria" -describe 'DistanceCalculator' do +describe "DistanceCalculator" do let(:data) do - File.readlines('./spec/fixtures/advent-01.txt').each do |line| - line.chomp.gsub(/\s+/, ' ') + File.readlines("./spec/fixtures/advent-01.txt").each do |line| + line.chomp.gsub(/\s+/, " ") end end let(:list_one) do - data.map { |line| line.split(' ')[0].to_i } + data.map { |line| line.split(" ")[0].to_i } end let(:list_two) do - data.map { |line| line.split(' ')[1].to_i } + data.map { |line| line.split(" ")[1].to_i } end - it 'calculates distance' do + it "calculates distance" do calc = DistanceCalculator.new([], []) result = calc.distance(1, 3) @@ -24,13 +24,13 @@ expect(result).to be(2) end - it 'calculates total distance' do + it "calculates total distance" do calc = DistanceCalculator.new(list_one, list_two) expect(calc.total_distance).to eq(2_166_959) end - it 'calculates similarity distance with matching number' do + it "calculates similarity distance with matching number" do a = [3, 4, 2, 1, 3, 3] b = [4, 3, 5, 3, 9, 3] calc = DistanceCalculator.new(a, b) @@ -38,7 +38,7 @@ expect(calc.similarity(4)).to eq(4) end - it 'calculates similarity distance with multiple matches' do + it "calculates similarity distance with multiple matches" do a = [3, 4, 2, 1, 3, 3] b = [4, 3, 5, 3, 9, 3] calc = DistanceCalculator.new(a, b) @@ -46,7 +46,7 @@ expect(calc.similarity(3)).to eq(9) end - it 'calculates similarity distance with missing number' do + it "calculates similarity distance with missing number" do a = [3, 4, 2, 1, 3, 3] b = [4, 3, 5, 3, 9, 3] calc = DistanceCalculator.new(a, b) @@ -54,7 +54,7 @@ expect(calc.similarity(2)).to eq(0) end - it 'calculates total similarity distance' do + it "calculates total similarity distance" do calc = DistanceCalculator.new(list_one, list_two) expect(calc.total_similarity_score).to eq(23_741_109) diff --git a/2024/ruby/spec/advent_02_spec.rb b/2024/ruby/spec/advent_02_red_nosed_reports_spec.rb similarity index 56% rename from 2024/ruby/spec/advent_02_spec.rb rename to 2024/ruby/spec/advent_02_red_nosed_reports_spec.rb index 0947a14..9affb9e 100644 --- a/2024/ruby/spec/advent_02_spec.rb +++ b/2024/ruby/spec/advent_02_red_nosed_reports_spec.rb @@ -1,82 +1,81 @@ -require 'spec_helper' -require 'pry' -require 'advent_02_red_nosed_reports' +require "spec_helper" +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 + it "is safe" do report = Report.new(levels) expect(report.safe?).to be(true) 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 + it "is safe" do report = Report.new(levels) expect(report.safe?).to be(true) end end - context 'with mixed levels' do + context "with mixed levels" do let(:levels) { [5, 4, 6] } - it 'is not safe' do + it "is not safe" do report = Report.new(levels) expect(report.safe?).to be(false) 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 + it "is not safe" do report = Report.new(levels) expect(report.safe?).to be(false) 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) + 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) + 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_mull_it_over_spec.rb b/2024/ruby/spec/advent_03_mull_it_over_spec.rb new file mode 100644 index 0000000..6aee231 --- /dev/null +++ b/2024/ruby/spec/advent_03_mull_it_over_spec.rb @@ -0,0 +1,52 @@ +require "spec_helper" +require "advent_03_mull_it_over" + +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)"]) + end + + it "mulls uncorrupted data" do + muller = Muller.new(data) + + expect(muller.uncorrupted_mull).to eq(48) + end + end + + 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)"]) + end + + it "mulls the data" do + muller = Muller.new(data) + + expect(muller.mull).to eq(161) + end + end + + context "with puzzle data" do + let(:data) { File.read("./spec/fixtures/advent-03.txt").chomp } + + it "mulls the data" do + muller = Muller.new(data) + + expect(muller.mull).to eq(165_225_049) + end + + it "mulls uncorrupted data" do + muller = Muller.new(data) + + expect(muller.uncorrupted_mull).to eq(108_830_766) + end + end +end diff --git a/2024/ruby/spec/advent_03_spec.rb b/2024/ruby/spec/advent_03_spec.rb deleted file mode 100644 index 710e902..0000000 --- a/2024/ruby/spec/advent_03_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'spec_helper' -require 'pry' -require 'advent_03_mull_it_over' - -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)']) - end - - it 'mulls uncorrupted data' do - muller = Muller.new(data) - - expect(muller.uncorrupted_mull).to eq(48) - end - end - - 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)']) - end - - it 'mulls the data' do - muller = Muller.new(data) - - expect(muller.mull).to eq(161) - end - end - - context 'with puzzle data' do - let(:data) { File.read('./spec/fixtures/advent-03.txt').chomp } - - it 'mulls the data' do - muller = Muller.new(data) - - expect(muller.mull).to eq(165_225_049) - end - - it 'mulls uncorrupted data' do - muller = Muller.new(data) - - expect(muller.uncorrupted_mull).to eq(108_830_766) - end - end -end diff --git a/2024/ruby/spec/advent_04_ceres_search_spec.rb b/2024/ruby/spec/advent_04_ceres_search_spec.rb new file mode 100644 index 0000000..6c193bc --- /dev/null +++ b/2024/ruby/spec/advent_04_ceres_search_spec.rb @@ -0,0 +1,212 @@ +require "spec_helper" +require "advent_04_ceres_search" + +describe "WordSearch" do + it "counts horizontal" do + data = [ + ["X", "M", "A", "S"], + [".", ".", ".", "."], + [".", ".", ".", "."], + [".", ".", ".", "."] + ] + + search = WordSearch.new(data) + expect(search.horizonal_count).to eq(1) + end + + it "counts horizontal in reverse" do + data = [ + ["S", "A", "M", "X"], + [".", ".", ".", "."], + [".", ".", ".", "."], + [".", ".", ".", "."] + ] + + search = WordSearch.new(data) + + expect(search.horizonal_count).to eq(1) + end + + it "counts vertical" do + data = [ + ["X", ".", ".", "."], + ["M", ".", ".", "."], + ["A", ".", ".", "."], + ["S", ".", ".", "."] + ] + + search = WordSearch.new(data) + + expect(search.vertical_count).to eq(1) + end + + it "counts vertical in reverse" do + data = [ + ["S", ".", ".", "."], + ["A", ".", ".", "."], + ["M", ".", ".", "."], + ["X", ".", ".", "."] + ] + + search = WordSearch.new(data) + + expect(search.vertical_count).to eq(1) + end + + it "counts downward diagonal" do + data = [ + ["X", ".", ".", "."], + [".", "M", ".", "."], + [".", ".", "A", "."], + [".", ".", ".", "S"] + ] + + search = WordSearch.new(data) + + expect(search.diagonal_count).to eq(1) + end + + it "counts downward reverse diagonal" do + data = [ + ["S", ".", ".", "."], + [".", "A", ".", "."], + [".", ".", "M", "."], + [".", ".", ".", "X"] + ] + + search = WordSearch.new(data) + + expect(search.diagonal_count).to eq(1) + end + + it "counts upward diagonal" do + data = [ + [".", ".", ".", "S"], + [".", ".", "A", "."], + [".", "M", ".", "."], + ["X", ".", ".", "."] + ] + + search = WordSearch.new(data) + + expect(search.diagonal_count).to eq(1) + end + + it "counts upward reverse diagonal" do + data = [ + [".", ".", ".", "X"], + [".", ".", "M", "."], + [".", "A", ".", "."], + ["S", ".", ".", "."] + ] + + search = WordSearch.new(data) + + expect(search.diagonal_count).to eq(1) + end + + it "counts crossing diagonals" do + data = [ + ["X", ".", ".", "S"], + [".", "M", "A", "."], + [".", "M", "A", "."], + ["X", ".", ".", "S"] + ] + + search = WordSearch.new(data) + + expect(search.diagonal_count).to eq(2) + end + + it "counts cross diagonals" do + data = [ + ["S", ".", ".", "S"], + [".", "A", "A", "."], + [".", "M", "M", "."], + ["X", ".", ".", "X"] + ] + + search = WordSearch.new(data) + + expect(search.diagonal_count).to eq(2) + end + + it "finds no matches" do + data = [ + %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) + + 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", ".", "."] + ] + + 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_count).to eq(4) + expect(search.word_count).to eq(4) + end + + it "counts cross words" do + data = [ + ["M", ".", "S"], + [".", "A", "."], + ["M", ".", "S"] + ] + + search = WordSearch.new(data) + + expect(search.cross_word_at?(1, 1)).to be(true) + expect(search.cross_word_count).to eq(1) + end + + 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 + search = WordSearch.new(data) + + expect(search.word_count).to eq(18) + end + end + + 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 + search = WordSearch.new(data) + + expect(search.word_count).to eq(2447) + end + + it "finds cross word counts" do + search = WordSearch.new(data) + + expect(search.cross_word_count).to eq(1868) + end + end +end diff --git a/2024/ruby/spec/advent_04_spec.rb b/2024/ruby/spec/advent_04_spec.rb deleted file mode 100644 index fc222b2..0000000 --- a/2024/ruby/spec/advent_04_spec.rb +++ /dev/null @@ -1,212 +0,0 @@ -require 'spec_helper' -require 'advent_04_ceres_search' - -describe 'WordSearch' do - it 'counts horizontal' do - data = [ - ['X', 'M', 'A', 'S'], - ['.', '.', '.', '.'], - ['.', '.', '.', '.'], - ['.', '.', '.', '.'] - ] - - search = WordSearch.new(data) - expect(search.horizonal_count).to eq(1) - end - - it 'counts horizontal in reverse' do - data = [ - ['S', 'A', 'M', 'X'], - ['.', '.', '.', '.'], - ['.', '.', '.', '.'], - ['.', '.', '.', '.'] - ] - - search = WordSearch.new(data) - - expect(search.horizonal_count).to eq(1) - end - - it 'counts vertical' do - data = [ - ['X', '.', '.', '.'], - ['M', '.', '.', '.'], - ['A', '.', '.', '.'], - ['S', '.', '.', '.'] - ] - - search = WordSearch.new(data) - - expect(search.vertical_count).to eq(1) - end - - it 'counts vertical in reverse' do - data = [ - ['S', '.', '.', '.'], - ['A', '.', '.', '.'], - ['M', '.', '.', '.'], - ['X', '.', '.', '.'] - ] - - search = WordSearch.new(data) - - expect(search.vertical_count).to eq(1) - end - - it 'counts downward diagonal' do - data = [ - ['X', '.', '.', '.'], - ['.', 'M', '.', '.'], - ['.', '.', 'A', '.'], - ['.', '.', '.', 'S'] - ] - - search = WordSearch.new(data) - - expect(search.diagonal_count).to eq(1) - end - - it 'counts downward reverse diagonal' do - data = [ - ['S', '.', '.', '.'], - ['.', 'A', '.', '.'], - ['.', '.', 'M', '.'], - ['.', '.', '.', 'X'] - ] - - search = WordSearch.new(data) - - expect(search.diagonal_count).to eq(1) - end - - it 'counts upward diagonal' do - data = [ - ['.', '.', '.', 'S'], - ['.', '.', 'A', '.'], - ['.', 'M', '.', '.'], - ['X', '.', '.', '.'] - ] - - search = WordSearch.new(data) - - expect(search.diagonal_count).to eq(1) - end - - it 'counts upward reverse diagonal' do - data = [ - ['.', '.', '.', 'X'], - ['.', '.', 'M', '.'], - ['.', 'A', '.', '.'], - ['S', '.', '.', '.'] - ] - - search = WordSearch.new(data) - - expect(search.diagonal_count).to eq(1) - end - - it 'counts crossing diagonals' do - data = [ - ['X', '.', '.', 'S'], - ['.', 'M', 'A', '.'], - ['.', 'M', 'A', '.'], - ['X', '.', '.', 'S'] - ] - - search = WordSearch.new(data) - - expect(search.diagonal_count).to eq(2) - end - - it 'counts cross diagonals' do - data = [ - ['S', '.', '.', 'S'], - ['.', 'A', 'A', '.'], - ['.', 'M', 'M', '.'], - ['X', '.', '.', 'X'] - ] - - search = WordSearch.new(data) - - expect(search.diagonal_count).to eq(2) - end - - it 'finds no matches' do - data = [ - %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) - - 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', '.', '.'] - ] - - 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_count).to eq(4) - expect(search.word_count).to eq(4) - end - - it 'counts cross words' do - data = [ - ['M', '.', 'S'], - ['.', 'A', '.'], - ['M', '.', 'S'] - ] - - search = WordSearch.new(data) - - expect(search.cross_word_at?(1, 1)).to be(true) - expect(search.cross_word_count).to eq(1) - end - - 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 - search = WordSearch.new(data) - - expect(search.word_count).to eq(18) - end - end - - 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 - search = WordSearch.new(data) - - expect(search.word_count).to eq(2447) - end - - it 'finds cross word counts' do - search = WordSearch.new(data) - - expect(search.cross_word_count).to eq(1868) - end - end -end diff --git a/2024/ruby/spec/spec_helper.rb b/2024/ruby/spec/spec_helper.rb index d7da771..19d7f15 100644 --- a/2024/ruby/spec/spec_helper.rb +++ b/2024/ruby/spec/spec_helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'pry' +require "pry" # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.