Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e1f8ffe

Browse files
only need the Fraction class
1 parent 8edd25b commit e1f8ffe

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

‎ch10/linearEquationTests.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# permissions and limitations under the License.
1717

1818
import datetime
19-
import fractions
19+
from fractionsimportFraction
2020
import random
2121
import unittest
2222

@@ -74,7 +74,7 @@ def e2(genes):
7474
def test_3_unknowns(self):
7575
geneRange = [i for i in range(-5, 5) if i != 0]
7676
geneset = [i for i in set(
77-
fractions.Fraction(d, e)
77+
Fraction(d, e)
7878
for d in geneRange
7979
for e in geneRange if e != 0)]
8080

@@ -91,16 +91,16 @@ def e2(genes):
9191

9292
def e3(genes):
9393
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
9696

9797
equations = [e1, e2, e3]
9898
self.solve_unknowns(3, geneset, equations, fnGenesToInputs)
9999

100100
def test_4_unknowns(self):
101101
geneRange = [i for i in range(-13, 13) if i != 0]
102102
geneset = [i for i in set(
103-
fractions.Fraction(d, e)
103+
Fraction(d, e)
104104
for d in geneRange
105105
for e in geneRange if e != 0)]
106106

@@ -109,34 +109,34 @@ def fnGenesToInputs(genes):
109109

110110
def e1(genes):
111111
x, y, z, a = genes
112-
return fractions.Fraction(1, 15) * x \
112+
return Fraction(1, 15) * x \
113113
- 2 * y \
114114
- 15 * z \
115-
- fractions.Fraction(4, 5) * a \
115+
- Fraction(4, 5) * a \
116116
- 3
117117

118118
def e2(genes):
119119
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 \
122122
+ 12 * z \
123123
- a \
124124
- 17
125125

126126
def e3(genes):
127127
x, y, z, a = genes
128128
return -13 * x \
129-
+ fractions.Fraction(3, 10) * y \
129+
+ Fraction(3, 10) * y \
130130
- 6 * z \
131-
- fractions.Fraction(2, 5) * a \
131+
- Fraction(2, 5) * a \
132132
- 17
133133

134134
def e4(genes):
135135
x, y, z, a = genes
136-
return fractions.Fraction(1, 2) * x \
136+
return Fraction(1, 2) * x \
137137
+ 2 * y \
138-
+ fractions.Fraction(7, 4) * z \
139-
+ fractions.Fraction(4, 3) * a \
138+
+ Fraction(7, 4) * z \
139+
+ Fraction(4, 3) * a \
140140
+ 9
141141

142142
equations = [e1, e2, e3, e4]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /