'Test the format_number converter utility'

def test_format_number(self):

    def equal(value, max_d, places, result):
        self.assertEqual(format_number(Decimal(value), max_d, places), result)
    equal(u'0', 12, 3, u'0.000')
    equal(u'0', 12, 8, u'0.00000000')
    equal(u'1', 12, 9, u'1.000000000')
    equal(u'0.00000000', 12, 8, u'0.00000000')
    equal(u'0.000000004', 12, 8, u'0.00000000')
    equal(u'0.000000008', 12, 8, u'0.00000001')
    equal(u'0.000000000000000000999', 10, 8, u'0.00000000')
    equal(u'0.1234567890', 12, 10, u'0.1234567890')
    equal(u'0.1234567890', 12, 9, u'0.123456789')
    equal(u'0.1234567890', 12, 8, u'0.12345679')
    equal(u'0.1234567890', 12, 5, u'0.12346')
    equal(u'0.1234567890', 12, 3, u'0.123')
    equal(u'0.1234567890', 12, 1, u'0.1')
    equal(u'0.1234567890', 12, 0, u'0')
