polynomials 0.4.3 → 0.4.4
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/.travis.yml +1 -1
- data/Gemfile +3 -3
- data/Gemfile.lock +6 -8
- data/README.markdown +19 -26
- data/Rakefile +3 -21
- data/VERSION +1 -1
- data/lib/polynomials.rb +1 -0
- data/lib/polynomials/analyzable.rb +15 -17
- data/lib/polynomials/plotable.rb +23 -0
- data/lib/polynomials/point.rb +13 -4
- data/lib/polynomials/polynomial.rb +12 -28
- data/polynomials.gemspec +7 -10
- data/test/analyzable_test.rb +6 -7
- data/test/polynomial_test.rb +6 -0
- data/test/test_helper.rb +3 -2
- metadata +9 -41
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -6,10 +6,10 @@ source "http://rubygems.org"
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
|
-
gem "
|
9
|
+
gem "rake"
|
10
10
|
gem "jeweler", "~> 1.6.0"
|
11
11
|
gem "simplecov", ">= 0"
|
12
|
-
gem 'awesome_print'
|
13
12
|
end
|
13
|
+
|
14
14
|
gem "activesupport"
|
15
|
-
gem
|
15
|
+
gem "i18n"
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activesupport (3.0.
|
5
|
-
awesome_print (0.3.2)
|
4
|
+
activesupport (3.0.9)
|
6
5
|
git (1.2.5)
|
7
|
-
i18n (0.
|
8
|
-
jeweler (1.6.
|
9
|
-
bundler (~> 1.0
|
6
|
+
i18n (0.6.0)
|
7
|
+
jeweler (1.6.2)
|
8
|
+
bundler (~> 1.0)
|
10
9
|
git (>= 1.2.5)
|
11
10
|
rake
|
12
|
-
rake (0.
|
11
|
+
rake (0.9.2)
|
13
12
|
simplecov (0.4.2)
|
14
13
|
simplecov-html (~> 0.4.4)
|
15
14
|
simplecov-html (0.4.5)
|
@@ -19,8 +18,7 @@ PLATFORMS
|
|
19
18
|
|
20
19
|
DEPENDENCIES
|
21
20
|
activesupport
|
22
|
-
awesome_print
|
23
|
-
bundler (~> 1.0.0)
|
24
21
|
i18n
|
25
22
|
jeweler (~> 1.6.0)
|
23
|
+
rake
|
26
24
|
simplecov
|
data/README.markdown
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
# Polynomials
|
2
|
-
|
3
|
-
[](http://travis-ci.org/mkorfmann/polynomials)
|
1
|
+
# Polynomials [](http://travis-ci.org/mkorfmann/polynomials)
|
4
2
|
|
5
3
|
## Example App
|
6
4
|
|
@@ -9,7 +7,7 @@ see the gem in action!
|
|
9
7
|
|
10
8
|
## Usage
|
11
9
|
|
12
|
-
|
10
|
+
```ruby
|
13
11
|
require 'polynomials'
|
14
12
|
require 'gnuplot'
|
15
13
|
include Polynomials
|
@@ -17,11 +15,10 @@ include Polynomials
|
|
17
15
|
|
18
16
|
polynomial = Polynomial.parse(ARGV[0])
|
19
17
|
|
20
|
-
points = polynomial.roots | polynomial.local_extrema |
|
21
|
-
polynomial.inflection_points
|
18
|
+
points = polynomial.roots | polynomial.local_extrema | polynomial.inflection_points
|
22
19
|
|
23
|
-
max_x = points.max_by(
|
24
|
-
min_x = points.min_by(
|
20
|
+
max_x = points.max_by(&:x)
|
21
|
+
min_x = points.min_by(&:x)
|
25
22
|
max_x = max_x == 0 ? max_x.x : 1
|
26
23
|
min_x = min_x == 0 ? min_x.x : -1
|
27
24
|
|
@@ -32,38 +29,34 @@ stop = max_x + difference/4.0
|
|
32
29
|
step = (start-stop).abs/1000.0
|
33
30
|
|
34
31
|
pointset = polynomial.pointset(start,stop,step)
|
35
|
-
data_x= pointset.map(
|
36
|
-
data_y = pointset.map(
|
32
|
+
data_x= pointset.map(&:first)
|
33
|
+
data_y = pointset.map(&:last)
|
37
34
|
|
38
35
|
Gnuplot.open do |gp|
|
39
36
|
Gnuplot::Plot.new(gp) do |plot|
|
40
|
-
plot.xrange
|
41
|
-
plot.title
|
42
|
-
plot.ylabel
|
43
|
-
plot.xlabel
|
37
|
+
plot.xrange "[#{start}:#{stop}]"
|
38
|
+
plot.title "Polynomial"
|
39
|
+
plot.ylabel "f(x)"
|
40
|
+
plot.xlabel "x"
|
44
41
|
plot.grid
|
45
|
-
plot.data
|
46
|
-
ds.with =
|
42
|
+
plot.data << Gnuplot::DataSet.new( [data_x,data_y] ) do |ds|
|
43
|
+
ds.with = "lines"
|
47
44
|
ds.linewidth = 0.2
|
48
|
-
ds.title =
|
45
|
+
ds.title = "f(x) = #{polynomial}"
|
49
46
|
ds.smooth
|
50
47
|
end
|
51
48
|
|
52
|
-
[:inflection_point,:root, :maximum, :minimum].each do
|
53
|
-
|
54
|
-
selected_points
|
55
|
-
points
|
56
|
-
plot.data <<
|
57
|
-
Gnuplot::DataSet.new([selected_points.map(&:x),
|
58
|
-
selected_points.map(&:y)]) do |ds|
|
59
|
-
ds.with = "points"
|
49
|
+
[:inflection_point,:root, :maximum, :minimum].each do |kind_of_point|
|
50
|
+
selected_points = points.select(&:"#{kind_of_point}?")
|
51
|
+
plot.data << Gnuplot::DataSet.new([selected_points.map(&:x), selected_points.map(&:y)]) do |ds|
|
52
|
+
ds.with = "points"
|
60
53
|
ds.linewidth = 2
|
61
54
|
ds.title = kind_of_point.to_s.pluralize.titleize
|
62
55
|
end
|
63
56
|
end
|
64
57
|
end
|
65
58
|
end
|
66
|
-
|
59
|
+
```
|
67
60
|
|
68
61
|
### Bash Command
|
69
62
|
<pre><code> % ruby examples/plot_only_mutual_data.rb '20.432 x^4 - 17.75 x^3 - 20x^2 + 5 x -50'</code></pre>
|
data/Rakefile
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
1
|
require 'bundler'
|
2
|
+
|
5
3
|
begin
|
6
4
|
Bundler.setup(:default, :development)
|
7
5
|
rescue Bundler::BundlerError => e
|
@@ -9,9 +7,11 @@ rescue Bundler::BundlerError => e
|
|
9
7
|
$stderr.puts "Run `bundle install` to install missing gems"
|
10
8
|
exit e.status_code
|
11
9
|
end
|
10
|
+
|
12
11
|
require 'rake'
|
13
12
|
|
14
13
|
require 'jeweler'
|
14
|
+
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
17
|
gem.name = "polynomials"
|
@@ -35,22 +35,4 @@ Rake::TestTask.new(:test) do |test|
|
|
35
35
|
test.verbose = true
|
36
36
|
end
|
37
37
|
|
38
|
-
#require 'rcov/rcovtask'
|
39
|
-
#Rcov::RcovTask.new do |test|
|
40
|
-
# test.libs << 'test'
|
41
|
-
# test.pattern = 'test/**/*_test.rb'
|
42
|
-
# test.verbose = true
|
43
|
-
# test.rcov_opts << '--exclude "gems/*"'
|
44
|
-
#end
|
45
|
-
#
|
46
38
|
task :default => :test
|
47
|
-
|
48
|
-
require 'rake/rdoctask'
|
49
|
-
Rake::RDocTask.new do |rdoc|
|
50
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
51
|
-
|
52
|
-
rdoc.rdoc_dir = 'rdoc'
|
53
|
-
rdoc.title = "polynomials #{version}"
|
54
|
-
rdoc.rdoc_files.include('README*')
|
55
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.4
|
data/lib/polynomials.rb
CHANGED
@@ -4,10 +4,13 @@ module Polynomials
|
|
4
4
|
MinimumOrMaximum = {[1.0,-1.0] => :maximum,[-1.0,1.0] => :minimum}
|
5
5
|
|
6
6
|
def strives_for
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
points = self.roots.map(&:x) | self.local_extrema.map(&:x)
|
8
|
+
return nil if points.empty?
|
9
|
+
points.minmax.zip([-1,1])
|
10
|
+
.map do |point,direction|
|
11
|
+
sign = self.(point + direction).sign
|
12
|
+
Extremum.new(Infinity * direction, sign * Infinity, sign < 0 ? :minimum : :maximum)
|
13
|
+
end
|
11
14
|
end
|
12
15
|
|
13
16
|
def inflection_points
|
@@ -28,7 +31,7 @@ module Polynomials
|
|
28
31
|
samples.push possible_extrema.last + 1
|
29
32
|
|
30
33
|
possible_extrema.zip(samples.each_cons(2)).inject(Set[]) do |set,(pe,sample)|
|
31
|
-
directions = sample.map { |x| derivative.(x).sign}
|
34
|
+
directions = sample.map { |x| derivative.(x).sign }
|
32
35
|
kind_of_extremum = MinimumOrMaximum[directions]
|
33
36
|
next set unless kind_of_extremum
|
34
37
|
set << Extremum.new(pe,self.calculate(pe), kind_of_extremum)
|
@@ -37,19 +40,14 @@ module Polynomials
|
|
37
40
|
|
38
41
|
def curvature_behaviour
|
39
42
|
hash = Hash.new {|h,k|h[k]=[]}
|
40
|
-
|
41
43
|
dd = self.derivative.derivative
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
end.with_index.inject(hash) do |hash,((curvature,values),i)|
|
51
|
-
hash.tap { |h| h[curvature].concat values.each {|a| a.map! { |p| (p.is_a? Point) ? p.x : p.first }}}
|
52
|
-
end
|
44
|
+
strives_for = derivative.strives_for
|
45
|
+
return nil if !strives_for
|
46
|
+
|
47
|
+
delimiter = [strives_for[0]] | derivative.local_extrema.to_a | [strives_for[1]]
|
48
|
+
delimiter.sort.each_cons(2).group_by do |b,_|
|
49
|
+
AfterExtremaCurvatureMapping[b.kind_of_extremum]
|
50
|
+
end.tap { |h| h.values.each { |a| a.each { |r| r.map!(&:x) }}}
|
53
51
|
end
|
54
52
|
end
|
55
53
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Polynomials
|
2
|
+
module Plotable
|
3
|
+
def pointset(start,stop,step=0.1)
|
4
|
+
data = []
|
5
|
+
x = start
|
6
|
+
while x < stop
|
7
|
+
data << [x,self.(x)]
|
8
|
+
x += step
|
9
|
+
end
|
10
|
+
data << [stop,self.(stop)]
|
11
|
+
end
|
12
|
+
|
13
|
+
def grouped_pointset(start,stop,step=0.1,grouped)
|
14
|
+
Hash[grouped.map do |key,intervals|
|
15
|
+
intervals = intervals.reject { |s,e| e < start || s > stop }
|
16
|
+
intervals = intervals.map do |s,e|
|
17
|
+
self.pointset([s,start].max, [e,stop].min, step)
|
18
|
+
end
|
19
|
+
[key,intervals]
|
20
|
+
end]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/polynomials/point.rb
CHANGED
@@ -4,13 +4,14 @@ module Polynomials
|
|
4
4
|
attr_accessor :x, :y
|
5
5
|
alias to_f x
|
6
6
|
|
7
|
-
|
8
|
-
self.class_eval do
|
9
|
-
define_method :"#{
|
10
|
-
self.is_a?
|
7
|
+
%w{Extremum Root InflectionPoint}.each do |special_point|
|
8
|
+
self.class_eval do
|
9
|
+
define_method :"#{special_point.underscore}?" do
|
10
|
+
self.is_a? Polynomials.const_get(special_point)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
14
15
|
def initialize(x,y)
|
15
16
|
@x,@y = x,y
|
16
17
|
end
|
@@ -69,4 +70,12 @@ module Polynomials
|
|
69
70
|
|
70
71
|
class InflectionPoint < Point
|
71
72
|
end
|
73
|
+
|
74
|
+
[:maximum,:minimum].each do |kind_of_extremum|
|
75
|
+
const_set(kind_of_extremum.to_s.capitalize, Class.new(Extremum) do
|
76
|
+
def initialize(x,y)
|
77
|
+
super x,y,kind_of_extremum
|
78
|
+
end
|
79
|
+
end)
|
80
|
+
end
|
72
81
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Polynomials
|
2
2
|
class Polynomial
|
3
3
|
include Analyzable
|
4
|
+
include Plotable
|
4
5
|
|
5
6
|
attr_accessor :terms
|
6
7
|
|
@@ -30,14 +31,13 @@ module Polynomials
|
|
30
31
|
alias call calculate
|
31
32
|
|
32
33
|
def derivative
|
33
|
-
new_function = self.alter do |
|
34
|
-
(
|
34
|
+
new_function = self.alter do |new_function, term|
|
35
|
+
(new_function.terms[term.exponent - 1].coefficient += term.exponent * term.coefficient) unless term.exponent.zero?
|
35
36
|
end
|
36
|
-
|
37
37
|
end
|
38
38
|
|
39
39
|
def roots
|
40
|
-
if
|
40
|
+
if terms[0].coefficient.zero? and !terms.values.map(&:coefficient).all?(&:zero?)
|
41
41
|
self.alter { |nf, term| nf.terms[term.exponent-self.lt.exponent].coefficient = term.coefficient }.roots << Root.new(0.0)
|
42
42
|
else
|
43
43
|
case self.degree
|
@@ -67,36 +67,21 @@ module Polynomials
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def ==(other)
|
70
|
-
|
71
|
-
self.terms.delete_if(&
|
70
|
+
check_if_zero = proc { |_,t| t.coefficient.zero? }
|
71
|
+
self.terms.delete_if(&check_if_zero) == other.terms.delete_if(&check_if_zero)
|
72
72
|
end
|
73
73
|
|
74
|
+
# greatest term
|
74
75
|
def gt
|
75
76
|
self.terms[self.degree]
|
76
77
|
end
|
77
78
|
|
79
|
+
# lowest term
|
78
80
|
def lt
|
79
|
-
self.terms[
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
data = []
|
84
|
-
x = start
|
85
|
-
while x < stop
|
86
|
-
data << [x,self.(x)]
|
87
|
-
x += step
|
88
|
-
end
|
89
|
-
data << [stop,self.(stop)]
|
90
|
-
end
|
91
|
-
|
92
|
-
def grouped_pointset(start,stop,step=0.1,grouped)
|
93
|
-
Hash[grouped.map do |key,intervals|
|
94
|
-
intervals = intervals.reject { |s,e| e < start || s > stop }
|
95
|
-
intervals = intervals.map do |s,e|
|
96
|
-
self.pointset([s,start].max, [e,stop].min, step)
|
97
|
-
end
|
98
|
-
[key,intervals]
|
99
|
-
end]
|
81
|
+
self.terms[
|
82
|
+
self.terms.reject { |_,t| t.coefficient.zero? }
|
83
|
+
.min_by{ |_,t| t.exponent}.first
|
84
|
+
]
|
100
85
|
end
|
101
86
|
|
102
87
|
def coefficients_till(n)
|
@@ -117,5 +102,4 @@ module Polynomials
|
|
117
102
|
end
|
118
103
|
protected :alter
|
119
104
|
end
|
120
|
-
|
121
105
|
end
|
data/polynomials.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{polynomials}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Manuel Korfmann"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-06-30}
|
13
13
|
s.description = %q{
|
14
14
|
This is a gem dedicated to parsing, manipulating and finding roots,extrema and inflection points of polynomials.
|
15
15
|
It can solve polynomial equations with a degree up to 4 by implementing formulas for solving quadratic, cubic and quartic functions.
|
@@ -33,6 +33,7 @@ It can solve polynomial equations with a degree up to 4 by implementing formulas
|
|
33
33
|
"lib/polynomials/analyzable.rb",
|
34
34
|
"lib/polynomials/exceptions.rb",
|
35
35
|
"lib/polynomials/formulas.rb",
|
36
|
+
"lib/polynomials/plotable.rb",
|
36
37
|
"lib/polynomials/point.rb",
|
37
38
|
"lib/polynomials/polynomial.rb",
|
38
39
|
"lib/polynomials/term.rb",
|
@@ -47,35 +48,31 @@ It can solve polynomial equations with a degree up to 4 by implementing formulas
|
|
47
48
|
s.homepage = %q{http://github.com/mkorfmann/polynomials}
|
48
49
|
s.licenses = ["MIT"]
|
49
50
|
s.require_paths = ["lib"]
|
50
|
-
s.rubygems_version = %q{1.
|
51
|
+
s.rubygems_version = %q{1.6.2}
|
51
52
|
s.summary = %q{parsing and computing data on polynomials}
|
52
53
|
|
53
54
|
if s.respond_to? :specification_version then
|
54
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
55
55
|
s.specification_version = 3
|
56
56
|
|
57
57
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
58
|
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
59
59
|
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
60
|
-
s.add_development_dependency(%q<
|
60
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
61
61
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
62
62
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
63
|
-
s.add_development_dependency(%q<awesome_print>, [">= 0"])
|
64
63
|
else
|
65
64
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
66
65
|
s.add_dependency(%q<i18n>, [">= 0"])
|
67
|
-
s.add_dependency(%q<
|
66
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
68
67
|
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
69
68
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
70
|
-
s.add_dependency(%q<awesome_print>, [">= 0"])
|
71
69
|
end
|
72
70
|
else
|
73
71
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
74
72
|
s.add_dependency(%q<i18n>, [">= 0"])
|
75
|
-
s.add_dependency(%q<
|
73
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
76
74
|
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
77
75
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
78
|
-
s.add_dependency(%q<awesome_print>, [">= 0"])
|
79
76
|
end
|
80
77
|
end
|
81
78
|
|
data/test/analyzable_test.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "#{File.dirname(File.expand_path(__FILE__))}/test_helper"
|
2
|
-
Infinity = 1.0/0
|
3
2
|
class TestAnalyzable < MiniTest::Unit::TestCase
|
4
3
|
include Polynomials
|
5
4
|
|
@@ -60,18 +59,18 @@ class TestAnalyzable < MiniTest::Unit::TestCase
|
|
60
59
|
|
61
60
|
def test_strives_for
|
62
61
|
polynomial = Polynomial.new(2,0,0)
|
63
|
-
assert_equal [Infinity,Infinity], polynomial.strives_for
|
62
|
+
assert_equal [Maximum.new(-Infinity,Infinity),Maximum.new(Infinity,Infinity)], polynomial.strives_for
|
64
63
|
polynomial = Polynomial.new(-2,0,0)
|
65
|
-
assert_equal [-Infinity,-Infinity], polynomial.strives_for
|
64
|
+
assert_equal [Minimum.new(-Infinity,-Infinity),Minimum.new(Infinity,-Infinity)], polynomial.strives_for
|
66
65
|
polynomial = Polynomial.new(2,0,0,0)
|
67
|
-
assert_equal [-Infinity,Infinity], polynomial.strives_for
|
66
|
+
assert_equal [Minimum.new(-Infinity,-Infinity),Maximum.new(Infinity,Infinity)], polynomial.strives_for
|
68
67
|
polynomial = Polynomial.new(-2,0,0,0)
|
69
|
-
assert_equal [Infinity,-Infinity], polynomial.strives_for
|
68
|
+
assert_equal [Maximum.new(-Infinity,Infinity),Minimum.new(Infinity,-Infinity)], polynomial.strives_for
|
70
69
|
polynomial = Polynomial.new(2)
|
71
70
|
assert_equal nil, polynomial.strives_for
|
72
71
|
|
73
72
|
polynomial = Polynomial.parse('+ 1.0 x^4 + 5.0 x^3 - 1.0 x^2 + 3.0 x + 5.0').derivative
|
74
|
-
assert_equal [-Infinity,Infinity], polynomial.strives_for
|
73
|
+
assert_equal [Minimum.new(-Infinity,-Infinity),Maximum.new(Infinity,Infinity)], polynomial.strives_for
|
75
74
|
end
|
76
75
|
|
77
76
|
def test_inflection_points_some_coefficients_of_derivative2_zero
|
@@ -86,6 +85,6 @@ class TestAnalyzable < MiniTest::Unit::TestCase
|
|
86
85
|
|
87
86
|
def test_strives_for_no_roots
|
88
87
|
polynomial = Polynomial.new(1,0,0,0,0)
|
89
|
-
assert_equal [Infinity,Infinity], polynomial.strives_for
|
88
|
+
assert_equal [Maximum.new(-Infinity,Infinity),Maximum.new(Infinity,Infinity)], polynomial.strives_for
|
90
89
|
end
|
91
90
|
end
|
data/test/polynomial_test.rb
CHANGED
@@ -95,4 +95,10 @@ class TestPolynomial < MiniTest::Unit::TestCase
|
|
95
95
|
polynomial = Polynomial.parse('5x + 2')
|
96
96
|
assert_equal 7, polynomial.(1)
|
97
97
|
end
|
98
|
+
|
99
|
+
def test_constant_zero_polynomial
|
100
|
+
constant_function = Polynomial.new(0)
|
101
|
+
assert_equal Set[], constant_function.roots
|
102
|
+
assert_equal nil, constant_function.curvature_behaviour
|
103
|
+
end
|
98
104
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polynomials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 4
|
8
|
-
- 3
|
9
|
-
version: 0.4.3
|
4
|
+
prerelease:
|
5
|
+
version: 0.4.4
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Manuel Korfmann
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-06-30 00:00:00 +02:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -24,8 +20,6 @@ dependencies:
|
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
23
|
version: "0"
|
30
24
|
type: :runtime
|
31
25
|
prerelease: false
|
@@ -37,24 +31,18 @@ dependencies:
|
|
37
31
|
requirements:
|
38
32
|
- - ">="
|
39
33
|
- !ruby/object:Gem::Version
|
40
|
-
segments:
|
41
|
-
- 0
|
42
34
|
version: "0"
|
43
35
|
type: :runtime
|
44
36
|
prerelease: false
|
45
37
|
version_requirements: *id002
|
46
38
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
39
|
+
name: rake
|
48
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
49
41
|
none: false
|
50
42
|
requirements:
|
51
|
-
- -
|
43
|
+
- - ">="
|
52
44
|
- !ruby/object:Gem::Version
|
53
|
-
|
54
|
-
- 1
|
55
|
-
- 0
|
56
|
-
- 0
|
57
|
-
version: 1.0.0
|
45
|
+
version: "0"
|
58
46
|
type: :development
|
59
47
|
prerelease: false
|
60
48
|
version_requirements: *id003
|
@@ -65,10 +53,6 @@ dependencies:
|
|
65
53
|
requirements:
|
66
54
|
- - ~>
|
67
55
|
- !ruby/object:Gem::Version
|
68
|
-
segments:
|
69
|
-
- 1
|
70
|
-
- 6
|
71
|
-
- 0
|
72
56
|
version: 1.6.0
|
73
57
|
type: :development
|
74
58
|
prerelease: false
|
@@ -80,25 +64,10 @@ dependencies:
|
|
80
64
|
requirements:
|
81
65
|
- - ">="
|
82
66
|
- !ruby/object:Gem::Version
|
83
|
-
segments:
|
84
|
-
- 0
|
85
67
|
version: "0"
|
86
68
|
type: :development
|
87
69
|
prerelease: false
|
88
70
|
version_requirements: *id005
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: awesome_print
|
91
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
92
|
-
none: false
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
segments:
|
97
|
-
- 0
|
98
|
-
version: "0"
|
99
|
-
type: :development
|
100
|
-
prerelease: false
|
101
|
-
version_requirements: *id006
|
102
71
|
description: "\n\
|
103
72
|
This is a gem dedicated to parsing, manipulating and finding roots,extrema and inflection points of polynomials.\n\
|
104
73
|
It can solve polynomial equations with a degree up to 4 by implementing formulas for solving quadratic, cubic and quartic functions.\n "
|
@@ -124,6 +93,7 @@ files:
|
|
124
93
|
- lib/polynomials/analyzable.rb
|
125
94
|
- lib/polynomials/exceptions.rb
|
126
95
|
- lib/polynomials/formulas.rb
|
96
|
+
- lib/polynomials/plotable.rb
|
127
97
|
- lib/polynomials/point.rb
|
128
98
|
- lib/polynomials/polynomial.rb
|
129
99
|
- lib/polynomials/term.rb
|
@@ -148,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
118
|
requirements:
|
149
119
|
- - ">="
|
150
120
|
- !ruby/object:Gem::Version
|
151
|
-
hash:
|
121
|
+
hash: 3457251127404448824
|
152
122
|
segments:
|
153
123
|
- 0
|
154
124
|
version: "0"
|
@@ -157,13 +127,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
127
|
requirements:
|
158
128
|
- - ">="
|
159
129
|
- !ruby/object:Gem::Version
|
160
|
-
segments:
|
161
|
-
- 0
|
162
130
|
version: "0"
|
163
131
|
requirements: []
|
164
132
|
|
165
133
|
rubyforge_project:
|
166
|
-
rubygems_version: 1.
|
134
|
+
rubygems_version: 1.6.2
|
167
135
|
signing_key:
|
168
136
|
specification_version: 3
|
169
137
|
summary: parsing and computing data on polynomials
|