def shouldDoLimitedSubtracts(self): v1 = ScientificFloat("3.14") v2 = ScientificFloat("3.141") self.assertAlmostEqual(v1, v2, 2) r1 = v1 - 3.13 self.assertAlmostEqual(r1, .01, 2) r2 = 3.15 - v1 self.assertAlmostEqual(r2, .01, 2)
class MockObject(Fixture): _typeDict = { "sFloat1": ScientificFloat, "sFloat2": ScientificFloat, } sFloat1 = ScientificFloat("3.14") def sFloat2(self): return self.sFloat1
def testApplicationProtocolEquals(self): obj = self.pro.parse(self.cell.text()) assert self.pro.equals(self.cell.text(), obj) assert self.pro.equals(ScientificFloat("2.798"), obj)
def shouldDoComparesWell(self): pi = 3.141592865 assert ScientificFloat("3.14") == pi assert ScientificFloat("3.142") == pi # original 3.141 wrong! assert ScientificFloat("3.1416") == pi # original 3.1415 wrong! assert ScientificFloat("3.14159") == pi assert ScientificFloat("3.141592865") == pi assert (ScientificFloat("3.140") == pi) is False assert (ScientificFloat("3.144") == pi) is False assert (ScientificFloat("3.1414") == pi) is False assert (ScientificFloat("3.141592863") == pi) is False assert ScientificFloat("3.141592863") != pi assert ScientificFloat("2.5") < pi av = 6.02e23 assert ScientificFloat("6.0e23") == av assert ScientificFloat("12") == 12.0 assert ScientificFloat("11") == 11 assert ScientificFloat("-12.05") == -12.051