def test_arithmetic(self): """ Tests a series of arithmetic operations around the decimal data structure (critical operations). """ result = colony.Decimal(12.2) * 34.23 self.assertEqual(result, 417.606) result = colony.Decimal(12687.23) * 34.132 self.assertEqual(result, 433040.53436) result = colony.Decimal(532687.23) * 4534.23 self.assertEqual(result, 2415326418.8829) result = 12.2 * 34.23 self.assertNotEqual(result, 417.606) result = colony.Decimal(88.151) - 88.15 self.assertEqual(result, 0.001) result = 88.151 - 88.15 self.assertNotEqual(result, 0.001) result = colony.Decimal(888888888.151) - 88.55 self.assertEqual(result, 888888799.601) result = 888888888.151 - 88.55 self.assertNotEqual(result, 888888799.601) result = colony.Decimal(88.151) - 823.35 self.assertEqual(result, -735.199) result = 88.151 - 823.35 self.assertNotEqual(result, -735.199) result = colony.Decimal(88.151) - 823.35 self.assertEqual(type(result), colony.Decimal) result = 88.151 - 823.35 self.assertEqual(type(result), float) result = colony.Decimal(1.55) self.assertEqual(result, 1.55) result = colony.Decimal(9999999999.155555555555555555) self.assertEqual(result, 9999999999.15555555555555555) result = colony.Decimal(88.151) / 1 self.assertEqual(result, 88.151) self.assertEqual(type(result), colony.Decimal) result = sum([colony.Decimal(88.151)]) self.assertEqual(result, 88.151) self.assertEqual(type(result), colony.Decimal) result = 88 - colony.Decimal(88.15) self.assertEqual(result, -0.15) self.assertEqual(type(result), colony.Decimal) result = 88.151 - colony.Decimal(88.15) self.assertEqual(result, 0.001) self.assertEqual(type(result), colony.Decimal) result = colony.Decimal(3348.5) * colony.Decimal(0.23) self.assertEqual(result, 770.155) self.assertEqual(type(result), colony.Decimal) result = colony.rounds(result, 2) self.assertEqual(result, 770.16) self.assertEqual(type(result), colony.Decimal)
def test_rounds(self): is_new = colony.round_is_new() result = colony.rounds(2.675, 2) self.assertEqual(result, 2.68) result = colony.rounds(2.685, 2) self.assertEqual(result, 2.69) result = colony.rounds(2.68, 2) self.assertEqual(result, 2.68) result = colony.rounds(2.683, 2) self.assertEqual(result, 2.68) result = colony.rounds(2.689, 2) self.assertEqual(result, 2.69) result = colony.rounds(2.695, 2) self.assertEqual(result, 2.70) result = colony.rounds(2.999, 2) self.assertEqual(result, 3.0) result = colony.rounds(2.945, 2) self.assertEqual(result, 2.95) result = colony.rounds(2.9444, 2) self.assertEqual(result, 2.94) result = colony.rounds(2.9444444444444444444444, 2) self.assertEqual(result, 2.94) result = colony.rounds(2.9944444444444444444444, 2) self.assertEqual(result, 2.99) result = colony.rounds(2.995, 2) self.assertEqual(result, 3.0) result = colony.rounds(1171.735, 2) self.assertEqual(result, 1171.74) result = colony.rounds(99999999.995, 2) self.assertEqual(result, 100000000.0) result = colony.rounds(999999999999999999999999999.9944444444444444444444, 2) is_new and self.assertEqual(result, 999999999999999999999999999.99) result = colony.rounds(999999999999999999999999999.995, 2) is_new and self.assertEqual(result, 1000000000000000000000000000.0) result = colony.rounds(770.155, 2) self.assertEqual(result, 770.16)
def test_rounds(self): is_new = colony.round_is_new() result = colony.rounds(2.675, 2) self.assertEqual(result, 2.68) result = colony.rounds(2.685, 2) self.assertEqual(result, 2.69) result = colony.rounds(2.68, 2) self.assertEqual(result, 2.68) result = colony.rounds(2.683, 2) self.assertEqual(result, 2.68) result = colony.rounds(2.689, 2) self.assertEqual(result, 2.69) result = colony.rounds(2.695, 2) self.assertEqual(result, 2.70) result = colony.rounds(2.999, 2) self.assertEqual(result, 3.0) result = colony.rounds(2.945, 2) self.assertEqual(result, 2.95) result = colony.rounds(2.9444, 2) self.assertEqual(result, 2.94) result = colony.rounds(2.9444444444444444444444, 2) self.assertEqual(result, 2.94) result = colony.rounds(2.9944444444444444444444, 2) self.assertEqual(result, 2.99) result = colony.rounds(2.995, 2) self.assertEqual(result, 3.0) result = colony.rounds(1171.735, 2) self.assertEqual(result, 1171.74) result = colony.rounds(99999999.995, 2) self.assertEqual(result, 100000000.0) result = colony.rounds( 999999999999999999999999999.9944444444444444444444, 2) is_new and self.assertEqual(result, 999999999999999999999999999.99) result = colony.rounds(999999999999999999999999999.995, 2) is_new and self.assertEqual(result, 1000000000000000000000000000.0) result = colony.rounds(770.155, 2) self.assertEqual(result, 770.16)