more_math 1.2.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01200b0474b98510b8405a12492684e8d871d3a406a697c2d7775a26efe8c2ae
4
- data.tar.gz: dfa50772aedbc2f2530e35e7c1825a128cdaa5a9a76781d12484c9b8a2a995f9
3
+ metadata.gz: d25fc8ea948e2f09f3ef35f3f7a583d113d17e3583502b2a4ad557761b32724d
4
+ data.tar.gz: bf6aab31d4d12fdc44772c2ee55deee97b4e8b84f7843358e56ca56660f9b58b
5
5
  SHA512:
6
- metadata.gz: c1dc76b84fed3a181158201798ce5fe6bff1ac22b2bff104b2f22ff5186104217c65ad1425cd676959f2358fc1b107722c3bc9bfcbd2ca6060fc033d927b47e6
7
- data.tar.gz: 90ad74b6b12f7735b088dc6bd06ccfbbe02af132718240a81eb8080c550a04c856698394c821441ddac4f7188524d02a006bf3579645a5b25a483a8e0dac568e
6
+ metadata.gz: dbfe1ea14d17e3726f9f72db9c14951aca55469856b09ba6181ae03629d8f02b175e244b4cda741bee3b8db9484a1ca8e6c4f6b6d1f9dfe5eea34aab33c9f815
7
+ data.tar.gz: e5b7f1d6746cfd26c1842e8a849ae4c4f73b7d8a139e6c7543e3b6f3620a5ecc4e49098a5ea1f870a5c4b305ec8a0959553add44e893860755e7677321b3cc04
data/CHANGES.md CHANGED
@@ -1,41 +1,59 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-07-12 v1.4.0
4
+
5
+ * Updated `project` method in Subset class with associated tests
6
+ + Maps dataset elements based on subset indices
7
+ + Ensures data size validation
8
+ + Comprehensive test cases for `project` functionality
9
+ * Added a list of features and example usage of the library in README
10
+ * Updated bundler behavior to clean up Gemfile.lock before installing gems
11
+ * Removed obsolete `binary` option from discover block in utility functions
12
+
13
+ ## 2024-09-30 v1.3.0
14
+
15
+ * **Added support for displaying histograms based on percentage of terminal width**
16
+ + Added `terminal_width` method to `Histogram` class
17
+ + Updated `display` method to take interpret the `width` parameter as a percentage string, e.g. `75%`
18
+ + Updated test cases to use the new `display` method with different widths
19
+ + Added a new test case for displaying histograms with counts and `75%` width
20
+
3
21
  ## 2024-09-30 v1.2.2
4
22
 
5
23
  ### Improvements
6
24
  * Refactor Histogram display logic for better UTF-8 support:
7
- + Extracted `output_row_with_count` and `output_row_without_count` methods
8
- + Updated test cases for histogram display with counts and UTF-8 support
25
+ + Extracted `output_row_with_count` and `output_row_without_count` methods
26
+ + Updated test cases for histogram display with counts and UTF-8 support
9
27
  * Update Rakefile to ignore `.utilsrc` file:
10
- - Add `.utilsrc` to `package_ignore` list in Rakefile
28
+ - Add `.utilsrc` to `package_ignore` list in Rakefile
11
29
 
12
30
  ## 2024-09-30 v1.2.1
13
31
 
14
32
  * Refactor histogram display logic for utf8 and ascii bars
15
- + *Improved `utf8_bar` method to handle fractional bar widths.*
16
- + *Updated test case in `histogram_test.rb` to reflect changes.*
33
+ + *Improved `utf8_bar` method to handle fractional bar widths.*
34
+ + *Updated test case in `histogram_test.rb` to reflect changes.*
17
35
 
18
36
  ## 2024-09-30 v1.2.0
19
37
 
20
38
  #### Significant Changes
21
39
 
22
40
  * Bumped version to **1.2.0**
23
- + Updated `VERSION` in `lib/more_math/version.rb`
24
- + Updated gemspec version and date
25
- + Bumped `gem_hadar` development dependency to **1.18.0**
41
+ + Updated `VERSION` in `lib/more_math/version.rb`
42
+ + Updated gemspec version and date
43
+ + Bumped `gem_hadar` development dependency to **1.18.0**
26
44
  * Update Ruby version check in `.all_images.yml`
27
- + Added `--full-index` to `bundle` command
45
+ + Added `--full-index` to `bundle` command
28
46
  * Add UTF-8 support to histogram display
29
- + Added `utf8?` method to Histogram class
30
- + Modified `output_row` method to use UTF-8 bars with braille when possible
31
- + Added tests for UTF-8 histogram display with and without counts
47
+ + Added `utf8?` method to Histogram class
48
+ + Modified `output_row` method to use UTF-8 bars with braille when possible
49
+ + Added tests for UTF-8 histogram display with and without counts
32
50
 
33
51
  ## 2024-08-28 v1.1.0
34
52
 
35
53
  * **Added** `interquartile_range` method to `MoreMath::Sequence`
36
- + Significant changes:
37
- - Added `interquartile_range` method to `MoreMath::Sequence`
38
- - Updated test cases for `sequence_test.rb`
54
+ + Significant changes:
55
+ - Added `interquartile_range` method to `MoreMath::Sequence`
56
+ - Updated test cases for `sequence_test.rb`
39
57
  * **Updated** all_images.yml to include Ruby **3.3**
40
58
 
41
59
  ## 2024-07-03 v1.0.2
@@ -43,16 +61,16 @@
43
61
  * Use github as homepage for rubygems
44
62
  * Only test newer ruby versions
45
63
  * Fine tune width settings a bit, and raise error when invalid arguments are provided:
46
- + Method: `code`**width_settings**
47
- + Variable: `code`**github_url**
64
+ + Method: `code`**width_settings**
65
+ + Variable: `code`**github_url**
48
66
 
49
67
  ## 2023-05-29 v1.0.1
50
68
 
51
69
  * **Fine-tuned** the width settings:
52
- + Raised an error when invalid arguments were provided
70
+ + Raised an error when invalid arguments were provided
53
71
  * Significant changes:
54
- * Raised error when `stupid` arguments are given to width settings
55
- * Updated width settings (no specific details available)
72
+ * Raised error when `stupid` arguments are given to width settings
73
+ * Updated width settings (no specific details available)
56
74
 
57
75
  ## 2023-05-26 v1.0.0
58
76
 
@@ -68,8 +86,8 @@
68
86
  * Use all_images instead of travis
69
87
  * Be compatible to older rubies
70
88
  * Adds predicate to check if ContinuedFraction is `#simple?` and add the standard […;…,…] notation for these.
71
- + Adds ContinuedFraction#reciprocal method.
72
- + Use keyword arguments for ContinuedFraction approximations instead of positional arguments.
89
+ + Adds ContinuedFraction#reciprocal method.
90
+ + Use keyword arguments for ContinuedFraction approximations instead of positional arguments.
73
91
  * Add exp log functions as well
74
92
  * Add erfc unless mixed in from Math already
75
93
  * Convert number to float b4 calculation
@@ -85,8 +103,8 @@
85
103
  ## 2017-07-04 v0.3.3
86
104
 
87
105
  * Added **1.0** version of the gem with a new feature:
88
- + Added `code`LICENSE = "MIT"` to Gemfile
89
- + Updated `code`gemspec.rb` with `code`SPDX-License-Identifier: MIT`
106
+ + Added `code`LICENSE = "MIT"` to Gemfile
107
+ + Updated `code`gemspec.rb` with `code`SPDX-License-Identifier: MIT`
90
108
  * No significant changes in this commit
91
109
 
92
110
  ## 2017-03-09 v0.3.2
@@ -103,20 +121,20 @@
103
121
  ## 2016-10-20 v0.3.1
104
122
 
105
123
  * **Corrected method name**
106
- + Changed `code`**_method_name_** to `code`**_correct_method_name_**
124
+ + Changed `code`**_method_name_** to `code`**_correct_method_name_**
107
125
 
108
126
  ## 2016-10-20 v0.3.0
109
127
 
110
128
  * **Significant Changes**
111
- + Bump version to **1.0** (commit)
112
- + Implement n-element moving average for Sequence in `Sequence` class
113
- + Add functions to compute entropy of texts in `EntropyCalculator` class
114
- + Refactor some methods in `continued_fraction.rb`
115
- + Ignore `.DS_Store` files
129
+ + Bump version to **1.0** (commit)
130
+ + Implement n-element moving average for Sequence in `Sequence` class
131
+ + Add functions to compute entropy of texts in `EntropyCalculator` class
132
+ + Refactor some methods in `continued_fraction.rb`
133
+ + Ignore `.DS_Store` files
116
134
  * Other changes:
117
- + Test ruby **2.3.1**
118
- + Add codeclimate configuration files
119
- + Add code climate coverage token
135
+ + Test ruby **2.3.1**
136
+ + Add codeclimate configuration files
137
+ + Add code climate coverage token
120
138
 
121
139
  ## 2015-05-21 v0.2.1
122
140
 
@@ -133,10 +151,10 @@
133
151
  #### New Features
134
152
 
135
153
  * Added Permutation features:
136
- + `identity`: Returns a permutation that leaves all elements unchanged.
137
- + `power`: Raises a permutation to a given power.
138
- + `from_mapping`: Creates a permutation from a given mapping.
139
- Contributed by Pramukta Kumar <prak@mac.com>.
154
+ + `identity`: Returns a permutation that leaves all elements unchanged.
155
+ + `power`: Raises a permutation to a given power.
156
+ + `from_mapping`: Creates a permutation from a given mapping.
157
+ Contributed by Pramukta Kumar <prak@mac.com>.
140
158
 
141
159
  #### Configuration Changes
142
160
 
@@ -147,24 +165,24 @@
147
165
  ## 2011-12-25 v0.0.4
148
166
 
149
167
  * **Changes for Ruby 1.9.3 and 1.8**
150
- + Added support for `ruby 1.9.3` as a test target
151
- + Implemented `to_int` method for symbols in Ruby 1.8
168
+ + Added support for `ruby 1.9.3` as a test target
169
+ + Implemented `to_int` method for symbols in Ruby 1.8
152
170
  * Renamed test files
153
171
 
154
172
  ## 2011-10-28 v0.0.3
155
173
 
156
174
  * **Changes in version **bold**0.2.3**bold**:*
157
- + Added permutation class to more_math
158
- + Started power set implementation
159
- + Shared code between subset and permutation
160
- + Fixed small subset issues
161
- + Merged branch 'power_set' into power_set
162
- + Resolved conflicts in lib/more_math.rb, lib/more_math/ranking_common.rb, lib/more_math/subset.rb, and more_math.gemspec
175
+ + Added permutation class to more_math
176
+ + Started power set implementation
177
+ + Shared code between subset and permutation
178
+ + Fixed small subset issues
179
+ + Merged branch 'power_set' into power_set
180
+ + Resolved conflicts in lib/more_math.rb, lib/more_math/ranking_common.rb, lib/more_math/subset.rb, and more_math.gemspec
163
181
 
164
182
  ## 2011-09-26 v0.0.2
165
183
 
166
184
  * **Depend on tins library**
167
- + Added dependency on `tins` library.
185
+ + Added dependency on `tins` library.
168
186
 
169
187
  ## 2011-07-17 v0.0.1
170
188
 
data/README.md CHANGED
@@ -2,20 +2,108 @@
2
2
 
3
3
  ## Description
4
4
 
5
- Ruby library that contains various mathematical functions and algorithms.
5
+ Ruby library that contains various mathematical functions and algorithms,
6
+ extending Ruby's capabilities in domains such as statistics, numerical
7
+ analysis, and combinatorics.
6
8
 
7
- ## Download
9
+ ### Core Features
8
10
 
9
- The homepage of this library is located at
11
+ 1. **Mathematical Functions**
12
+ - **Gamma Function**: Computes the gamma function for real numbers.
13
+ - **Beta Function**: Calculates the beta function and its regularized form.
14
+ - **Error Function (erf)**: Provides the error function used in probability
15
+ and statistics.
10
16
 
11
- * http://github.com/flori/more_math
17
+ 2. **Special Functions**
18
+ - **Lambert W Function**: Solves equations of the form `x = a * exp(x)`.
19
+ - **Continued Fractions**: Evaluates continued fractions for various
20
+ mathematical expressions.
12
21
 
22
+ 3. **Statistical Tools**
23
+ - **Probability Distributions**: Implements distributions like Student's t,
24
+ chi-squared, and Fisher's z.
25
+ - **Random Number Generation**: Generates random numbers following specific
26
+ distributions.
27
+ - **Hypothesis Testing**: Performs tests like the Kolmogorov-Smirnov test
28
+ for distribution comparison.
29
+
30
+ 4. **Sequence Analysis**
31
+ - **Moving Averages**: Computes simple moving averages for time series data.
32
+ - **Autocorrelation and Autovariance**: Analyzes the correlation structure
33
+ of sequences.
34
+ - **Histograms**: Visualizes data distributions with customizable bins.
35
+
36
+ 5. **Combinatorics and Algorithms**
37
+ - **Permutations and Combinations**: Generates permutations, combinations,
38
+ and Cartesian products.
39
+ - **Graph Theory**: Includes algorithms for shortest paths (Dijkstra,
40
+ Floyd-Warshall) and minimum spanning trees.
41
+ - **Root Finding**: Uses Newton-Raphson and bisection methods to find roots
42
+ of functions.
43
+
44
+ ### Specialized Modules
45
+
46
+ 1. **String Numeral Conversion**
47
+ - Converts strings to Gödel numbers and vice versa using a specified
48
+ alphabet.
49
+
50
+ 2. **Cantor Pairing Function**
51
+ - Encodes tuples into a single integer and decodes them back, useful in set
52
+ theory and combinatorics.
53
+
54
+ 3. **Histograms**
55
+ - Creates histograms for data visualization with support for different
56
+ binning strategies.
57
+
58
+ ## Example Usage
59
+
60
+ ```ruby
61
+ include MoreMath::Functions # include like you would ::Math
62
+
63
+ # Compute the gamma function at 0.5
64
+ puts gamma(0.5) # => 1.77245385091
65
+
66
+ # Define a continued fraction representation of the arctangent function (atan)
67
+ atan = ContinuedFraction.for_a do |n, x|
68
+ n == 0 ? 0 : 2 * n - 1
69
+ end.for_b do |n, x|
70
+ n <= 1 ? x : ((n - 1) * x) ** 2
71
+ end
72
+ pi = -> (epsilon: 1E-16) { 4 * atan.(1, epsilon:) }
73
+ puts pi.() # => 3.1415926535897936
74
+
75
+ # Compute the moving average of an array
76
+ sequence = [1, 2, 3, 4, 5]
77
+ ma = Sequence.new(sequence).simple_moving_average(2)
78
+ puts ma.inspect # => [1.5, 2.5, 3.5, 4.5]
79
+
80
+ # Create a histogram with 3 bins, display it in on STDOUT with a width of 80 characters
81
+ Histogram.new([1, 2, 3, 4, 5, 1], bins: 3).display(STDOUT, 80) ; nil
82
+ # 4.33333 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
83
+ # 3.00000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇
84
+ # 1.66667 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
85
+ ```
86
+
87
+ ## Installation
88
+
89
+ To install `more_math`, run:
90
+
91
+ ```bash
92
+ gem install more_math
93
+ ```
13
94
 
14
95
  ## Author
15
96
 
16
- Florian Frank mailto:flori@ping.de
97
+ Florian Frank
98
+ mailto:flori@ping.de
17
99
 
18
100
  ## License
19
101
 
20
102
  This software is licensed under the X11 (or MIT) license:
21
103
  http://www.xfree86.org/3.3.6/COPYRIGHT2.html#3
104
+
105
+ ## Homepage
106
+
107
+ The homepage of this library is located at:
108
+
109
+ * http://github.com/flori/more_math
@@ -1,3 +1,5 @@
1
+ require 'tins'
2
+
1
3
  module MoreMath
2
4
  # A histogram gives an overview of a sequence's elements.
3
5
  class Histogram
@@ -35,8 +37,12 @@ module MoreMath
35
37
 
36
38
  # Display this histogram to +output+, +width+ is the parameter for
37
39
  # +prepare_display+
38
- def display(output = $stdout, width = 50)
39
- width >= 1 or raise ArgumentError, "width needs to be >= 1"
40
+ def display(output = $stdout, width = 65)
41
+ if width.is_a?(String) && width =~ /(.+)%\z/
42
+ percentage = Float($1).clamp(0, 100)
43
+ width = (terminal_width * (percentage / 100.0)).floor
44
+ end
45
+ width > 15 or raise ArgumentError, "width needs to be >= 15"
40
46
  for r in rows
41
47
  output << output_row(r, width)
42
48
  end
@@ -44,6 +50,10 @@ module MoreMath
44
50
  self
45
51
  end
46
52
 
53
+ def terminal_width
54
+ Tins::Terminal.columns
55
+ end
56
+
47
57
  def max_count
48
58
  counts.max
49
59
  end
@@ -79,6 +89,7 @@ module MoreMath
79
89
  end
80
90
 
81
91
  def output_row_with_count(left, right, count, width)
92
+ width -= 15
82
93
  c = utf8? ? 2 : 1
83
94
  left_width = width - (counts.map { |x| x.to_s.size }.max + c)
84
95
  if left_width < 0
@@ -87,12 +98,13 @@ module MoreMath
87
98
  factor = left_width.to_f / max_count
88
99
  bar_width = (count * factor)
89
100
  bar = utf8? ? utf8_bar(bar_width) : ascii_bar(bar_width)
90
- max_count_length = max_count.to_s.size
101
+ max_count_length = max_count.to_s.size
91
102
  "%11.5f -|%#{-width + max_count_length}s%#{max_count_length}s\n" %
92
- [ (left + right) / 2.0, bar, count ]
103
+ [ (left + right) / 2.0, bar, count ]
93
104
  end
94
105
 
95
106
  def output_row_without_count(left, right, count, width)
107
+ width -= 15
96
108
  left_width = width
97
109
  left_width < 0 and left_width = width
98
110
  factor = left_width.to_f / max_count
@@ -41,6 +41,13 @@ module MoreMath
41
41
  result
42
42
  end
43
43
 
44
- # TODO project
44
+ # This method maps elements from a given dataset based on the
45
+ # subset's indices determined by its rank and returns the result, while
46
+ # ensuring the input data size matches the subset's size.
47
+ def project(data = nil)
48
+ data ||= @collection || (0...size).to_a
49
+ raise ArgumentError, "data size is != #{size}!" if data.size != size
50
+ value.map { |i| data[i] }
51
+ end
45
52
  end
46
53
  end
@@ -1,6 +1,6 @@
1
1
  module MoreMath
2
2
  # MoreMath version
3
- VERSION = '1.2.2'
3
+ VERSION = '1.4.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/more_math.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: more_math 1.2.2 ruby lib
2
+ # stub: more_math 1.4.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "more_math".freeze
6
- s.version = "1.2.2".freeze
6
+ s.version = "1.4.0".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Florian Frank".freeze]
11
- s.date = "2024-09-30"
11
+ s.date = "1980-01-02"
12
12
  s.description = "Library that provides more mathematical functions/algorithms than standard Ruby.".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.extra_rdoc_files = ["README.md".freeze, "lib/more_math.rb".freeze, "lib/more_math/cantor_pairing_function.rb".freeze, "lib/more_math/constants/functions_constants.rb".freeze, "lib/more_math/continued_fraction.rb".freeze, "lib/more_math/distributions.rb".freeze, "lib/more_math/entropy.rb".freeze, "lib/more_math/exceptions.rb".freeze, "lib/more_math/functions.rb".freeze, "lib/more_math/histogram.rb".freeze, "lib/more_math/linear_regression.rb".freeze, "lib/more_math/newton_bisection.rb".freeze, "lib/more_math/numberify_string_function.rb".freeze, "lib/more_math/permutation.rb".freeze, "lib/more_math/ranking_common.rb".freeze, "lib/more_math/sequence.rb".freeze, "lib/more_math/sequence/moving_average.rb".freeze, "lib/more_math/sequence/refinement.rb".freeze, "lib/more_math/string_numeral.rb".freeze, "lib/more_math/subset.rb".freeze, "lib/more_math/version.rb".freeze]
@@ -17,13 +17,13 @@ Gem::Specification.new do |s|
17
17
  s.licenses = ["MIT".freeze]
18
18
  s.rdoc_options = ["--title".freeze, "MoreMath -- More Math in Ruby".freeze, "--main".freeze, "README.md".freeze]
19
19
  s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
20
- s.rubygems_version = "3.5.18".freeze
20
+ s.rubygems_version = "3.6.9".freeze
21
21
  s.summary = "Library that provides more mathematics.".freeze
22
22
  s.test_files = ["tests/cantor_pairing_function_test.rb".freeze, "tests/continued_fraction_test.rb".freeze, "tests/distribution_test.rb".freeze, "tests/entropy_test.rb".freeze, "tests/functions_test.rb".freeze, "tests/histogram_test.rb".freeze, "tests/newton_bisection_test.rb".freeze, "tests/numberify_string_function_test.rb".freeze, "tests/permutation_test.rb".freeze, "tests/sequence/refinement_test.rb".freeze, "tests/sequence_moving_average_test.rb".freeze, "tests/sequence_test.rb".freeze, "tests/string_numeral_test.rb".freeze, "tests/subset_test.rb".freeze, "tests/test_helper.rb".freeze]
23
23
 
24
24
  s.specification_version = 4
25
25
 
26
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.18.0".freeze])
26
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.20".freeze])
27
27
  s.add_development_dependency(%q<rake>.freeze, [">= 0".freeze])
28
28
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
29
29
  s.add_development_dependency(%q<test-unit>.freeze, [">= 0".freeze])
@@ -23,7 +23,7 @@ class HistogramTest < Test::Unit::TestCase
23
23
  assert_equal [[2.0, 3.0, 1], [1.0, 2.0, 2], [0.0, 1.0, 2]],
24
24
  histogram.instance_eval { rows }
25
25
  output = StringIO.new
26
- histogram.display output
26
+ histogram.display output, 65
27
27
  assert_equal <<~end, output.string
28
28
  2.50000 -|*************************
29
29
  1.50000 -|**************************************************
@@ -41,7 +41,7 @@ class HistogramTest < Test::Unit::TestCase
41
41
  assert_equal [[2.0, 3.0, 1], [1.0, 2.0, 2], [0.0, 1.0, 2]],
42
42
  histogram.instance_eval { rows }
43
43
  output = StringIO.new
44
- histogram.display output
44
+ histogram.display output, 65
45
45
  assert_equal <<~end, output.string
46
46
  2.50000 -|************************ 1
47
47
  1.50000 -|************************************************ 2
@@ -58,7 +58,7 @@ class HistogramTest < Test::Unit::TestCase
58
58
  false
59
59
  end
60
60
  output = StringIO.new
61
- histogram.display output
61
+ histogram.display output, 65
62
62
  assert_equal <<~end, output.string
63
63
  67.50000 -|***** 81
64
64
  40.50000 -|************* 206
@@ -75,7 +75,7 @@ class HistogramTest < Test::Unit::TestCase
75
75
  true
76
76
  end
77
77
  output = StringIO.new
78
- histogram.display output
78
+ histogram.display output, 65
79
79
  assert_equal <<~end, output.string
80
80
  7.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
81
81
  4.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇
@@ -92,7 +92,7 @@ class HistogramTest < Test::Unit::TestCase
92
92
  true
93
93
  end
94
94
  output = StringIO.new
95
- histogram.display output
95
+ histogram.display output, 65
96
96
  assert_equal <<~end, output.string
97
97
  7.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇ 295
98
98
  4.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇ 285
@@ -101,7 +101,7 @@ class HistogramTest < Test::Unit::TestCase
101
101
  end
102
102
  end
103
103
 
104
- def test_histogram_display_with_counts_utf8_zero
104
+ def test_histogram_display_with_counts_utf8_product
105
105
  srand 1337
106
106
  sequence = Sequence.new 1000.times.map { rand(10) * rand(10) }
107
107
  histogram = Histogram.new sequence, with_counts: true, bins: 3
@@ -109,7 +109,7 @@ class HistogramTest < Test::Unit::TestCase
109
109
  true
110
110
  end
111
111
  output = StringIO.new
112
- histogram.display output
112
+ histogram.display output, 65
113
113
  assert_equal <<~end, output.string
114
114
  67.50000 -|⣿⣿⣿⣿⣿ 81
115
115
  40.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ 206
@@ -118,11 +118,31 @@ class HistogramTest < Test::Unit::TestCase
118
118
  end
119
119
  end
120
120
 
121
+ def test_histogram_display_with_counts_utf8_product_width_75_percent
122
+ srand 1337
123
+ sequence = Sequence.new 1000.times.map { rand(10) * rand(10) }
124
+ histogram = Histogram.new sequence, with_counts: true, bins: 3
125
+ def histogram.utf8?
126
+ true
127
+ end
128
+ def histogram.terminal_width
129
+ 80
130
+ end
131
+ output = StringIO.new
132
+ histogram.display output, '90%'
133
+ assert_equal <<~end, output.string
134
+ 67.50000 -|⣿⣿⣿⣿⣿⡇ 81
135
+ 40.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ 206
136
+ 13.50000 -|⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ 713
137
+ max_count=713
138
+ end
139
+ end
140
+
121
141
  private
122
142
 
123
- def output_histogram(histogram)
143
+ def output_histogram(histogram, width = 65)
124
144
  $stdout.puts
125
- histogram.display $stdout
145
+ histogram.display $stdout, width
126
146
  $stdout.puts
127
147
  end
128
148
  end
data/tests/subset_test.rb CHANGED
@@ -19,4 +19,15 @@ class SubsetTest < Test::Unit::TestCase
19
19
  assert_equal expected, Subset.for([1, 2, 3]).map(&:value)
20
20
  assert_equal expected, Subset.power_set([1, 2, 3])
21
21
  end
22
+
23
+ def test_project
24
+ a = %i[ a b c d e ]
25
+ subset = Subset.new(a.size, 23)
26
+ assert_raises(ArgumentError) { subset.project a + %i[ f ] }
27
+ (2 ** a.size).times do |i|
28
+ subset = Subset.new(a.size, i)
29
+ projected = subset.project(a)
30
+ assert_equal(projected, Subset.power_set(a)[i])
31
+ end
32
+ end
22
33
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: more_math
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-09-30 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: gem_hadar
@@ -16,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: 1.18.0
18
+ version: '1.20'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: 1.18.0
25
+ version: '1.20'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rake
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -195,7 +194,6 @@ homepage: https://github.com/flori/more_math
195
194
  licenses:
196
195
  - MIT
197
196
  metadata: {}
198
- post_install_message:
199
197
  rdoc_options:
200
198
  - "--title"
201
199
  - MoreMath -- More Math in Ruby
@@ -214,8 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
212
  - !ruby/object:Gem::Version
215
213
  version: '0'
216
214
  requirements: []
217
- rubygems_version: 3.5.18
218
- signing_key:
215
+ rubygems_version: 3.6.9
219
216
  specification_version: 4
220
217
  summary: Library that provides more mathematics.
221
218
  test_files: