Пример #1
0
def assert_fields(card1, card2):
    return
    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(fields1), print_card(fields2)))
        raise RuntimeError(msg)

    for (i, field1, field2) in zip(count(), fields1, fields2):
        value1a = print_field_8(field1)
        value2a = print_field_8(field2)
        if value1a != value2a:
            value1 = print_field_8(interpret_value(value1a))
            value2 = print_field_8(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)
Пример #2
0
 def test_ints_8(self):
     self.assertEqual(print_field_8(1), '       1', 'a')
     self.assertEqual(print_field_8(12345678), '12345678', 'b')
     self.assertRaises(RuntimeError, print_field_8, 123456789)
     self.assertEqual(print_field_8('12345678'), '12345678', 'c')
     self.assertEqual(print_field_8('1       '), '1       ',
                      '|%s|' % (print_field_8('1       ')))
 def test_ints_8(self):
     self.assertEqual(print_field_8(1), '       1', 'a')
     self.assertEqual(print_field_8(12345678), '12345678', 'b')
     self.assertRaises(RuntimeError, print_field_8, 123456789)
     self.assertEqual(print_field_8('12345678'), '12345678', 'c')
     self.assertEqual(print_field_8('1       '), '1       ',
                      '|%s|' %(print_field_8('1       ')))
Пример #4
0
def assert_fields(card1, card2):
    return
    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(fields1), print_card(fields2)))
        raise RuntimeError(msg)

    for (i, field1, field2) in zip(count(), fields1, fields2):
        value1a = print_field_8(field1)
        value2a = print_field_8(field2)
        if value1a != value2a:
            value1 = print_field_8(interpret_value(value1a))
            value2 = print_field_8(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)
Пример #5
0
def compare(value_in):
    field = print_field_8(value_in)
    val = interpret_value(field)
    if val != 0:
        p = (val - value_in) / val
        if p > 0.01:  # pragma: no cover
            raise ValueError('val=%s value_in=%s' % (val, value_in))
def compare(value_in):
    field = print_field_8(value_in)

    val = interpret_value(field)
    if val != 0:
        p = (val - value_in) / val
        if p > 0.01:
            raise ValueError('val=%s value_in=%s' % (val, value_in))
Пример #7
0
 def write_card(self, size: int=8, is_double: bool=False) -> str:
     nodes = self.node_ids
     data = [self.eid, self.Pid()] + nodes[:6]
     theta = set_blank_if_default(self.theta, 0.0)
     row2 = ['        ' if node is None else '%8i' % node for node in nodes[6:]
              ] + [print_field_8(theta)]
     msg = ('CQUADX8 %8i%8i%8i%8i%8i%8i%8s%8s\n'
            '        %8s%8s%s' % tuple(data + row2))
     return self.comment + msg.rstrip() + '\n'
Пример #8
0
 def write_card(self, size=8, is_double=False):
     nodes = self.node_ids
     data = [self.eid, self.Pid()] + nodes[:6]
     theta = set_blank_if_default(self.theta, 0.0)
     row2 = ['        ' if node is None else '%8i' % node for node in nodes[6:]
              ] + [print_field_8(theta)]
     msg = ('CQUADX8 %8i%8i%8i%8i%8i%8i%8s%8s\n'
            '        %8s%8s%s' % tuple(data + row2))
     return self.comment + msg.rstrip() + '\n'
Пример #9
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_8('1       ')))
Пример #10
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)

    msg_end = ''
    max_int = 99999999
    for (i, field1, field2) in zip(count(), fields1, fields2):
        if isinstance(field1, int) and field1 > max_int:
            value1a = print_field_16(field1)
            value2a = print_field_16(field2)
        else:
            value1a = print_field_8(field1)
            value2a = print_field_8(field2)
        msg_end += '%-2s: %-8s %-8s\n' % (i, field1, field2)
        if value1a != value2a:
            if isinstance(field1, int) and field1 > max_int:
                value1 = print_field_16(interpret_value(value1a))
                value2 = print_field_16(interpret_value(value2a))
            else:
                value1 = print_field_8(interpret_value(value1a))
                value2 = print_field_8(interpret_value(value2a))

            if value1 != value2:
                msg = 'value1 != value2\n'
                msg += (
                    'card_name=%s ID=%s i=%s field1=%r field2=%r value1=%r '
                    'value2=%r\n%r\n%r\n' %
                    (fields1[0], fields1[1], i, field1, field2, value1, value2,
                     fields1, fields2))
                raise RuntimeError(msg + msg_end)
Пример #11
0
 def test_strings_8(self):
     self.assertEqual(print_field_8(None), '        ', print_field_8(None))
     self.assertEqual(print_field_8('asdf'), '    asdf',
                      print_field_8('asdf'))
     self.assertEqual(print_field_8('  asdf  '), '  asdf  ',
                      print_field_8('  asdf  '))
     self.assertRaises(RuntimeError, print_field_8, '  asdf   ')
Пример #12
0
def assert_fields(card1, card2):
    try:
        fields1 = wipe_empty_fields_typed(card1.repr_fields())
        fields2 = wipe_empty_fields_typed(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)

    msg_end = ''
    max_int = 99999999
    for (i, field1, field2) in zip(count(), fields1, fields2):
        if isinstance(field1, int) and field1 > max_int:
            value1a = print_field_16(field1)
            value2a = print_field_16(field2)
        else:
            value1a = print_field_8(field1)
            value2a = print_field_8(field2)
        msg_end += '%-2s: %-8s %-8s\n' % (i, field1, field2)
        if value1a != value2a:
            if isinstance(field1, int) and field1 > max_int:
                value1 = print_field_16(interpret_value(value1a))
                value2 = print_field_16(interpret_value(value2a))
            else:
                value1 = print_field_8(interpret_value(value1a))
                value2 = print_field_8(interpret_value(value2a))

            if value1 != value2:
                msg = 'value1 != value2\n'
                msg += ('card_name=%s ID=%s i=%s field1=%r field2=%r value1=%r '
                        'value2=%r\n%r\n%r\n' % (fields1[0], fields1[1], i,
                                                 field1, field2, value1, value2,
                                                 fields1, fields2))
                raise RuntimeError(msg + msg_end)
 def test_strings_8(self):
     self.assertEqual(print_field_8(None), '        ',
                      print_field_8(None))
     self.assertEqual(print_field_8('asdf'), '    asdf',
                      print_field_8('asdf'))
     self.assertEqual(print_field_8('  asdf  '), '  asdf  ',
                      print_field_8('  asdf  '))
     self.assertRaises(RuntimeError, print_field_8, '  asdf   ')
Пример #14
0
def write_field(value, fieldspan=1):
    """Convert `value` to field string
    """
    width = fieldspan * 8
    if isinstance(value, str):
        return value[:width].strip()
    elif width == 8:
        return print_field_8(value).strip()
    elif width == 16:
        return print_field_16(value).strip()
    else:
        raise ValueError("non-character field entries "
                         "cannot span more than 2 fields, "
                         "but fieldspan is {}".format(fieldspan))
    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_8(1.2), '     1.2', 'a')
        self.assertEqual(print_field_8(1.23456789), '1.234568', 'b')
        self.assertEqual(print_field_8(12.234568), '12.23457', 'c')
        self.assertEqual(print_field_8(123.23457), '123.2346', 'd')
        self.assertEqual(print_field_8(1234.23468), '1234.235', 'e')
        self.assertEqual(print_field_8(12345.238), '12345.24', 'f')
        self.assertEqual(print_field_8(123456.28), '123456.3', 'g')
        self.assertEqual(print_field_8(1234567.25), '1234567.',
                         print_field_8(1234567.25))  # 1.2346+6
        self.assertEqual(print_field_8(12345678.), '1.2346+7',
                         '%r' % print_field_8(12345678.))
        self.assertEqual(print_field_8(
            123456789.), '1.2346+8', '%r' % print_field_8(12345678.))

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

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

        self.assertEqual(print_field_8(0.0), '      0.',
                         print_field_8(0.0))
        self.assertEqual(print_field_8(1.0), '      1.',
                         print_field_8(1.0))
    def test_floats_negative_8(self):
        self.assertEqual(print_field_8(-1.2), '    -1.2',
                         print_field_8(-1.2))
        self.assertEqual(print_field_8(-1.23456789), '-1.23457',
                         print_field_8(-1.23456789))
        self.assertEqual(print_field_8(-12.234568), '-12.2346',
                         print_field_8(-12.234568))
        self.assertEqual(print_field_8(-123.23457), '-123.235',
                         print_field_8(-123.23457))
        self.assertEqual(print_field_8(-1234.23468), '-1234.23',
                         print_field_8(-1234.23468))
        self.assertEqual(print_field_8(-12345.238), '-12345.2',
                         print_field_8(-12345.238))
        self.assertEqual(print_field_8(-123456.28), '-123456.',
                         print_field_8(-123456.28))
        self.assertEqual(print_field_8(-1234567.25), '-1.235+6', # is this right?
                         print_field_8(-1234567.25))
        self.assertEqual(print_field_8(-12345678.), '-1.235+7', # is this right?
                         '|%s|' % print_field_8(-12345678.))
        self.assertEqual(print_field_8(-123456789.), '-1.235+8', # is this right?
                         '|%s|' % print_field_8(-123456789.))

        self.assertEqual(print_field_8(-0.1), '     -.1',
                         'A|%s|' % print_field_8(-0.1))
        self.assertEqual(print_field_8(-0.0001), '  -.0001',
                         'B|%s|' % print_field_8(-0.0001))
        self.assertEqual(print_field_8(-0.00001), ' -.00001',
                         'C|%s|' % print_field_8(-0.00001))
        self.assertEqual(print_field_8(-0.000001), '   -1.-6',
                         'D|%s|' % print_field_8(-0.000001))
        self.assertEqual(print_field_8(-0.0000001), '   -1.-7',
                         'E|%s|' % print_field_8(-0.0000001))
        self.assertEqual(print_field_8(-0.00000012), '  -1.2-7',
                         'F|%s|' % print_field_8(-0.00000012))
        self.assertEqual(print_field_8(-0.000748519), '-7.485-4',
                         'G|%s|' % print_field_8(-0.000748519))
        self.assertEqual(print_field_8(-0.12345678), '-.123457',
                         'H|%s|' % print_field_8(-0.12345678))
        self.assertEqual(print_field_8(-0.00012349), '-1.235-4',
                         'I|%s|' % print_field_8(-0.00012349))
        self.assertEqual(print_field_8(-0.000012349), '-1.235-5',
                         'J|%s|' % print_field_8(-0.000012349))
        self.assertEqual(print_field_8(-1e-5), ' -.00001',
                         'K|%s|' % print_field_8(-1e-5))
        self.assertEqual(print_field_8(-1e-6), '   -1.-6',
                         'L|%s|' % print_field_8(-1e-6))
        self.assertEqual(print_field_8(-1e-7), '   -1.-7',
                         'M|%s|' % print_field_8(-1e-7))
        self.assertEqual(print_field_8(-1e-20), '  -1.-20',
                         'N|%s|' % print_field_8(-1e-20))
Пример #17
0
 def test_field_vals_8(self):
     self.assertEqual(print_field_8(1e20), '   1.+20', print_field_8(1e20))
     self.assertEqual(print_field_8(-.723476), '-.723476',
                      print_field_8(-.723476))
     self.assertEqual(print_field_8(125000.), ' 125000.',
                      print_field_8(125000.))
     self.assertEqual(print_field_8(12500000.), '  1.25+7',
                      print_field_8(12500000.))
     self.assertEqual(print_field_8(47.77267), '47.77267',
                      print_field_8(47.77267))
     self.assertEqual(print_field_8(.001), '    .001', print_field_8(.001))
     self.assertEqual(print_field_8(.0000001), '.0000001',
                      print_field_8(.0000001))
     self.assertEqual(print_field_8(-5.007e-3), '-5.007-3',
                      print_field_8(-5.007e-3))
     self.assertEqual(print_field_8(-0.0748662), '-.074866',
                      print_field_8(-0.0748662))
Пример #18
0
    def test_floats_negative_8(self):
        self.assertEqual(print_field_8(-1.2), '    -1.2', print_field_8(-1.2))
        self.assertEqual(print_field_8(-1.23456789), '-1.23457',
                         print_field_8(-1.23456789))
        self.assertEqual(print_field_8(-12.234568), '-12.2346',
                         print_field_8(-12.234568))
        self.assertEqual(print_field_8(-123.23457), '-123.235',
                         print_field_8(-123.23457))
        self.assertEqual(print_field_8(-1234.23468), '-1234.23',
                         print_field_8(-1234.23468))
        self.assertEqual(print_field_8(-12345.238), '-12345.2',
                         print_field_8(-12345.238))
        self.assertEqual(print_field_8(-123456.28), '-123456.',
                         print_field_8(-123456.28))
        self.assertEqual(
            print_field_8(-1234567.25),
            '-1.235+6',  # is this right?
            print_field_8(-1234567.25))
        self.assertEqual(
            print_field_8(-12345678.),
            '-1.235+7',  # is this right?
            '|%s|' % print_field_8(-12345678.))
        self.assertEqual(
            print_field_8(-123456789.),
            '-1.235+8',  # is this right?
            '|%s|' % print_field_8(-123456789.))

        self.assertEqual(print_field_8(-0.1), '     -.1',
                         'A|%s|' % print_field_8(-0.1))
        self.assertEqual(print_field_8(-0.0001), '  -.0001',
                         'B|%s|' % print_field_8(-0.0001))
        self.assertEqual(print_field_8(-0.00001), ' -.00001',
                         'C|%s|' % print_field_8(-0.00001))
        self.assertEqual(print_field_8(-0.000001), '   -1.-6',
                         'D|%s|' % print_field_8(-0.000001))
        self.assertEqual(print_field_8(-0.0000001), '   -1.-7',
                         'E|%s|' % print_field_8(-0.0000001))
        self.assertEqual(print_field_8(-0.00000012), '  -1.2-7',
                         'F|%s|' % print_field_8(-0.00000012))
        self.assertEqual(print_field_8(-0.000748519), '-7.485-4',
                         'G|%s|' % print_field_8(-0.000748519))
        self.assertEqual(print_field_8(-0.12345678), '-.123457',
                         'H|%s|' % print_field_8(-0.12345678))
        self.assertEqual(print_field_8(-0.00012349), '-1.235-4',
                         'I|%s|' % print_field_8(-0.00012349))
        self.assertEqual(print_field_8(-0.000012349), '-1.235-5',
                         'J|%s|' % print_field_8(-0.000012349))
        self.assertEqual(print_field_8(-1e-5), ' -.00001',
                         'K|%s|' % print_field_8(-1e-5))
        self.assertEqual(print_field_8(-1e-6), '   -1.-6',
                         'L|%s|' % print_field_8(-1e-6))
        self.assertEqual(print_field_8(-1e-7), '   -1.-7',
                         'M|%s|' % print_field_8(-1e-7))
        self.assertEqual(print_field_8(-1e-20), '  -1.-20',
                         'N|%s|' % print_field_8(-1e-20))
Пример #19
0
 def test_field_vals_8_edge_cases(self):
     self.assertEqual(print_field_8(-999999.56), '  -10.+5',
                      print_field_8(-999999.56))
Пример #20
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_8(1.2), '     1.2', 'a')
        self.assertEqual(print_field_8(1.23456789), '1.234568', 'b')
        self.assertEqual(print_field_8(12.234568), '12.23457', 'c')
        self.assertEqual(print_field_8(123.23457), '123.2346', 'd')
        self.assertEqual(print_field_8(1234.23468), '1234.235', 'e')
        self.assertEqual(print_field_8(12345.238), '12345.24', 'f')
        self.assertEqual(print_field_8(123456.28), '123456.3', 'g')
        self.assertEqual(print_field_8(1234567.25), '1234567.',
                         print_field_8(1234567.25))  # 1.2346+6
        self.assertEqual(print_field_8(12345678.), '1.2346+7',
                         '%r' % print_field_8(12345678.))
        self.assertEqual(print_field_8(123456789.), '1.2346+8',
                         '%r' % print_field_8(12345678.))

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

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

        self.assertEqual(print_field_8(0.0), '      0.', print_field_8(0.0))
        self.assertEqual(print_field_8(1.0), '      1.', print_field_8(1.0))
 def test_field_vals_8(self):
     self.assertEqual(print_field_8(1e20), '   1.+20',
                      print_field_8(1e20))
     self.assertEqual(print_field_8(-.723476), '-.723476',
                      print_field_8(-.723476))
     self.assertEqual(print_field_8(125000.), ' 125000.',
                      print_field_8(125000.))
     self.assertEqual(print_field_8(12500000.), '  1.25+7',
                      print_field_8(12500000.))
     self.assertEqual(print_field_8(47.77267), '47.77267',
                      print_field_8(47.77267))
     self.assertEqual(print_field_8(.001), '    .001',
                      print_field_8(.001))
     self.assertEqual(print_field_8(.0000001), '.0000001',
                      print_field_8(.0000001))
     self.assertEqual(print_field_8(-5.007e-3), '-5.007-3',
                      print_field_8(-5.007e-3))
     self.assertEqual(print_field_8(-0.0748662), '-.074866',
                      print_field_8(-0.0748662))