Skip to content

Commit

Permalink
WIP: Rewrite from scratch the pretty printer.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienatplumbee committed May 10, 2015
1 parent b417c38 commit 0ea1662
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 89 deletions.
38 changes: 0 additions & 38 deletions lib/minesweeper/console/minefield_pretty_printer.rb

This file was deleted.

17 changes: 17 additions & 0 deletions lib/minesweeper/console/prettyprinter/header_printer.rb
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 lib/minesweeper/console/prettyprinter/minefield_pretty_printer.rb
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

21 changes: 21 additions & 0 deletions lib/minesweeper/console/prettyprinter/row_printer.rb
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

51 changes: 0 additions & 51 deletions test/minesweeper/console/minefield_pretty_printer_test.rb

This file was deleted.

File renamed without changes.
27 changes: 27 additions & 0 deletions test/minesweeper/console/prettyprinter/header_printer_test.rb
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

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 test/minesweeper/console/prettyprinter/row_printer_test.rb
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

0 comments on commit 0ea1662

Please sign in to comment.