コード例 #1
0
    def test_boolean(self):
        """
        Runs a series of tests on the boolean based operators
        defined for the decimal data structure.
        """

        result = colony.Decimal(12.2) and 12.2
        self.assertEqual(result, 12.2)
        self.assertEqual(type(result), float)

        result = 12.2 and colony.Decimal(12.2)
        self.assertEqual(result, colony.Decimal(12.2))
        self.assertEqual(type(result), colony.Decimal)

        result = colony.Decimal(12.2) or 12
        self.assertEqual(result, colony.Decimal(12.2))
        self.assertEqual(type(result), colony.Decimal)
コード例 #2
0
    def test_coercing(self):
        """
        Runs a series of coercing tests for the decimal data
        type conversion to other types and vice-versa
        """

        result = int(colony.Decimal(12.2))
        self.assertEqual(result, 12)
        self.assertEqual(type(result), int)

        result = int(colony.Decimal(12.99))
        self.assertEqual(result, 12)
        self.assertEqual(type(result), int)

        result = float(colony.Decimal(12.99))
        self.assertEqual(result, 12.99)
        self.assertEqual(type(result), float)

        result = str(colony.Decimal(12.99))
        self.assertEqual(result, "12.99")
        self.assertEqual(type(result), str)

        result = colony.Decimal(int(12))
        self.assertEqual(result, 12.0)
        self.assertEqual(type(result), colony.Decimal)

        result = colony.Decimal(float(12.99))
        self.assertEqual(result, 12.99)
        self.assertEqual(type(result), colony.Decimal)

        result = colony.Decimal("12.99")
        self.assertEqual(result, 12.99)
        self.assertEqual(type(result), colony.Decimal)
コード例 #3
0
ファイル: round_util.py プロジェクト: tanyhuan/colony
    def test_roundt(self):
        result = colony.roundt(2.675, 2)
        self.assertEqual(type(result), float)

        result = colony.roundt(colony.Decimal(2.675), 2)
        self.assertEqual(type(result), colony.Decimal)

        result = colony.roundt(2, 2)
        self.assertEqual(type(result), int)
コード例 #4
0
    def test_basic(self):
        """
        Runs a series of basic sanity tests for the decimal
        data structure.
        """

        result = +colony.Decimal(12.2)
        self.assertEqual(result, +12.2)
        self.assertEqual(type(result), colony.Decimal)

        result = -colony.Decimal(12.2)
        self.assertEqual(result, -12.2)
        self.assertEqual(type(result), colony.Decimal)

        result = abs(colony.Decimal(-12.2))
        self.assertEqual(result, 12.2)
        self.assertEqual(type(result), colony.Decimal)

        result = round(colony.Decimal(88.151), 2)
        self.assertEqual(result, 88.15)
        self.assertEqual(type(result), colony.Decimal)
コード例 #5
0
    def test_operations(self):
        """
        Runs a series of general operations testing for the
        decimal data structure.
        """

        key = colony.Decimal(88.151) - 88.15
        self.assertEqual(type(key), colony.Decimal)

        map = dict()
        map[key] = "value"
        result = map[key]
        self.assertEqual(result, "value")
コード例 #6
0
    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)