Skip to content

Commit

Permalink
Write tests to the TextChart#to_s
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavothecoder committed Dec 17, 2023
1 parent 4546aac commit c0e0848
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
4 changes: 2 additions & 2 deletions lib/text_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def find_references

# @return [String]
def to_s
@designer.draw_header
@designer.draw_axis.join
@designer.draw_axis
@designer.draw_header.join
end
end
4 changes: 2 additions & 2 deletions lib/text_chart/size_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def calculate_number_of_rows
result += x_axis_row

reference_row = 1
number_of_references = [@data.size / 2, 1].max
number_of_references = calculate_number_of_references
number_of_references.times { result += reference_row }

reference_spacing = 2
Expand All @@ -80,7 +80,7 @@ def calculate_y_axis_size

# @return [Integer]
def calculate_number_of_references
@number_of_references ||= [(@data.size / 2).round, 1].max
@number_of_references ||= [(@data.size.to_f / 2.0).round, 1].max
end

# @return [Integer]
Expand Down
1 change: 0 additions & 1 deletion test/text_chart/designer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class TextChart::DesignerTest < Test::Unit::TestCase
no_sample_designer = TextChart.new("No sample", "Testing", []).designer
small_sample_designer = TextChart.new("Small sample", "Testing", [*1..10]).designer

# TODO: create a method to return the printable chart
no_sample_result = no_sample_designer.draw_axis.join
small_sample_result = small_sample_designer.draw_axis.join

Expand Down
49 changes: 28 additions & 21 deletions test/text_chart_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,32 @@ class TextChartTest < Test::Unit::TestCase
assert_equal small_sample_refs, [10, 8, 6, 4, 2]
end

# test "text chart with integer values" do
# small_sample = TextChart.new("Small sample", "Testing", [*1..5])
# # medium_chart = TextChart.new("medium data", [*1..10], "testing")
# # big_chart = TextChart.new("big data", [*1..20], "testing")

# small_sample_result = small_sample.generate

# assert_equal small_sample_result, <<~EXPECTED
# Small sample
# Goal: Testing

# 6 |
# | 5
# | 4 ###
# 3 | 3 ### ###
# | 2 ### ### ###
# | 1 ### ### ### ###
# 0 | ### ### ### ### ###
# --------------------------------------------------
# EXPECTED
# end
test "#to_s" do
no_sample = TextChart.new("No sample", "Testing", [])
small_sample = TextChart.new("Small sample", "Testing", [*1..5])

no_sample_result = no_sample.to_s
small_sample_result = small_sample.to_s

assert_equal no_sample_result, <<~EXPECTED
No sample
Goal: Testing
0 |
----------
EXPECTED
assert_equal small_sample_result, <<~EXPECTED
Small sample
Goal: Testing
5 |
|
|
3 |
|
|
1 |
--------------------------------------------------
EXPECTED
end
end

0 comments on commit c0e0848

Please sign in to comment.