Skip to content

Commit

Permalink
Merge pull request #8 from gustavothecoder/prepare_first_public_version
Browse files Browse the repository at this point in the history
Prepare first public version
  • Loading branch information
gustavothecoder authored Dec 24, 2023
2 parents a7683a6 + 35c4eae commit 753a6d4
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 46 deletions.
46 changes: 16 additions & 30 deletions lib/text_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,23 @@
require_relative "text_chart/size_calculator"
require_relative "text_chart/designer"

# Last 5 races
# Goal: 3km in 16m
# AVG: 13
# This is the main class of the text_chart. After calling the `#to_s` method you'll receive a string
# representing the chart, just like this one:
#
# 18 |'''###
# 17 | ###
# 16 | ###
# 15 |'''###'''''''''''''''''''''''''''###
# 14 | ### ###
# 13 | ### ###
# 12 | ### ###
# 11 | ### ###
# 10 |'''###'''''''###'''''''''''''''''###'''''''###
# 9 |'''###'''''''###'''''''### ### ###
# 8 | ### ### ### ### ###
# 7 | ### ### ### ### ###
# 6 | ### ### ### ### ###
# 5 | ### ### ### ### ###
# 4 | ### ### ### ### ###
# 3 | ### ### ### ### ###
# 2 | ### ### ### ### ###
# 1 | ### ### ### ### ###
# 0 | ### ### ### ### ###
# --------------------------------------------------
# text_chart demonstration
# Goal: Show you how cool this is
#
# Requirements:
# 1. The "Last 5 races" should be a customizable string;
# 2. The "Goal" should be a customizable string;
# 3. The "AVG" should consider only the displayed data;
# 4. The chart should support time, integers and floats;
# 5. The y axi should change based on the highest value.

# 9 |'''''''''''''''''''''''''''''''''''''''''''''''''''''###
# 8 | ###
# 7 | ###
# 6 |'''''''''''''### ###
# 5 |'''''''''''''###'''''''''''''''''''''''''''### ###
# 4 |'''''''''''''###'''''''''''''''''''''''''''###'''''''###'''''''###
# 3 |'''###'''''''###'''''''''''''''''### ### ### ###
# 2 | ### ### ### ### ### ###
# 1 | ### ### ### ### ### ###
# 0 |'''###'''''''###'''''''### ### ### ### ###
# ----------------------------------------------------------------------
class TextChart
class Error < StandardError; end

Expand All @@ -56,6 +41,7 @@ def initialize(title, goal, data)
# @return [String]
def to_s
@designer.draw_axis
@designer.draw_bars
@designer.draw_header.join
end

Expand Down
8 changes: 4 additions & 4 deletions test/text_chart/designer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ class TextChart::DesignerTest < Test::Unit::TestCase
with_zero_designer = TextChart.new(
"With zero", "Testing", [*0..5].shuffle(random: Random.new(1))
).designer
duplicated_and_gaps = TextChart.new(
gaps = TextChart.new(
"Duplicated and gaps", "Testing", [*1..3, 6, 12].shuffle(random: Random.new(1))
).designer

sorted_result = sorted_designer.draw_bars.join
random_order_result = random_order_designer.draw_bars.join
with_zero_result = with_zero_designer.draw_bars.join
duplicated_and_gaps_result = duplicated_and_gaps.draw_bars.join
gaps_result = gaps.draw_bars.join

expected_sorted_result = <<-END
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''###
Expand Down Expand Up @@ -125,7 +125,7 @@ class TextChart::DesignerTest < Test::Unit::TestCase
END
assert_equal with_zero_result, expected_with_zero_result

expected_duplicated_and_gaps_result = <<-END
expected_gaps_result = <<-END
'''''''''''''''''''''''###
###
###
Expand All @@ -141,6 +141,6 @@ class TextChart::DesignerTest < Test::Unit::TestCase
### ### ### ### ###
END
assert_equal duplicated_and_gaps_result, expected_duplicated_and_gaps_result
assert_equal gaps_result, expected_gaps_result
end
end
73 changes: 61 additions & 12 deletions test/text_chart_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,78 @@ class TextChartTest < Test::Unit::TestCase

test "#to_s" do
no_sample = TextChart.new("No sample", "Testing", [])
small_sample = TextChart.new("Small sample", "Testing", [*1..5])
sorted_sample = TextChart.new("Sorted sample", "Testing", [*1..10])
random_order_sample = TextChart.new(
"Random order sample", "Testing", [*1..10].shuffle(random: Random.new(1))
)
duplicated_and_gaps = TextChart.new(
"Duplicated and gaps sample", "Testing", [*0..3, 3, 6, 12].shuffle(random: Random.new(1))
)

no_sample_result = no_sample.to_s
small_sample_result = small_sample.to_s
sorted_result = sorted_sample.to_s
random_order_result = random_order_sample.to_s
duplicated_and_gaps_result = duplicated_and_gaps.to_s

assert_equal no_sample_result, <<~EXPECTED
No sample
Goal: Testing
0 |
0 |'''###
----------
EXPECTED
assert_equal small_sample_result, <<~EXPECTED
Small sample
assert_equal sorted_result, <<~EXPECTED
Sorted sample
Goal: Testing
5 |
4 |
3 |
2 |
1 |
0 |
--------------------------------------------------
10 |'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''###
9 |'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''### ###
8 |'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''### ### ###
7 |'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''### ### ### ###
6 |'''''''''''''''''''''''''''''''''''''''''''''''''''''### ### ### ### ###
5 |'''''''''''''''''''''''''''''''''''''''''''### ### ### ### ### ###
4 |'''''''''''''''''''''''''''''''''### ### ### ### ### ### ###
3 |'''''''''''''''''''''''### ### ### ### ### ### ### ###
2 |'''''''''''''### ### ### ### ### ### ### ### ###
1 |'''### ### ### ### ### ### ### ### ### ###
0 | ### ### ### ### ### ### ### ### ### ###
----------------------------------------------------------------------------------------------------
EXPECTED
assert_equal random_order_result, <<~EXPECTED
Random order sample
Goal: Testing
10 |'''''''''''''###
9 |'''''''''''''###'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''###
8 |'''''''''''''###'''''''''''''''''''''''''''''''''''''''''''''''''''''''''### ###
7 |'''''''''''''###'''''''### ### ###
6 |'''''''''''''###'''''''###'''''''''''''''''''''''''''''''''''''''''''''''###'''''''###'''''''###
5 |'''''''''''''###'''''''###'''''''### ### ### ###
4 |'''''''''''''###'''''''###'''''''###'''''''''''''''''### ### ### ###
3 |'''### ### ### ### ### ### ### ###
2 |'''###'''''''###'''''''###'''''''###'''''''''''''''''###'''''''### ### ### ###
1 |'''###'''''''###'''''''###'''''''###'''''''### ### ### ### ### ###
0 | ### ### ### ### ### ### ### ### ### ###
----------------------------------------------------------------------------------------------------
EXPECTED
assert_equal duplicated_and_gaps_result, <<~EXPECTED
Duplicated and gaps sample
Goal: Testing
12 |'''###
11 | ###
10 | ###
9 | ###
8 | ###
7 | ###
6 |'''###'''''''''''''''''''''''''''''''''''''''''''''''''''''''''###
5 | ### ###
4 | ### ###
3 |'''###'''''''''''''''''''''''''''''''''''''###'''''''### ###
2 |'''###'''''''### ### ### ###
1 |'''###'''''''###'''''''### ### ### ###
0 |'''###'''''''###'''''''###'''''''### ### ### ###
----------------------------------------------------------------------
EXPECTED
end
end

0 comments on commit 753a6d4

Please sign in to comment.