def testiSub2(self): self.b -= Bruch(2) assert (self.b == Bruch(-1, 2))
def testiAdd(self): self.b += 1 assert (self.b == Bruch(5, 2))
def setUp(self): self.b = Bruch(3, 2) self.b2 = Bruch(self.b) self.b3 = Bruch(4, 2) pass
''' Created on 28.12.2013 @author: uhs374h ''' from bruch.Bruch import * from random import randint if __name__ == '__main__': b1=Bruch(3,4) b2=Bruch(3,4)+b1 z1,z3=b1 z2=b1.nenner print(z1,z2) b3=3+b1+Bruch(1,4) b4=3/b3+3 b3+=Bruch(3,2) b0=Bruch(4,3) print(str(b1)+" == invert "+str(b0),b1== ~b0 ) print(b3) b3=-b3 print(b3 is not b2) b5=Bruch(b3.zaehler,b3.nenner) print(b3 is b5) b4=4*b4-Bruch(2,4)-b3**2 print(b1,'=',float(b1)) print(hex(int(b1+123))) print(oct(int(b1+123))) print(int(b1+123)) print(b2,'=',float(b2)) print(b3,'=',float(b3)) print(b4,'=',float(b4))
def testplus(self): self.b = self.b + Bruch(4, 5) assert (float(self.b) == 2.3)
def testPow(self): h = 4 assert (self.b2**h == Bruch(self.b2.zaehler**h, self.b2.nenner**h))
def testNeg(self): b4 = Bruch(-3, 2) assert (-b4 == Bruch(3, 2))
def testFloat(self): b = Bruch(3, 4) assert (float(b) == 0.75)
def testdivZeroError2(self): self.assertRaises(ZeroDivisionError, self.b2.__truediv__, Bruch(0, 3))
def testrmal(self): self.b2 = 2 * Bruch(3, 2) assert (float(self.b2) == 3)
def testdiv(self): self.b = self.b / Bruch(4) assert (float(self.b) == 0.375)
def testiMul2(self): self.b *= Bruch(2) assert (self.b == 3)
def testmal(self): self.b = self.b * Bruch(4) assert (float(self.b) == 6)
def testrsub(self): self.b2 = 3 - Bruch(3, 2) assert (float(self.b2) == 1.5)
def testInvert(self): z, n = 5, 4 b = Bruch(z, n) assert (~b == Bruch(n, z))
def testrdivZeroError(self): bneu = Bruch(0, 3) self.assertRaises(ZeroDivisionError, bneu.__rtruediv__, 3)
def testInteger(self): self.b2 = Bruch(3, 1) assert (str(self.b2) == '(3)')
def testiDiv(self): self.b /= 2 assert (self.b == Bruch(3, 4))
def testAbs(self): b4 = Bruch(-3, 2) assert (abs(b4) == Bruch(3, 2))
def testiDiv2(self): self.b /= Bruch(2) assert (self.b == Bruch(3, 4))
def testrdiv(self): self.b2 = 2 / Bruch(2) assert (float(self.b2) == 1)
def testInt(self): b = Bruch(5, 4) assert (int(b) == 1)
def teststr2(self): b2 = Bruch(-3, -2) str1 = "(3/2)" assert (str(b2) == str1)
def testTuple(self): z, n = Bruch(3, 4) assert (z == 3 and n == 4)
def testradd(self): self.b2 = 3 + Bruch(3, 2) assert (float(self.b2) == 4.5)
def testTuple2(self): z, n = self.b self.assertEqual(Bruch(z, n), self.b)
def testiAdd2(self): self.b += Bruch(1) assert (self.b == Bruch(5, 2))
def testComplex(self): b = Bruch(3, 4) assert (complex(b) == 0.75)
def testminus(self): self.b = self.b - Bruch(4, 5) assert (float(self.b) == 0.7)
def testiSub(self): self.b -= 2 assert (self.b == Bruch(-1, 2))