Ejemplo n.º 1
0
 def test_ints_8(self):
     self.assertEqual(print_field(1), '       1', 'a')
     self.assertEqual(print_field(12345678), '12345678', 'b')
     self.assertRaises(RuntimeError, print_field, 123456789)
     self.assertEqual(print_field('12345678'), '12345678', 'c')
     self.assertEqual(print_field('1       '), '1       ',
                      '|%s|' %(print_field('1       ')))
Ejemplo n.º 2
0
def assert_fields(card1, card2):
    try:
        fields1 = wipe_empty_fields(card1.repr_fields())
        fields2 = wipe_empty_fields(card2.repr_fields())
    except:
        print("card1 = \n%s" % (card1))
        print("card2 = \n%s" % (card2))
        raise

    if len(fields1) != len(fields2):
        msg = ('len(fields1)=%s len(fields2)=%s\n%r\n%r\n%s\n%s'
               % (len(fields1), len(fields2), fields1, fields2,
                  print_card_8(fields1), print_card_8(fields2)))
        raise RuntimeError(msg)

    for (i, field1, field2) in zip(count(), fields1, fields2):
        value1a = print_field(field1)
        value2a = print_field(field2)
        if value1a != value2a:
            value1 = print_field(interpret_value(value1a))
            value2 = print_field(interpret_value(value2a))

            if value1 != value2:
                msg = 'value1 != value2\n'
                msg += ('cardName=%s ID=%s i=%s field1=%r field2=%r value1=%r '
                        'value2=%r\n%r\n%r' % (fields1[0], fields1[1], i,
                                               field1, field2, value1, value2,
                                               fields1, fields2))
                raise RuntimeError(msg)
Ejemplo n.º 3
0
def compare(valueIn):
    field = print_field(valueIn)

    val = interpret_value(field)
    if val != 0:
        p = (val - valueIn) / val
        if p > 0.01:
            raise ValueError('val=%s valueIn=%s' % (val, valueIn))
Ejemplo n.º 4
0
    def test_ints_16(self):
        self.assertEqual(print_field_16(1), '               1', 'a')
        self.assertEqual(print_field_16(12345678), '        12345678', 'b')
        self.assertEqual(print_field_16(1234567890123456), '1234567890123456', 'c')
        self.assertRaises(RuntimeError, print_field_16, 12345678901234567)

        #msg = print_field_16('12345678        ')
        #msg = '|%s| len(msg)=%s' %(msg, len(msg))
        #self.assertEqual(print_field_16('12345678'), '12345678        ',msg)
        self.assertEqual(print_field_16('1               '), '1               ',
                          '|%s|' % (print_field('1       ')))
Ejemplo n.º 5
0
 def test_strings_8(self):
     self.assertEqual(print_field(None), '        ',
                      print_field(None))
     self.assertEqual(print_field('asdf'), '    asdf',
                      print_field('asdf'))
     self.assertEqual(print_field('  asdf  '), '  asdf  ',
                      print_field('  asdf  '))
     self.assertRaises(RuntimeError, print_field, '  asdf   ')
Ejemplo n.º 6
0
 def test_field_vals_8(self):
     self.assertEqual(print_field(1e20), '   1.+20',
                      print_field(1e20))
     self.assertEqual(print_field(-.723476), '-.723476',
                      print_field(-.723476))
     self.assertEqual(print_field(125000.), ' 125000.',
                      print_field(125000.))
     self.assertEqual(print_field(12500000.), '  1.25+7',
                      print_field(12500000.))
     self.assertEqual(print_field(47.77267), '47.77267',
                      print_field(47.77267))
     self.assertEqual(print_field(.001), '    .001',
                      print_field(.001))
     self.assertEqual(print_field(.0000001), '.0000001',
                      print_field(.0000001))
     self.assertEqual(print_field(-5.007e-3), '-5.007-3',
                      print_field(-5.007e-3))
     self.assertEqual(print_field(-0.0748662), '-.074866',
                      print_field(-0.0748662))
Ejemplo n.º 7
0
    def test_floats_negative_8(self):
        self.assertEqual(print_field(-1.2), '    -1.2',
                         print_field(-1.2))
        self.assertEqual(print_field(-1.23456789), '-1.23457',
                         print_field(-1.23456789))
        self.assertEqual(print_field(-12.234568), '-12.2346',
                         print_field(-12.234568))
        self.assertEqual(print_field(-123.23457), '-123.235',
                         print_field(-123.23457))
        self.assertEqual(print_field(-1234.23468), '-1234.23',
                         print_field(-1234.23468))
        self.assertEqual(print_field(-12345.238), '-12345.2',
                         print_field(-12345.238))
        self.assertEqual(print_field(-123456.28), '-123456.',
                         print_field(-123456.28))
        self.assertEqual(print_field(-1234567.25), '-1.235+6', # is this right?
                         print_field(-1234567.25))
        self.assertEqual(print_field(-12345678.), '-1.235+7', # is this right?
                         '|%s|' % print_field(-12345678.))
        self.assertEqual(print_field(-123456789.), '-1.235+8', # is this right?
                         '|%s|' % print_field(-123456789.))

        self.assertEqual(print_field(-0.1), '     -.1',
                         'A|%s|' % print_field(-0.1))
        self.assertEqual(print_field(-0.0001), '  -.0001',
                         'B|%s|' % print_field(-0.0001))
        self.assertEqual(print_field(-0.00001), ' -.00001',
                         'C|%s|' % print_field(-0.00001))
        self.assertEqual(print_field(-0.000001), '   -1.-6',
                         'D|%s|' % print_field(-0.000001))
        self.assertEqual(print_field(-0.0000001), '   -1.-7',
                         'E|%s|' % print_field(-0.0000001))
        self.assertEqual(print_field(-0.00000012), '  -1.2-7',
                         'F|%s|' % print_field(-0.00000012))
        self.assertEqual(print_field(-0.000748519), '-7.485-4',
                         'G|%s|' % print_field(-0.000748519))
        self.assertEqual(print_field(-0.12345678), '-.123457',
                         'H|%s|' % print_field(-0.12345678))
        self.assertEqual(print_field(-0.00012349), '-1.235-4',
                         'I|%s|' % print_field(-0.00012349))
        self.assertEqual(print_field(-0.000012349), '-1.235-5',
                         'J|%s|' % print_field(-0.000012349))
        self.assertEqual(print_field(-1e-5), ' -.00001',
                         'K|%s|' % print_field(-1e-5))
        self.assertEqual(print_field(-1e-6), '   -1.-6',
                         'L|%s|' % print_field(-1e-6))
        self.assertEqual(print_field(-1e-7), '   -1.-7',
                         'M|%s|' % print_field(-1e-7))
        self.assertEqual(print_field(-1e-20), '  -1.-20',
                         'N|%s|' % print_field(-1e-20))
Ejemplo n.º 8
0
    def test_floats_positive_8(self):
        # ideal
        #self.assertEqual(print_float_8(-.003607), '-.003607',
        #                 print_float_8(-.003607))

        # actual
        self.assertEqual(print_float_8(-.003607), '-3.607-3',
                         print_float_8(-.003607))

        # good
        self.assertEqual(print_float_8(1.2), '     1.2',
                         print_float_8(1.2))
        self.assertEqual(print_float_8(0.5), '      .5',
                         print_float_8(0.5))
        self.assertEqual(print_float_8(-0.5), '     -.5',
                         print_float_8(-0.5))

        self.assertEqual(print_field(1.2), '     1.2', 'a')
        self.assertEqual(print_field(1.23456789), '1.234568', 'b')
        self.assertEqual(print_field(12.234568), '12.23457', 'c')
        self.assertEqual(print_field(123.23457), '123.2346', 'd')
        self.assertEqual(print_field(1234.23468), '1234.235', 'e')
        self.assertEqual(print_field(12345.238), '12345.24', 'f')
        self.assertEqual(print_field(123456.28), '123456.3', 'g')
        self.assertEqual(print_field(1234567.25), '1234567.',
                         print_field(1234567.25))  # 1.2346+6
        self.assertEqual(print_field(12345678.), '1.2346+7',
                         '%r' % print_field(12345678.))
        self.assertEqual(print_field(
            123456789.), '1.2346+8', '%r' % print_field(12345678.))

        self.assertEqual(print_field(0.1), '      .1',
                         'A|%s|' % print_field(0.1))
        self.assertEqual(print_field(0.0001), '   .0001',
                         'B|%s|' % print_field(0.0001))
        self.assertEqual(print_field(0.00001), '  .00001',
                         'C|%s|' % print_field(0.00001))
        self.assertEqual(print_field(0.000001), ' .000001',
                         'D|%s|' % print_field(0.000001))
        self.assertEqual(print_field(0.0000001), '.0000001',
                         'E|%s|' % print_field(0.0000001))
        self.assertEqual(print_field(0.00000012), '   1.2-7',
                         'F|%s|' % print_field(0.00000012))
        self.assertEqual(print_field(0.000748519), '7.4852-4',
                         'G|%s|' % print_field(0.000748519))
        self.assertEqual(print_field(0.12345678), '.1234568',
                         'H|%s|' % print_field(0.12345678))
        self.assertEqual(print_field(0.00012349), '1.2349-4',
                         'I|%s|' % print_field(0.00012349))
        self.assertEqual(print_field(0.000012349), '1.2349-5',
                         'J|%s|' % print_field(0.000012349))
        self.assertEqual(print_field(5e-08), '    5.-8',
                         'K|%s|' % print_field(5e-08))

        self.assertEqual(print_field(1e-20), '   1.-20',
                         'L|%s|' % print_field(1e-20))

        self.assertEqual(print_field(0.0), '      0.',
                         print_field(0.0))
        self.assertEqual(print_field(1.0), '      1.',
                         print_field(1.0))