Class: HistogramTest
- Includes:
- MoreMath
- Defined in:
- tests/histogram_test.rb
Constant Summary
Constants included from MoreMath
MoreMath::Infinity, MoreMath::STD_NORMAL_DISTRIBUTION, MoreMath::VERSION, MoreMath::VERSION_ARRAY, MoreMath::VERSION_BUILD, MoreMath::VERSION_MAJOR, MoreMath::VERSION_MINOR
Instance Method Summary collapse
- #output_histogram(histogram, width = 65) ⇒ Object private
- #test_histogram ⇒ Object
- #test_histogram_display ⇒ Object
- #test_histogram_display_utf8 ⇒ Object
- #test_histogram_display_with_counts ⇒ Object
- #test_histogram_display_with_counts_lots ⇒ Object
- #test_histogram_display_with_counts_utf8 ⇒ Object
- #test_histogram_display_with_counts_utf8_product ⇒ Object
- #test_histogram_display_with_counts_utf8_product_width_75_percent ⇒ Object
Instance Method Details
#output_histogram(histogram, width = 65) ⇒ Object (private)
143 144 145 146 147 |
# File 'tests/histogram_test.rb', line 143 def output_histogram(histogram, width = 65) $stdout.puts histogram.display $stdout, width $stdout.puts end |
#test_histogram ⇒ Object
10 11 12 13 14 15 |
# File 'tests/histogram_test.rb', line 10 def test_histogram sequence = Sequence.new [ 1, 2, 3, 0, 2 ] histogram = Histogram.new sequence, 3 assert_equal [ [0.0, 1.0, 2], [1.0, 2.0, 2], [2.0, 3.0, 1] ], histogram.each_bin.map(&:to_a) end |
#test_histogram_display ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'tests/histogram_test.rb', line 17 def test_histogram_display sequence = Sequence.new [ 1, 2, 3, 0, 2 ] histogram = Histogram.new sequence, 3 def histogram.utf8? false end assert_equal [[2.0, 3.0, 1], [1.0, 2.0, 2], [0.0, 1.0, 2]], histogram.instance_eval { rows } output = StringIO.new histogram.display output, 65 assert_equal <<~end, output.string 2.50000 -|************************* 1.50000 -|************************************************** 0.50000 -|************************************************** max_count=2 end end |
#test_histogram_display_utf8 ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'tests/histogram_test.rb', line 70 def test_histogram_display_utf8 srand 1337 sequence = Sequence.new 1000.times.map { rand(10) } histogram = Histogram.new sequence, 3 def histogram.utf8? true end output = StringIO.new histogram.display output, 65 assert_equal <<~end, output.string 7.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ 4.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇ 1.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ max_count=420 end end |
#test_histogram_display_with_counts ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'tests/histogram_test.rb', line 35 def test_histogram_display_with_counts sequence = Sequence.new [ 1, 2, 3, 0, 2 ] histogram = Histogram.new sequence, with_counts: true, bins: 3 def histogram.utf8? false end assert_equal [[2.0, 3.0, 1], [1.0, 2.0, 2], [0.0, 1.0, 2]], histogram.instance_eval { rows } output = StringIO.new histogram.display output, 65 assert_equal <<~end, output.string 2.50000 -|************************ 1 1.50000 -|************************************************ 2 0.50000 -|************************************************ 2 max_count=2 end end |
#test_histogram_display_with_counts_lots ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'tests/histogram_test.rb', line 53 def test_histogram_display_with_counts_lots srand 1337 sequence = Sequence.new 1000.times.map { rand(10) * rand(10) } histogram = Histogram.new sequence, with_counts: true, bins: 3 def histogram.utf8? false end output = StringIO.new histogram.display output, 65 assert_equal <<~end, output.string 67.50000 -|***** 81 40.50000 -|************* 206 13.50000 -|********************************************** 713 max_count=713 end end |
#test_histogram_display_with_counts_utf8 ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'tests/histogram_test.rb', line 87 def test_histogram_display_with_counts_utf8 srand 1337 sequence = Sequence.new 1000.times.map { rand(10) } histogram = Histogram.new sequence, with_counts: true, bins: 3 def histogram.utf8? true end output = StringIO.new histogram.display output, 65 assert_equal <<~end, output.string 7.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇ 295 4.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇ 285 1.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ 420 max_count=420 end end |
#test_histogram_display_with_counts_utf8_product ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'tests/histogram_test.rb', line 104 def test_histogram_display_with_counts_utf8_product srand 1337 sequence = Sequence.new 1000.times.map { rand(10) * rand(10) } histogram = Histogram.new sequence, with_counts: true, bins: 3 def histogram.utf8? true end output = StringIO.new histogram.display output, 65 assert_equal <<~end, output.string 67.50000 -|⣿⣿⣿⣿⣿ 81 40.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ 206 13.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ 713 max_count=713 end end |
#test_histogram_display_with_counts_utf8_product_width_75_percent ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'tests/histogram_test.rb', line 121 def test_histogram_display_with_counts_utf8_product_width_75_percent srand 1337 sequence = Sequence.new 1000.times.map { rand(10) * rand(10) } histogram = Histogram.new sequence, with_counts: true, bins: 3 def histogram.utf8? true end def histogram.terminal_width 80 end output = StringIO.new histogram.display output, '90%' assert_equal <<~end, output.string 67.50000 -|⣿⣿⣿⣿⣿⡇ 81 40.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ 206 13.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ 713 max_count=713 end end |