more_math 0.2.1 → 0.3.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 +4 -4
- data/.codeclimate.yml +16 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +1158 -0
- data/.travis.yml +5 -0
- data/Gemfile +1 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/more_math/continued_fraction.rb +23 -23
- data/lib/more_math/entropy.rb +26 -0
- data/lib/more_math/functions.rb +3 -0
- data/lib/more_math/sequence.rb +17 -0
- data/lib/more_math/sequence/moving_average.rb +21 -0
- data/lib/more_math/sequence/refinement.rb +9 -0
- data/lib/more_math/version.rb +1 -1
- data/more_math.gemspec +31 -31
- data/tests/entropy_test.rb +44 -0
- data/tests/sequence_moving_average_test.rb +31 -0
- data/tests/sequence_test.rb +7 -0
- metadata +17 -5
data/.travis.yml
CHANGED
@@ -2,9 +2,14 @@ rvm:
|
|
2
2
|
- 2.0
|
3
3
|
- 2.1
|
4
4
|
- 2.2
|
5
|
+
- 2.3.1
|
5
6
|
- ruby-head
|
6
7
|
- jruby-head
|
7
8
|
matrix:
|
8
9
|
allow_failures:
|
9
10
|
- rvm: ruby-head
|
10
11
|
- rvm: jruby-head
|
12
|
+
sudo: false
|
13
|
+
addons:
|
14
|
+
code_climate:
|
15
|
+
repo_token: c9eff249077e5d42951c2ac14abcaba555cb214524310e8d8f1769a579cbeb81
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ GemHadar do
|
|
11
11
|
description 'Library that provides more mathematical functions/algorithms than standard Ruby.'
|
12
12
|
test_dir 'tests'
|
13
13
|
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc',
|
14
|
-
'.AppleDouble', 'tags'
|
14
|
+
'.AppleDouble', 'tags', '.byebug_history', '.DS_Store'
|
15
15
|
readme 'README.rdoc'
|
16
16
|
title "#{name.camelize} -- More Math in Ruby"
|
17
17
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -35,19 +35,24 @@ module MoreMath
|
|
35
35
|
new.for_b(arg, &block)
|
36
36
|
end
|
37
37
|
|
38
|
+
def for_arg(arg = nil, &block)
|
39
|
+
if arg and !block
|
40
|
+
arg
|
41
|
+
elsif block and !arg
|
42
|
+
block
|
43
|
+
else
|
44
|
+
raise ArgumentError, "exactly one argument or one block required"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
private :for_arg
|
48
|
+
|
38
49
|
# This method either takes a block or an argument +arg+. The argument +arg+
|
39
50
|
# has to respond to an integer index n >= 0 and return the value a_n. The
|
40
51
|
# block has to return the value for a_n when +n+ is passed as the first
|
41
52
|
# argument to the block. If a_n is dependent on an +x+ value (see the call
|
42
53
|
# method) the +x+ will be the second argument of the block.
|
43
54
|
def for_a(arg = nil, &block)
|
44
|
-
|
45
|
-
@a = arg
|
46
|
-
elsif block and !arg
|
47
|
-
@a = block
|
48
|
-
else
|
49
|
-
raise ArgumentError, "exactly one argument or one block required"
|
50
|
-
end
|
55
|
+
@a = for_arg(arg, &block)
|
51
56
|
self
|
52
57
|
end
|
53
58
|
|
@@ -57,32 +62,27 @@ module MoreMath
|
|
57
62
|
# argument to the block. If b_n is dependent on an +x+ value (see the call
|
58
63
|
# method) the +x+ will be the second argument of the block.
|
59
64
|
def for_b(arg = nil, &block)
|
60
|
-
|
61
|
-
@b = arg
|
62
|
-
elsif block and !arg
|
63
|
-
@b = block
|
64
|
-
else
|
65
|
-
raise ArgumentError, "exactly one argument or one block required"
|
66
|
-
end
|
65
|
+
@b = for_arg(arg, &block)
|
67
66
|
self
|
68
67
|
end
|
69
68
|
|
70
|
-
|
71
|
-
def a(n, x = nil)
|
69
|
+
def value(v, n, x = nil)
|
72
70
|
result = if x
|
73
|
-
|
71
|
+
v[n, x]
|
74
72
|
else
|
75
|
-
|
73
|
+
v[n]
|
76
74
|
end and result.to_f
|
77
75
|
end
|
76
|
+
private :value
|
77
|
+
|
78
|
+
# Returns the value for a_n or a_n(x).
|
79
|
+
def a(n, x = nil)
|
80
|
+
value(@a, n, x)
|
81
|
+
end
|
78
82
|
|
79
83
|
# Returns the value for b_n or b_n(x).
|
80
84
|
def b(n, x = nil)
|
81
|
-
|
82
|
-
@b[n, x]
|
83
|
-
else
|
84
|
-
@b[n]
|
85
|
-
end and result.to_f
|
85
|
+
value(@b, n, x)
|
86
86
|
end
|
87
87
|
|
88
88
|
# Evaluates the continued fraction for the value +x+ (if any) with the
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module MoreMath
|
2
|
+
module Entropy
|
3
|
+
def entropy(text)
|
4
|
+
chars = text.chars
|
5
|
+
size = chars.size
|
6
|
+
|
7
|
+
chars.each_with_object(Hash.new(0.0)) { |c, h| h[c] += 1 }.
|
8
|
+
each_value.reduce(0.0) do |entropy, count|
|
9
|
+
frequency = count / size
|
10
|
+
entropy + frequency * Math.log2(frequency)
|
11
|
+
end.abs
|
12
|
+
end
|
13
|
+
|
14
|
+
def entropy_ideal(size)
|
15
|
+
size <= 1 and return 0.0
|
16
|
+
frequency = 1.0 / size
|
17
|
+
-1.0 * size * frequency * Math.log2(frequency)
|
18
|
+
end
|
19
|
+
|
20
|
+
def entropy_percentage(text)
|
21
|
+
size = text.each_char.size
|
22
|
+
size <= 1 and return 0.0
|
23
|
+
entropy(text) / entropy_ideal(size)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/more_math/functions.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'more_math'
|
2
|
+
require 'more_math/entropy'
|
2
3
|
|
3
4
|
module MoreMath
|
4
5
|
module Functions
|
@@ -186,5 +187,7 @@ module MoreMath
|
|
186
187
|
def stringify_number(number, alphabet = 'a'..'z')
|
187
188
|
NumberifyStringFunction.stringify_number(number, alphabet)
|
188
189
|
end
|
190
|
+
|
191
|
+
include Entropy
|
189
192
|
end
|
190
193
|
end
|
data/lib/more_math/sequence.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require 'more_math'
|
2
2
|
require 'tins/memoize'
|
3
|
+
require 'more_math/sequence/moving_average'
|
4
|
+
require 'more_math/sequence/refinement'
|
3
5
|
|
4
6
|
module MoreMath
|
5
7
|
# This class is used to contain elements and compute various statistical
|
6
8
|
# values for them.
|
7
9
|
class Sequence
|
10
|
+
include MoreMath::Sequence::MovingAverage
|
11
|
+
|
8
12
|
def initialize(elements)
|
9
13
|
@elements = elements.dup.freeze
|
10
14
|
end
|
@@ -34,6 +38,19 @@ module MoreMath
|
|
34
38
|
self
|
35
39
|
end
|
36
40
|
|
41
|
+
def to_ary
|
42
|
+
@elements.dup
|
43
|
+
end
|
44
|
+
|
45
|
+
alias to_a to_ary
|
46
|
+
|
47
|
+
# Push +element+ on this Sequence and return a new Sequence instance with
|
48
|
+
# +element+ as its last element.
|
49
|
+
def push(element)
|
50
|
+
Sequence.new(@elements.dup.push(element))
|
51
|
+
end
|
52
|
+
alias << push
|
53
|
+
|
37
54
|
# Returns the variance of the elements.
|
38
55
|
def variance
|
39
56
|
sum_of_squares / size
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module MoreMath
|
2
|
+
class Sequence
|
3
|
+
module MovingAverage
|
4
|
+
def simple_moving_average(n)
|
5
|
+
n < 1 and raise ArgumentError, 'n < 1, has to be >= 1'
|
6
|
+
n <= @elements.size or raise ArgumentError,
|
7
|
+
'n > #elements, has to be <= #elements'
|
8
|
+
avg = []
|
9
|
+
0.upto(@elements.size - n) do |i|
|
10
|
+
sum = 0.0
|
11
|
+
i.upto(i + n - 1) do |j|
|
12
|
+
sum += @elements[j].to_f
|
13
|
+
end
|
14
|
+
avg << sum / n
|
15
|
+
end
|
16
|
+
avg
|
17
|
+
end
|
18
|
+
alias moving_average simple_moving_average
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/more_math/version.rb
CHANGED
data/more_math.gemspec
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: more_math 0.
|
2
|
+
# stub: more_math 0.3.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name = "more_math"
|
6
|
-
s.version = "0.
|
5
|
+
s.name = "more_math".freeze
|
6
|
+
s.version = "0.3.0"
|
7
7
|
|
8
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
|
-
s.require_paths = ["lib"]
|
10
|
-
s.authors = ["Florian Frank"]
|
11
|
-
s.date = "
|
12
|
-
s.description = "Library that provides more mathematical functions/algorithms than standard Ruby."
|
13
|
-
s.email = "flori@ping.de"
|
14
|
-
s.extra_rdoc_files = ["README.rdoc", "lib/more_math.rb", "lib/more_math/cantor_pairing_function.rb", "lib/more_math/constants/functions_constants.rb", "lib/more_math/continued_fraction.rb", "lib/more_math/distributions.rb", "lib/more_math/exceptions.rb", "lib/more_math/functions.rb", "lib/more_math/histogram.rb", "lib/more_math/linear_regression.rb", "lib/more_math/newton_bisection.rb", "lib/more_math/numberify_string_function.rb", "lib/more_math/permutation.rb", "lib/more_math/ranking_common.rb", "lib/more_math/sequence.rb", "lib/more_math/string_numeral.rb", "lib/more_math/subset.rb", "lib/more_math/version.rb"]
|
15
|
-
s.files = [".gitignore", ".travis.yml", "CHANGES", "Gemfile", "LICENSE", "README.rdoc", "Rakefile", "VERSION", "lib/more_math.rb", "lib/more_math/cantor_pairing_function.rb", "lib/more_math/constants/functions_constants.rb", "lib/more_math/continued_fraction.rb", "lib/more_math/distributions.rb", "lib/more_math/exceptions.rb", "lib/more_math/functions.rb", "lib/more_math/histogram.rb", "lib/more_math/linear_regression.rb", "lib/more_math/newton_bisection.rb", "lib/more_math/numberify_string_function.rb", "lib/more_math/permutation.rb", "lib/more_math/ranking_common.rb", "lib/more_math/sequence.rb", "lib/more_math/string_numeral.rb", "lib/more_math/subset.rb", "lib/more_math/version.rb", "more_math.gemspec", "tests/cantor_pairing_function_test.rb", "tests/continued_fraction_test.rb", "tests/distribution_test.rb", "tests/functions_test.rb", "tests/histogram_test.rb", "tests/newton_bisection_test.rb", "tests/numberify_string_function_test.rb", "tests/permutation_test.rb", "tests/sequence_test.rb", "tests/string_numeral_test.rb", "tests/subset_test.rb", "tests/test_helper.rb"]
|
16
|
-
s.homepage = "http://flori.github.com/more_math"
|
17
|
-
s.rdoc_options = ["--title", "MoreMath -- More Math in Ruby", "--main", "README.rdoc"]
|
18
|
-
s.rubygems_version = "2.
|
19
|
-
s.summary = "Library that provides more mathematics."
|
20
|
-
s.test_files = ["tests/cantor_pairing_function_test.rb", "tests/continued_fraction_test.rb", "tests/distribution_test.rb", "tests/functions_test.rb", "tests/histogram_test.rb", "tests/newton_bisection_test.rb", "tests/numberify_string_function_test.rb", "tests/permutation_test.rb", "tests/sequence_test.rb", "tests/string_numeral_test.rb", "tests/subset_test.rb", "tests/test_helper.rb"]
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib".freeze]
|
10
|
+
s.authors = ["Florian Frank".freeze]
|
11
|
+
s.date = "2016-10-20"
|
12
|
+
s.description = "Library that provides more mathematical functions/algorithms than standard Ruby.".freeze
|
13
|
+
s.email = "flori@ping.de".freeze
|
14
|
+
s.extra_rdoc_files = ["README.rdoc".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]
|
15
|
+
s.files = [".codeclimate.yml".freeze, ".gitignore".freeze, ".rubocop.yml".freeze, ".travis.yml".freeze, "CHANGES".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.rdoc".freeze, "Rakefile".freeze, "VERSION".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, "more_math.gemspec".freeze, "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_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]
|
16
|
+
s.homepage = "http://flori.github.com/more_math".freeze
|
17
|
+
s.rdoc_options = ["--title".freeze, "MoreMath -- More Math in Ruby".freeze, "--main".freeze, "README.rdoc".freeze]
|
18
|
+
s.rubygems_version = "2.6.7".freeze
|
19
|
+
s.summary = "Library that provides more mathematics.".freeze
|
20
|
+
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_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]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
s.specification_version = 4
|
24
24
|
|
25
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
-
s.add_development_dependency(%q<gem_hadar
|
27
|
-
s.add_development_dependency(%q<rake
|
28
|
-
s.add_development_dependency(%q<simplecov
|
29
|
-
s.add_development_dependency(%q<test-unit
|
30
|
-
s.add_runtime_dependency(%q<tins
|
26
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
|
27
|
+
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
28
|
+
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
29
|
+
s.add_development_dependency(%q<test-unit>.freeze, [">= 0"])
|
30
|
+
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.0"])
|
31
31
|
else
|
32
|
-
s.add_dependency(%q<gem_hadar
|
33
|
-
s.add_dependency(%q<rake
|
34
|
-
s.add_dependency(%q<simplecov
|
35
|
-
s.add_dependency(%q<test-unit
|
36
|
-
s.add_dependency(%q<tins
|
32
|
+
s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
|
33
|
+
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
34
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
35
|
+
s.add_dependency(%q<test-unit>.freeze, [">= 0"])
|
36
|
+
s.add_dependency(%q<tins>.freeze, ["~> 1.0"])
|
37
37
|
end
|
38
38
|
else
|
39
|
-
s.add_dependency(%q<gem_hadar
|
40
|
-
s.add_dependency(%q<rake
|
41
|
-
s.add_dependency(%q<simplecov
|
42
|
-
s.add_dependency(%q<test-unit
|
43
|
-
s.add_dependency(%q<tins
|
39
|
+
s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
|
40
|
+
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
41
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
42
|
+
s.add_dependency(%q<test-unit>.freeze, [">= 0"])
|
43
|
+
s.add_dependency(%q<tins>.freeze, ["~> 1.0"])
|
44
44
|
end
|
45
45
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'more_math'
|
5
|
+
|
6
|
+
class EntropyTest < Test::Unit::TestCase
|
7
|
+
include MoreMath::Functions
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@empty = ''
|
11
|
+
@low = ?A * 42
|
12
|
+
@string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
|
13
|
+
@high = 'The quick brown fox jumps over the lazy dog'
|
14
|
+
@random = "\xAC-\x8A\xF5\xA8\xF7\\\e\xB5\x8CI\x06\xA7"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_entropy
|
18
|
+
assert_equal 0, entropy(@empty)
|
19
|
+
assert_equal 0, entropy(@low)
|
20
|
+
assert_in_delta 3.9514, entropy(@string), 1E-3
|
21
|
+
assert_in_delta 4.4319, entropy(@high), 1E-3
|
22
|
+
assert_in_delta 3.700, entropy(@random), 1E-3
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_entropy_ideal
|
26
|
+
assert_equal 0, entropy_ideal(-1)
|
27
|
+
assert_equal 0, entropy_ideal(0)
|
28
|
+
assert_equal 0, entropy_ideal(0.5)
|
29
|
+
assert_equal 0, entropy_ideal(1)
|
30
|
+
assert_in_delta 1, entropy_ideal(2), 1E-3
|
31
|
+
assert_in_delta 1.584, entropy_ideal(3), 1E-3
|
32
|
+
assert_in_delta 3, entropy_ideal(8), 1E-3
|
33
|
+
assert_in_delta 3.321, entropy_ideal(10), 1E-3
|
34
|
+
assert_in_delta 4, entropy_ideal(16), 1E-3
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_entropy_percentage
|
38
|
+
assert_equal 0, entropy_percentage(@empty)
|
39
|
+
assert_equal 0, entropy_percentage(@low)
|
40
|
+
assert_in_delta 0.6834, entropy_percentage(@string), 1E-3
|
41
|
+
assert_in_delta 0.8167, entropy_percentage(@high), 1E-3
|
42
|
+
assert_in_delta 1.0, entropy_percentage(@random), 1E-3
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'more_math'
|
5
|
+
|
6
|
+
class SequenceMovingAverageTest < Test::Unit::TestCase
|
7
|
+
include MoreMath
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@seq = Sequence.new([ 3, 1, 7, 5, 6 ])
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_moving_average_fail
|
14
|
+
assert_raise(ArgumentError) { @seq.moving_average(0) }
|
15
|
+
assert_raise(ArgumentError) { @seq.moving_average(-1) }
|
16
|
+
assert_raise(ArgumentError) { @seq.moving_average(@seq.size + 1) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_moving_average
|
20
|
+
assert_equal @seq.elements.map(&:to_f),
|
21
|
+
@seq.moving_average(1)
|
22
|
+
assert_equal [ (3 + 1) / 2.0, (1 + 7) / 2.0, (7 + 5) / 2.0, (5 + 6) / 2.0 ],
|
23
|
+
@seq.moving_average(2)
|
24
|
+
assert_equal [ (3 + 1 + 7) / 3.0, (1 + 7 + 5) / 3.0, (7 + 5 + 6) / 3.0 ],
|
25
|
+
@seq.moving_average(3)
|
26
|
+
assert_equal [ (3 + 1 + 7 + 5) / 4.0, (1 + 7 + 5 + 6) / 4.0 ],
|
27
|
+
@seq.moving_average(4)
|
28
|
+
assert_equal [ @seq.mean ], @seq.moving_average(5)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
data/tests/sequence_test.rb
CHANGED
@@ -321,4 +321,11 @@ class SequenceTest < Test::Unit::TestCase
|
|
321
321
|
assert @flat.cover?(@rasi)
|
322
322
|
assert_operator @flat.suggested_sample_size(@rasi), '>', 500
|
323
323
|
end
|
324
|
+
|
325
|
+
def test_sequence_push
|
326
|
+
seq = Sequence.new([ 1, 2 ])
|
327
|
+
seq2 = seq.push 3
|
328
|
+
assert_not_same seq2, seq
|
329
|
+
assert_equal [ 1, 2, 3 ], seq2.elements
|
330
|
+
end
|
324
331
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: more_math
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.9.1
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.9.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,6 +92,7 @@ extra_rdoc_files:
|
|
92
92
|
- lib/more_math/constants/functions_constants.rb
|
93
93
|
- lib/more_math/continued_fraction.rb
|
94
94
|
- lib/more_math/distributions.rb
|
95
|
+
- lib/more_math/entropy.rb
|
95
96
|
- lib/more_math/exceptions.rb
|
96
97
|
- lib/more_math/functions.rb
|
97
98
|
- lib/more_math/histogram.rb
|
@@ -101,11 +102,15 @@ extra_rdoc_files:
|
|
101
102
|
- lib/more_math/permutation.rb
|
102
103
|
- lib/more_math/ranking_common.rb
|
103
104
|
- lib/more_math/sequence.rb
|
105
|
+
- lib/more_math/sequence/moving_average.rb
|
106
|
+
- lib/more_math/sequence/refinement.rb
|
104
107
|
- lib/more_math/string_numeral.rb
|
105
108
|
- lib/more_math/subset.rb
|
106
109
|
- lib/more_math/version.rb
|
107
110
|
files:
|
111
|
+
- ".codeclimate.yml"
|
108
112
|
- ".gitignore"
|
113
|
+
- ".rubocop.yml"
|
109
114
|
- ".travis.yml"
|
110
115
|
- CHANGES
|
111
116
|
- Gemfile
|
@@ -118,6 +123,7 @@ files:
|
|
118
123
|
- lib/more_math/constants/functions_constants.rb
|
119
124
|
- lib/more_math/continued_fraction.rb
|
120
125
|
- lib/more_math/distributions.rb
|
126
|
+
- lib/more_math/entropy.rb
|
121
127
|
- lib/more_math/exceptions.rb
|
122
128
|
- lib/more_math/functions.rb
|
123
129
|
- lib/more_math/histogram.rb
|
@@ -127,6 +133,8 @@ files:
|
|
127
133
|
- lib/more_math/permutation.rb
|
128
134
|
- lib/more_math/ranking_common.rb
|
129
135
|
- lib/more_math/sequence.rb
|
136
|
+
- lib/more_math/sequence/moving_average.rb
|
137
|
+
- lib/more_math/sequence/refinement.rb
|
130
138
|
- lib/more_math/string_numeral.rb
|
131
139
|
- lib/more_math/subset.rb
|
132
140
|
- lib/more_math/version.rb
|
@@ -134,11 +142,13 @@ files:
|
|
134
142
|
- tests/cantor_pairing_function_test.rb
|
135
143
|
- tests/continued_fraction_test.rb
|
136
144
|
- tests/distribution_test.rb
|
145
|
+
- tests/entropy_test.rb
|
137
146
|
- tests/functions_test.rb
|
138
147
|
- tests/histogram_test.rb
|
139
148
|
- tests/newton_bisection_test.rb
|
140
149
|
- tests/numberify_string_function_test.rb
|
141
150
|
- tests/permutation_test.rb
|
151
|
+
- tests/sequence_moving_average_test.rb
|
142
152
|
- tests/sequence_test.rb
|
143
153
|
- tests/string_numeral_test.rb
|
144
154
|
- tests/subset_test.rb
|
@@ -166,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
176
|
version: '0'
|
167
177
|
requirements: []
|
168
178
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.
|
179
|
+
rubygems_version: 2.6.7
|
170
180
|
signing_key:
|
171
181
|
specification_version: 4
|
172
182
|
summary: Library that provides more mathematics.
|
@@ -174,11 +184,13 @@ test_files:
|
|
174
184
|
- tests/cantor_pairing_function_test.rb
|
175
185
|
- tests/continued_fraction_test.rb
|
176
186
|
- tests/distribution_test.rb
|
187
|
+
- tests/entropy_test.rb
|
177
188
|
- tests/functions_test.rb
|
178
189
|
- tests/histogram_test.rb
|
179
190
|
- tests/newton_bisection_test.rb
|
180
191
|
- tests/numberify_string_function_test.rb
|
181
192
|
- tests/permutation_test.rb
|
193
|
+
- tests/sequence_moving_average_test.rb
|
182
194
|
- tests/sequence_test.rb
|
183
195
|
- tests/string_numeral_test.rb
|
184
196
|
- tests/subset_test.rb
|