linear1 1.0.0.pre → 1.0.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
  SHA1:
3
- metadata.gz: 0958577ede7ba8fa57fd241fc9a29aae34cd911b
4
- data.tar.gz: c8266881e23d9eab12c5538f0ee408eaf2271fe0
3
+ metadata.gz: 31aee81c2882bacd6ef1a027d30a18285e13ad48
4
+ data.tar.gz: aff302ca97029bc3ca08288609a6da4e7acbec51
5
5
  SHA512:
6
- metadata.gz: f1311e4c1482095f42a3f034d32ec7a87c00f45b8d779d8fd004e5ee2356d76d88c1a613f18e78e5bc9e78bdc2a792696485c7e2c2b889e78fc876fdc28cc1e8
7
- data.tar.gz: 41fff4658e2866970b790045db11b208a5a4bc19ae2e1ee56695d640f3e4cd7d6aeb8acc3f181f950fdb9501278581c503fa368c4f8286543d633b9cd741aa69
6
+ metadata.gz: 6a224cec4069c0ce61512d5dc99fb208f8a56388436f7789bccf2007ad8d0e4654e2967d96f185db7c0184f3033c34e00a3aaf968bdaec5bc8718e7e307a7319
7
+ data.tar.gz: 7e934f04c40b81c1f07f77ff4e2f633d17a00fb95182db37c41ff77383bc0b60fca256ffd63761f10adb8b570be27554812dbd133c7391641a42bb372ba1e1d7
@@ -3,6 +3,7 @@ module Linear1
3
3
  class ArthmeticSequence < Function
4
4
  attr_reader :a, :common_difference
5
5
  alias d common_difference
6
+ private :slope, :y_intercept
6
7
  alias to_a a
7
8
  alias slope d
8
9
  def initialize a
@@ -11,7 +12,7 @@ module Linear1
11
12
  raise ArgumentError, "Elements must have a common difference" unless a[i+1] - a[i] == a[i+2] - a[i+1]
12
13
  i += 1
13
14
  end
14
- @common_difference, @a = a[1] - a[0], a
15
+ @common_difference, @a = display_num(a[1]) - display_num(a[0]), a
15
16
  super @common_difference, @a[0]
16
17
  end
17
18
  def to_s # Modified to count from zero instead of one
@@ -7,7 +7,7 @@ module Linear1
7
7
  Function.new ARGV[i1], ARGV[i1 + 1], ARGV[i1 + 2]
8
8
  end
9
9
  def initialize(slope=1, y_intercept=0, power=1)
10
- @slope, @y_intercept, @power = slope.to_f, y_intercept.to_f, power.to_i
10
+ @slope, @y_intercept, @power = display_num(slope), display_num(y_intercept), display_num(power)
11
11
  end
12
12
  # @param x [Integer, Float]
13
13
  # @return [Integer, Float]
@@ -22,13 +22,16 @@ module Linear1
22
22
  alias zero x_intercept
23
23
  alias solution x_intercept
24
24
  alias root x_intercept
25
- def to_s
26
- "f(x) = #{idx slope.to_i if slope.to_i == slope}x#{power_string unless power == 1}#{" + #{@y_intercept.to_i if @y_intercept.to_i == @y_intercept}" unless direct_variation?}"
25
+ alias solve root
26
+ def to_s # @return [String] the equation
27
+ "f(x) = #{idx display_num slope}x#{power_string unless power == 1}#{" + #{display_num @y_intercept}" unless direct_variation?}"
27
28
  end
28
- def direct_variation?
29
+ def direct_variation? # @return [Boolean]
29
30
  y_intercept.zero? and power == 1
30
31
  end
31
32
  alias dv? direct_variation?
33
+ # @return [DirectVariation]
34
+ # @raise [TypeError]
32
35
  def to_direct_variation
33
36
  if direct_variation?
34
37
  require "linear1/direct_variation"
@@ -68,6 +71,17 @@ module Linear1
68
71
  s
69
72
  end
70
73
  end
74
+ def display_num num
75
+ if num.to_r.to_s == num.to_s
76
+ num.to_r
77
+ elsif num.to_i.to_s == num.to_s
78
+ num.to_i
79
+ elsif num.to_f.to_s == num.to_s
80
+ num.to_f
81
+ elsif num.to_c.to_s == num.to_s
82
+ num.to_c
83
+ end
84
+ end
71
85
  end
72
86
  end
73
87
 
@@ -3,8 +3,8 @@ module Linear1
3
3
  class PointSlope < Function
4
4
  attr_reader :x1, :y1
5
5
  private :y_intercept, :power
6
- def initialize slope, x, y
7
- @slope, @x1, @y1 = slope.to_f, x.to_f, y.to_f
6
+ def initialize x, y, slope
7
+ @slope, @x1, @y1 = display_num(slope), display_num(x), display_num(y)
8
8
  super @slope, @x1 - @y1
9
9
  end
10
10
  def self.find index
@@ -0,0 +1,14 @@
1
+ require "linear1/point_slope"
2
+ RSpec.describe Linear1::PointSlope do
3
+ describe "#new" do
4
+ [ [6, 3, 5], [-2, 1, -3], [-4, 2, 0] ].each do |spec|
5
+ context "given #{spec[0]}, #{spec[1]}, #{spec[2]}" do
6
+ subject {Linear1::PointSlope.new spec[0], spec[1], spec[2]}
7
+ it "should not raise error" do
8
+ expect{Linear1::PointSlope.new spec[0], spec[1], spec[2]}.to_not raise_error
9
+ end
10
+ its(:to_slope_intercept) {is_expected.to be_instance_of Linear1::SlopeIntercept}
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,4 +1,5 @@
1
1
  require "linear1/slope_intercept"
2
+ require "rational"
2
3
  include Linear1
3
4
  RSpec.describe SlopeIntercept do
4
5
  describe "#new" do
@@ -16,5 +17,16 @@ RSpec.describe SlopeIntercept do
16
17
  it {is_expected.to_not be_direct_variation}
17
18
  its(:to_s) {is_expected.to eq "y = 3x + 6"}
18
19
  end
20
+ [ [3, 5], [-2, -9], [Rational("2/3"), 3], [Rational("-5/8"), -2], [-5, -3] ].each do |spec|
21
+ context "given #{spec[0]}, #{spec[1]}" do
22
+ subject {SlopeIntercept.new spec[0], spec[1]}
23
+ its(:to_s) {is_expected.to eq "y = #{spec[0]}x + #{spec[1]}"}
24
+ it "should be graphable" do
25
+ require "linear1/graph"
26
+ expect{Graph.new subject}.to_not raise_error
27
+ end
28
+ end
29
+ end
30
+
19
31
  end
20
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linear1
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Perlmutter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-29 00:00:00.000000000 Z
11
+ date: 2015-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -62,6 +62,7 @@ files:
62
62
  - spec/lib/linear1/direct_variation_spec.rb
63
63
  - spec/lib/linear1/function_spec.rb
64
64
  - spec/lib/linear1/graph_spec.rb
65
+ - spec/lib/linear1/point_slope_spec.rb
65
66
  - spec/lib/linear1/slope_intercept_spec.rb
66
67
  - spec/lib/linear1/standard_spec.rb
67
68
  homepage:
@@ -79,9 +80,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
80
  version: '0'
80
81
  required_rubygems_version: !ruby/object:Gem::Requirement
81
82
  requirements:
82
- - - ">"
83
+ - - ">="
83
84
  - !ruby/object:Gem::Version
84
- version: 1.3.1
85
+ version: '0'
85
86
  requirements: []
86
87
  rubyforge_project:
87
88
  rubygems_version: 2.2.2
@@ -92,5 +93,6 @@ test_files:
92
93
  - spec/lib/linear1/direct_variation_spec.rb
93
94
  - spec/lib/linear1/function_spec.rb
94
95
  - spec/lib/linear1/graph_spec.rb
96
+ - spec/lib/linear1/point_slope_spec.rb
95
97
  - spec/lib/linear1/slope_intercept_spec.rb
96
98
  - spec/lib/linear1/standard_spec.rb