def _reduceSelf(self): """ Parse our unit and reduce ourselves to the smallest representation """ if isinstance(self.unit, basestring): self.unit = self.__findUnit() a = self.amount * self.prefix self.amount, self.prefix = Prefix.closestPrefix(a)
def testSimplePrefix(self): r = Prefix.closestPrefix(1000) assert r == (1.0, Prefix.Prefixes.kilo)
def testNegativePrefix(self): r = Prefix.closestPrefix(-1000) assert r == (-1.0, Prefix.Prefixes.kilo), r
def testSmallPrefix(self): r = Prefix.closestPrefix(0.05) assert r == (50, Prefix.Prefixes.milli)
def testComplexPrefix(self): r = Prefix.closestPrefix(1024) assert r == (1.024, Prefix.Prefixes.kilo)