rational_number 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 794dc0823355a2349f3f92c556d9256119791143
4
- data.tar.gz: 7560fbf7d62ba9aefb95f243ad1ca16142591c96
3
+ metadata.gz: 614d4ca60dcdf859b4fac3018350a0fee61cfe68
4
+ data.tar.gz: 23218cd6a192d2dd0d5c75f455251e2bc892a21b
5
5
  SHA512:
6
- metadata.gz: b0c44b8906a602e9a715878855762692a532e369a6928f90b212487829890b0d1eff7eb732586a174dcf98dc5b37d36d718dd893398bd4f37ab048313687d315
7
- data.tar.gz: ee14b91f09f34c9045c0ec27bdb0a47352d89027dcd2e752ab59e4fdab765315dee0718cd2ebfc3f5821142ae6f4529c42d4a9c907148023a6af4417b7198c1c
6
+ metadata.gz: 15bbc836c11981635c08ab04b2efabf63bcea96f0b3e697b627e1612e767d7a9ead96081a6dbfc45fb844833f6379586bbc90bb2774492143373f08903e6533e
7
+ data.tar.gz: e8560caa78b7555c8c080f5ec333961eb20f528db6e7976113cc999ce278bc08226bea87ebd600e07fa07132edac78310df5d476e54811191c86178c22b1e570
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rational_number (0.1.1)
4
+ rational_number (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module RationalNumberGem
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -12,6 +12,8 @@
12
12
  # It is possible to verify child/parent relationships without even checking with a database.
13
13
  #
14
14
 
15
+ require 'bigdecimal'
16
+
15
17
  class RationalNumber # < Object
16
18
  include Comparable
17
19
  attr_reader :nv, :dv, :snv, :sdv, :number
@@ -139,9 +141,9 @@ class RationalNumber # < Object
139
141
  @snv = snv
140
142
  @sdv = sdv
141
143
  if nv == 0 and dv == 0
142
- @number = Float(0)
144
+ @number = BigDecimal(0)
143
145
  else
144
- @number = Float(nv)/Float(dv)
146
+ @number = BigDecimal(nv)/BigDecimal(dv)
145
147
  end
146
148
  end
147
149
 
@@ -82,12 +82,12 @@ describe "RationalNumber" do
82
82
  @root.dv.should == 1
83
83
  @root.snv.should == 1
84
84
  @root.sdv.should == 0
85
- @root.number.should == Float(0)
85
+ @root.number.should == BigDecimal(0)
86
86
  end
87
87
 
88
88
  it "should create a 0 based rational number without getting div by zero" do
89
89
  test = RationalNumber.new(0,0,0,0)
90
- test.number.should == Float(0)
90
+ test.number.should == BigDecimal(0)
91
91
  end
92
92
 
93
93
  it "should get the first child values" do
@@ -95,7 +95,7 @@ describe "RationalNumber" do
95
95
  @first_child.dv.should == 1
96
96
  @first_child.snv.should == 2
97
97
  @first_child.sdv.should == 1
98
- @first_child.number.should == Float(@first_child.nv)/Float(@first_child.dv)
98
+ @first_child.number.should == BigDecimal(@first_child.nv)/BigDecimal(@first_child.dv)
99
99
  end
100
100
 
101
101
  it "should verify the parent values of the first child" do
@@ -116,7 +116,7 @@ describe "RationalNumber" do
116
116
  fifth_child.dv.should == 1
117
117
  fifth_child.snv.should == 6
118
118
  fifth_child.sdv.should == 1
119
- fifth_child.number.should == Float(fifth_child.nv)/Float(fifth_child.dv)
119
+ fifth_child.number.should == BigDecimal(fifth_child.nv)/BigDecimal(fifth_child.dv)
120
120
  end
121
121
 
122
122
  it "should get the next sibling from first child" do
@@ -125,7 +125,7 @@ describe "RationalNumber" do
125
125
  next_sibling.dv.should == 1
126
126
  next_sibling.snv.should == 3
127
127
  next_sibling.sdv.should == 1
128
- next_sibling.number.should == Float(next_sibling.nv)/Float(next_sibling.dv)
128
+ next_sibling.number.should == BigDecimal(next_sibling.nv)/BigDecimal(next_sibling.dv)
129
129
  end
130
130
 
131
131
  it "should get fifth sibling from first child" do
@@ -134,7 +134,7 @@ describe "RationalNumber" do
134
134
  fifth_sibling.dv.should == 1
135
135
  fifth_sibling.snv.should == 6
136
136
  fifth_sibling.sdv.should == 1
137
- fifth_sibling.number.should == Float(fifth_sibling.nv)/Float(fifth_sibling.dv)
137
+ fifth_sibling.number.should == BigDecimal(fifth_sibling.nv)/BigDecimal(fifth_sibling.dv)
138
138
  end
139
139
 
140
140
  it "should verify two children of the first child" do
@@ -143,7 +143,7 @@ describe "RationalNumber" do
143
143
  child_1_1.dv.should == 2
144
144
  child_1_1.snv.should == 5
145
145
  child_1_1.sdv.should == 3
146
- child_1_1.number.should == Float(child_1_1.nv)/Float(child_1_1.dv)
146
+ child_1_1.number.should == BigDecimal(child_1_1.nv)/BigDecimal(child_1_1.dv)
147
147
 
148
148
  child_1_3 = @first_child.child_from_position(3)
149
149
 
@@ -151,7 +151,7 @@ describe "RationalNumber" do
151
151
  child_1_3.dv.should == 4
152
152
  child_1_3.snv.should == 9
153
153
  child_1_3.sdv.should == 5
154
- child_1_3.number.should == Float(child_1_3.nv)/Float(child_1_3.dv)
154
+ child_1_3.number.should == BigDecimal(child_1_3.nv)/BigDecimal(child_1_3.dv)
155
155
  end
156
156
 
157
157
  it "should verify the position of three rational numbers" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rational_number
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leif Ringstad