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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rational_number/version.rb +1 -1
- data/lib/rational_number.rb +4 -2
- data/spec/rational_number_spec.rb +8 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 614d4ca60dcdf859b4fac3018350a0fee61cfe68
|
4
|
+
data.tar.gz: 23218cd6a192d2dd0d5c75f455251e2bc892a21b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15bbc836c11981635c08ab04b2efabf63bcea96f0b3e697b627e1612e767d7a9ead96081a6dbfc45fb844833f6379586bbc90bb2774492143373f08903e6533e
|
7
|
+
data.tar.gz: e8560caa78b7555c8c080f5ec333961eb20f528db6e7976113cc999ce278bc08226bea87ebd600e07fa07132edac78310df5d476e54811191c86178c22b1e570
|
data/Gemfile.lock
CHANGED
data/lib/rational_number.rb
CHANGED
@@ -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 =
|
144
|
+
@number = BigDecimal(0)
|
143
145
|
else
|
144
|
-
@number =
|
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 ==
|
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 ==
|
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 ==
|
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 ==
|
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 ==
|
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 ==
|
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 ==
|
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 ==
|
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
|