advanced_math 0.0.4 → 0.0.5

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.
data/History.txt CHANGED
@@ -0,0 +1,4 @@
1
+ === 0.0.5 2011-08-28
2
+
3
+ * 1 major enhancement:
4
+ * Cleaned up SMA and added tests
data/Manifest.txt CHANGED
@@ -1,13 +1,8 @@
1
+ advanced_math-0.0.4.gem
1
2
  advanced_math.gemspec
2
3
  History.txt
3
4
  lib/advanced_math.rb
4
5
  Manifest.txt
5
- pkg/adbanced_math-0.borked
6
- pkg/adbanced_math-0.borked/advanced_math.gemspec
7
- pkg/adbanced_math-0.borked/lib/advanced_math.rb
8
- pkg/adbanced_math-0.borked/Manifest.txt
9
- pkg/adbanced_math-0.borked/test/test_simple_moving_average.rb
10
- pkg/adbanced_math-0.borked.gem
11
- pkg/adbanced_math-0.borked.tgz
6
+ PostInstall.txt
12
7
  README.rdoc
13
8
  test/test_simple_moving_average.rb
data/PostInstall.txt ADDED
File without changes
data/README.rdoc CHANGED
@@ -0,0 +1,41 @@
1
+ = advanced_math
2
+
3
+ * https://github.com/gnagel/mercury-wireless-public/tree/master/ruby/advanced_math
4
+
5
+ == DESCRIPTION:
6
+
7
+ A simple gem for advanced and financial math calcualtions.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Awesomeness!
12
+
13
+ == SYNOPSIS:
14
+
15
+ sma = AdvancedMath::SMA.new(5)
16
+ sma.add(1)
17
+ => nil
18
+ sma.add(2)
19
+ => nil
20
+ sma.add(3)
21
+ => nil
22
+ sma.add(4)
23
+ => nil
24
+ sma.add(5)
25
+ => 3
26
+ => (ie (1+2+3+4+5)/5)
27
+ sma.add(6)
28
+ => 4
29
+ => (ie (2+3+4+5+6)/5)
30
+
31
+ == REQUIREMENTS:
32
+
33
+ * None
34
+
35
+ == INSTALL:
36
+
37
+ * sudo gem install advanced_math
38
+
39
+ == LICENSE:
40
+
41
+ Property of Mercury Wireless Software LLC
Binary file
@@ -1,11 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  Gem::Specification.new do |s|
2
- s.name = 'advanced_math'
3
- s.version = '0.0.4'
4
- s.date = '2011-08-25'
5
- s.summary = "A simple gem for advanced and financial math calcualtions."
6
- s.description = "A simple gem for advanced and financial math calcualtions."
7
- s.authors = ["G Nagel"]
8
- s.email = 'glenn@mercury-wireless.com'
9
- s.files = Dir['**/*.*']
10
- s.homepage = 'https://github.com/gnagel/mercury-wireless-public'
4
+ s.name = %q{advanced_math}
5
+ s.version = "0.0.5"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = [%q{Glenn Nagel}]
9
+ s.date = %q{2011-08-28}
10
+ s.description = %q{A simple gem for advanced and financial math calcualtions.}
11
+ s.email = [%q{glenn@mercury-wireless.com}]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt"]
13
+ s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "advanced_math-0.0.4.gem", "advanced_math.gemspec", "lib/advanced_math.rb", "test/test_simple_moving_average.rb"]
14
+ s.homepage = %q{https://github.com/gnagel/mercury-wireless-public/tree/master/ruby/advanced_math}
15
+ s.post_install_message = %q{PostInstall.txt}
16
+ s.rdoc_options = [%q{--main}, %q{README.rdoc}]
17
+ s.require_paths = [%q{lib}]
18
+ s.rubyforge_project = %q{advanced_math}
19
+ s.rubygems_version = %q{1.8.6}
20
+ s.summary = %q{A simple gem for advanced and financial math calcualtions.}
21
+ s.test_files = [%q{test/test_simple_moving_average.rb}]
22
+
23
+ if s.respond_to? :specification_version then
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<hoe>, ["~> 2.9"])
28
+ else
29
+ s.add_dependency(%q<hoe>, ["~> 2.9"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<hoe>, ["~> 2.9"])
33
+ end
11
34
  end
data/lib/advanced_math.rb CHANGED
@@ -1,5 +1,7 @@
1
1
 
2
2
  module AdvancedMath
3
+ VERSION = '0.0.5'
4
+
3
5
 
4
6
  # Simple Moving Average (SMA) calculator
5
7
  # Created: 2011-06-24
@@ -1,51 +1,57 @@
1
1
  require 'test/unit'
2
2
  require File.dirname(__FILE__) + "/../lib/advanced_math.rb"
3
3
 
4
+ module AdvancedMath
5
+ class SimpleMovingAverageTest < Test::Unit::TestCase
6
+ # Verify the constructor raises an ArgumentError if the "range" is invalid
7
+ def test_sma_initialize_nil
8
+ assert_raise(ArgumentError) { SimpleMovingAverage.new(nil); }
9
+ end
4
10
 
11
+ # Verify the constructor raises an ArgumentError if the "range" is invalid
12
+ def test_sma_initialize_negative
13
+ assert_raise(ArgumentError) { SimpleMovingAverage.new(-1); }
14
+ (-1...-1000).each do |i|
15
+ assert_raise(ArgumentError) { SimpleMovingAverage.new(i); }
16
+ end
17
+ end
5
18
 
6
- class SimpleMovingAverageTest < Test::Unit::TestCase
7
- # Verify the constructor raises an ArgumentError if the "range" is invalid
8
- def test_sma_initialize_nil
9
- assert_raise(ArgumentError) { AdvancedMath::SimpleMovingAverage.new(nil); }
10
- end
11
-
12
- # Verify the constructor raises an ArgumentError if the "range" is invalid
13
- def test_sma_initialize_negative
14
- assert_raise(ArgumentError) { AdvancedMath::SimpleMovingAverage.new(-1); }
15
- end
16
-
17
- # Verify the constructor raises an ArgumentError if the "range" is invalid
18
- def test_sma_initialize_zero
19
- assert_raise(ArgumentError) { AdvancedMath::SimpleMovingAverage.new(0); }
20
- end
19
+ # Verify the constructor raises an ArgumentError if the "range" is invalid
20
+ def test_sma_initialize_zero
21
+ assert_raise(ArgumentError) { SimpleMovingAverage.new(0); }
22
+ end
21
23
 
22
- # Verify the constructor doesn't raise an exception if the value is positive
23
- def test_sma_initialize_positive
24
- (1...1000).each do |i|
25
- assert_nothing_raised(ArgumentError) { AdvancedMath::SimpleMovingAverage.new(i); }
24
+ # Verify the constructor doesn't raise an exception if the value is positive
25
+ def test_sma_initialize_positive
26
+ (1...1000).each do |i|
27
+ assert_nothing_raised(ArgumentError) { SimpleMovingAverage.new(i); }
28
+ end
26
29
  end
27
- end
28
30
 
29
- # Verify "add" raises an ArgumentError if the "value" is invalid
30
- def test_sma_add_nil
31
- assert_raise(ArgumentError) { AdvancedMath::SimpleMovingAverage.new(1).add(nil); }
32
- end
31
+ # Verify "add" raises an ArgumentError if the "value" is invalid
32
+ def test_sma_add_nil
33
+ assert_raise(ArgumentError) { SimpleMovingAverage.new(1).add(nil); }
34
+ end
33
35
 
34
- # Verify SMA of 1, always returns the same value
35
- def test_sma_add_1
36
- sma = AdvancedMath::SimpleMovingAverage.new(1);
37
- (1...1000).each do |i|
38
- assert_equal(i, sma.add(i));
36
+ # Verify SMA of 1, always returns the same value
37
+ def test_sma_add_1
38
+ sma = SimpleMovingAverage.new(1);
39
+ (1...1000).each do |i|
40
+ assert_equal(i, sma.add(i));
41
+ end
39
42
  end
40
- end
41
43
 
42
- # Verify SMA of 2, always returns the same value - 0.5
43
- def test_sma_add_2
44
- sma = AdvancedMath::SimpleMovingAverage.new(2);
45
- assert_equal(nil, sma.add(1));
46
- (2...1000).each do |i|
47
- assert_equal(i - 0.5, sma.add(i));
44
+ # Verify SMA of 2, always returns the same value - 0.5
45
+ def test_sma_add_2
46
+ sma = SimpleMovingAverage.new(2);
47
+ assert_equal(nil, sma.add(1));
48
+ (2...1000).each do |i|
49
+ assert_equal(i - 0.5, sma.add(i));
50
+ end
48
51
  end
49
52
  end
50
-
51
- end
53
+
54
+
55
+ class SMATest < SimpleMovingAverageTest
56
+ end
57
+ end
metadata CHANGED
@@ -1,50 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advanced_math
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
- - G Nagel
13
+ - Glenn Nagel
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-25 00:00:00 Z
19
- dependencies: []
20
-
18
+ date: 2011-08-28 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: hoe
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 17
29
+ segments:
30
+ - 2
31
+ - 9
32
+ version: "2.9"
33
+ type: :development
34
+ version_requirements: *id001
21
35
  description: A simple gem for advanced and financial math calcualtions.
22
- email: glenn@mercury-wireless.com
36
+ email:
37
+ - glenn@mercury-wireless.com
23
38
  executables: []
24
39
 
25
40
  extensions: []
26
41
 
27
- extra_rdoc_files: []
28
-
42
+ extra_rdoc_files:
43
+ - History.txt
44
+ - Manifest.txt
45
+ - PostInstall.txt
29
46
  files:
30
- - advanced_math.gemspec
31
47
  - History.txt
32
- - lib/advanced_math.rb
33
48
  - Manifest.txt
34
- - pkg/adbanced_math-0.borked/advanced_math.gemspec
35
- - pkg/adbanced_math-0.borked/lib/advanced_math.rb
36
- - pkg/adbanced_math-0.borked/Manifest.txt
37
- - pkg/adbanced_math-0.borked/test/test_simple_moving_average.rb
38
- - pkg/adbanced_math-0.borked.gem
39
- - pkg/adbanced_math-0.borked.tgz
49
+ - PostInstall.txt
40
50
  - README.rdoc
51
+ - advanced_math-0.0.4.gem
52
+ - advanced_math.gemspec
53
+ - lib/advanced_math.rb
41
54
  - test/test_simple_moving_average.rb
42
- homepage: https://github.com/gnagel/mercury-wireless-public
55
+ homepage: https://github.com/gnagel/mercury-wireless-public/tree/master/ruby/advanced_math
43
56
  licenses: []
44
57
 
45
- post_install_message:
46
- rdoc_options: []
47
-
58
+ post_install_message: PostInstall.txt
59
+ rdoc_options:
60
+ - --main
61
+ - README.rdoc
48
62
  require_paths:
49
63
  - lib
50
64
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -67,10 +81,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
81
  version: "0"
68
82
  requirements: []
69
83
 
70
- rubyforge_project:
84
+ rubyforge_project: advanced_math
71
85
  rubygems_version: 1.8.6
72
86
  signing_key:
73
87
  specification_version: 3
74
88
  summary: A simple gem for advanced and financial math calcualtions.
75
- test_files: []
76
-
89
+ test_files:
90
+ - test/test_simple_moving_average.rb
Binary file
Binary file
@@ -1,13 +0,0 @@
1
- advanced_math.gemspec
2
- History.txt
3
- lib/advanced_math.rb
4
- Manifest.txt
5
- pkg/adbanced_math-0.borked
6
- pkg/adbanced_math-0.borked/advanced_math.gemspec
7
- pkg/adbanced_math-0.borked/lib/advanced_math.rb
8
- pkg/adbanced_math-0.borked/Manifest.txt
9
- pkg/adbanced_math-0.borked/test/test_simple_moving_average.rb
10
- pkg/adbanced_math-0.borked.gem
11
- pkg/adbanced_math-0.borked.tgz
12
- README.rdoc
13
- test/test_simple_moving_average.rb
@@ -1,11 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'advanced_math'
3
- s.version = '0.0.4'
4
- s.date = '2011-08-25'
5
- s.summary = "A simple gem for advanced and financial math calcualtions."
6
- s.description = "A simple gem for advanced and financial math calcualtions."
7
- s.authors = ["G Nagel"]
8
- s.email = 'glenn@mercury-wireless.com'
9
- s.files = Dir['**/*.*']
10
- s.homepage = 'https://github.com/gnagel/mercury-wireless-public'
11
- end
@@ -1,57 +0,0 @@
1
-
2
- module AdvancedMath
3
-
4
- # Simple Moving Average (SMA) calculator
5
- # Created: 2011-06-24
6
- # Author: G Nagel
7
- # Company: Mercury Wireless Software LLC
8
- class SimpleMovingAverage
9
- ###
10
- # Initialize the members:
11
- # range:
12
- # number of values to average
13
- # sum:
14
- # current sum of all values in the array
15
- # values:
16
- # array of values used as temporary storage
17
- ###
18
- def initialize(range)
19
- raise ArgumentError, "Range is nil" unless (range);
20
- raise ArgumentError, "Range must be >= 1" unless range.to_i >= 1;
21
- @range = range.to_i;
22
- @sum = 0;
23
- @values = Array.new();
24
- end
25
-
26
- ###
27
- # Add a value to the list.
28
- # If the list is < @range, then return nil.
29
- # Otherwise compute the SMA and return the value.
30
- ###
31
- def add(value)
32
- raise ArgumentError, "Value is nil" unless (value);
33
-
34
- # add the value to the end of the array.
35
- @values.push(value);
36
-
37
- # Calculate the sum of the array
38
- @sum += value.to_f;
39
-
40
- # Is the array less than the range?
41
- return nil if (@values.length() < @range)
42
-
43
- # Is the array larger than the range?
44
- @sum -= @values.shift.to_f() if (@values.length() > @range)
45
-
46
- # Compute the average
47
- return @sum.to_f / @range.to_f;
48
- end
49
- end
50
-
51
- ###
52
- # SMA is just an alias to SimpleMovingAverage
53
- ###
54
- class SMA < SimpleMovingAverage
55
- end
56
-
57
- end
@@ -1,51 +0,0 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + "/../lib/advanced_math.rb"
3
-
4
-
5
-
6
- class SimpleMovingAverageTest < Test::Unit::TestCase
7
- # Verify the constructor raises an ArgumentError if the "range" is invalid
8
- def test_sma_initialize_nil
9
- assert_raise(ArgumentError) { AdvancedMath::SimpleMovingAverage.new(nil); }
10
- end
11
-
12
- # Verify the constructor raises an ArgumentError if the "range" is invalid
13
- def test_sma_initialize_negative
14
- assert_raise(ArgumentError) { AdvancedMath::SimpleMovingAverage.new(-1); }
15
- end
16
-
17
- # Verify the constructor raises an ArgumentError if the "range" is invalid
18
- def test_sma_initialize_zero
19
- assert_raise(ArgumentError) { AdvancedMath::SimpleMovingAverage.new(0); }
20
- end
21
-
22
- # Verify the constructor doesn't raise an exception if the value is positive
23
- def test_sma_initialize_positive
24
- (1...1000).each do |i|
25
- assert_nothing_raised(ArgumentError) { AdvancedMath::SimpleMovingAverage.new(i); }
26
- end
27
- end
28
-
29
- # Verify "add" raises an ArgumentError if the "value" is invalid
30
- def test_sma_add_nil
31
- assert_raise(ArgumentError) { AdvancedMath::SimpleMovingAverage.new(1).add(nil); }
32
- end
33
-
34
- # Verify SMA of 1, always returns the same value
35
- def test_sma_add_1
36
- sma = AdvancedMath::SimpleMovingAverage.new(1);
37
- (1...1000).each do |i|
38
- assert_equal(i, sma.add(i));
39
- end
40
- end
41
-
42
- # Verify SMA of 2, always returns the same value - 0.5
43
- def test_sma_add_2
44
- sma = AdvancedMath::SimpleMovingAverage.new(2);
45
- assert_equal(nil, sma.add(1));
46
- (2...1000).each do |i|
47
- assert_equal(i - 0.5, sma.add(i));
48
- end
49
- end
50
-
51
- end