16
16
# permissions and limitations under the License.
17
17
18
18
import datetime
19
- import fractions
19
+ from fractions import Fraction
20
20
import random
21
21
import unittest
22
22
@@ -74,7 +74,7 @@ def e2(genes):
74
74
def test_3_unknowns (self ):
75
75
geneRange = [i for i in range (- 5 , 5 ) if i != 0 ]
76
76
geneset = [i for i in set (
77
- fractions . Fraction (d , e )
77
+ Fraction (d , e )
78
78
for d in geneRange
79
79
for e in geneRange if e != 0 )]
80
80
@@ -91,16 +91,16 @@ def e2(genes):
91
91
92
92
def e3 (genes ):
93
93
x , y , z = genes
94
- return 2 * z * fractions . Fraction (6 , x ) \
95
- + 3 * fractions . Fraction (y , 2 ) - 6
94
+ return 2 * z * Fraction (6 , x ) \
95
+ + 3 * Fraction (y , 2 ) - 6
96
96
97
97
equations = [e1 , e2 , e3 ]
98
98
self .solve_unknowns (3 , geneset , equations , fnGenesToInputs )
99
99
100
100
def test_4_unknowns (self ):
101
101
geneRange = [i for i in range (- 13 , 13 ) if i != 0 ]
102
102
geneset = [i for i in set (
103
- fractions . Fraction (d , e )
103
+ Fraction (d , e )
104
104
for d in geneRange
105
105
for e in geneRange if e != 0 )]
106
106
@@ -109,34 +109,34 @@ def fnGenesToInputs(genes):
109
109
110
110
def e1 (genes ):
111
111
x , y , z , a = genes
112
- return fractions . Fraction (1 , 15 ) * x \
112
+ return Fraction (1 , 15 ) * x \
113
113
- 2 * y \
114
114
- 15 * z \
115
- - fractions . Fraction (4 , 5 ) * a \
115
+ - Fraction (4 , 5 ) * a \
116
116
- 3
117
117
118
118
def e2 (genes ):
119
119
x , y , z , a = genes
120
- return - fractions . Fraction (5 , 2 ) * x \
121
- - fractions . Fraction (9 , 4 ) * y \
120
+ return - Fraction (5 , 2 ) * x \
121
+ - Fraction (9 , 4 ) * y \
122
122
+ 12 * z \
123
123
- a \
124
124
- 17
125
125
126
126
def e3 (genes ):
127
127
x , y , z , a = genes
128
128
return - 13 * x \
129
- + fractions . Fraction (3 , 10 ) * y \
129
+ + Fraction (3 , 10 ) * y \
130
130
- 6 * z \
131
- - fractions . Fraction (2 , 5 ) * a \
131
+ - Fraction (2 , 5 ) * a \
132
132
- 17
133
133
134
134
def e4 (genes ):
135
135
x , y , z , a = genes
136
- return fractions . Fraction (1 , 2 ) * x \
136
+ return Fraction (1 , 2 ) * x \
137
137
+ 2 * y \
138
- + fractions . Fraction (7 , 4 ) * z \
139
- + fractions . Fraction (4 , 3 ) * a \
138
+ + Fraction (7 , 4 ) * z \
139
+ + Fraction (4 , 3 ) * a \
140
140
+ 9
141
141
142
142
equations = [e1 , e2 , e3 , e4 ]
0 commit comments