-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Rewrite from scratch the pretty printer.
- Loading branch information
1 parent
b417c38
commit 0ea1662
Showing
10 changed files
with
133 additions
and
89 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Minesweeper | ||
module Console | ||
module PrettyPrinter | ||
class HeaderPrinter | ||
def initialize(separator) | ||
raise StandardError if separator.nil? | ||
end | ||
|
||
def print(number_of_columns) | ||
raise StandardError if number_of_columns == 0 | ||
raise StandardError if number_of_columns < 0 | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
17 changes: 17 additions & 0 deletions
17
lib/minesweeper/console/prettyprinter/minefield_pretty_printer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'minesweeper' | ||
require_relative 'empty_minefield_error' | ||
|
||
module Minesweeper | ||
module Console | ||
module PrettyPrinter | ||
class MinefieldPrettyPrinter | ||
def initialize | ||
end | ||
|
||
def print | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Minesweeper | ||
module Console | ||
module PrettyPrinter | ||
class RowPrinter | ||
def initialize(separator) | ||
raise StandardError if separator.nil? | ||
@separator = separator | ||
end | ||
|
||
def print(row_number, raw_row) | ||
result = row_number.to_s + @separator | ||
raw_row.each_char do |c| | ||
result << c + @separator | ||
end | ||
result | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
This file was deleted.
Oops, something went wrong.
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
test/minesweeper/console/prettyprinter/header_printer_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'minesweeper/console/prettyprinter/header_printer' | ||
require_relative '../../../test_helper' | ||
|
||
module Minesweeper | ||
module Console | ||
module PrettyPrinter | ||
class HeaderPrinterTest < Test::Unit::TestCase | ||
SEP = '§' | ||
|
||
def test_raises_error_when_initialized_with_nil_separator | ||
assert_raise(StandardError) { HeaderPrinter.new(nil) } | ||
end | ||
|
||
def test_raises_error_when_number_of_columns_is_zero | ||
printer = HeaderPrinter.new(SEP) | ||
assert_raise(StandardError) { printer.print(0) } | ||
end | ||
|
||
def test_raises_error_when_number_of_columns_is_negative | ||
printer = HeaderPrinter.new(SEP) | ||
assert_raise(StandardError) { printer.print(-1) } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
14 changes: 14 additions & 0 deletions
14
test/minesweeper/console/prettyprinter/minefield_pretty_printer_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'minesweeper/console/prettyprinter/minefield_pretty_printer' | ||
require 'minesweeper/console/prettyprinter/empty_minefield_error' | ||
require_relative '../../../test_helper' | ||
require_relative 'empty_minefield' | ||
|
||
module Minesweeper | ||
module Console | ||
module PrettyPrinter | ||
class MinefieldPrettyPrinterTest < Test::Unit::TestCase | ||
end | ||
end | ||
end | ||
end | ||
|
37 changes: 37 additions & 0 deletions
37
test/minesweeper/console/prettyprinter/row_printer_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'minesweeper/console/prettyprinter/row_printer' | ||
require_relative '../../../test_helper' | ||
|
||
module Minesweeper | ||
module Console | ||
module PrettyPrinter | ||
class RowPrinterTest < Test::Unit::TestCase | ||
SEP = '§' | ||
|
||
def setup | ||
@printer = RowPrinter.new(SEP) | ||
end | ||
|
||
def test_raise_error_when_initialized_with_a_nil_separator | ||
assert_raise(StandardError) { RowPrinter.new(nil) } | ||
end | ||
|
||
def test_prints_row_number_first | ||
assert_match(/^0.*$/, @printer.print(0, 'HHHH')) | ||
end | ||
|
||
def test_prints_separator_after_row_number | ||
assert_match(/^\d+#{SEP}.*$/, @printer.print(0, 'HHHH')) | ||
end | ||
|
||
def test_prints_each_character_of_the_sequence_separated_by_separator | ||
assert_match(/^\d+#{SEP}X#{SEP}Y#{SEP}Z.*$/, @printer.print(0, 'XYZ')) | ||
end | ||
|
||
def test_appends_separator | ||
assert_match(/^.*#{SEP}$/, @printer.print(0, 'XYZ')) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|