示例#1
0
def exercise_hybrid_36():
    hybrid_36.exercise(hy36enc=pdb.hy36encode, hy36dec=pdb.hy36decode)
    for width, s in [(3, "AAA"), (6, "zzzzzz")]:
        try:
            pdb.hy36encode(width=width, value=0)
        except RuntimeError as e:
            assert str(e) == "unsupported width."
        else:
            raise Exception_expected
        try:
            pdb.hy36decode(width=width, s=s)
        except RuntimeError as e:
            assert str(e) == "unsupported width."
        else:
            raise Exception_expected
    ups = user_plus_sys_time()
    n_ok = pdb.hy36recode_width_4_all()
    ups = ups.elapsed()
    print("time hy36recode_width_4_all: %.2f s" \
      " (%.3f micro s per encode-decode cycle)" % (ups, 1.e6*ups/max(1,n_ok)))
    assert n_ok == 999 + 10000 + 2 * 26 * 36**3
    #
    assert pdb.resseq_decode(s=1234) == 1234
    assert pdb.resseq_decode(s="A123") == 11371
    assert pdb.resseq_decode(s="1") == 1
    pdb.resseq_encode(value=1) == "   1"
    pdb.resseq_encode(value=11371) == "A123"
    pdb.resseq_encode(value=1234) == "1234"
    #
    try:
        pdb.resseq_decode(s="18A")
    except ValueError as e:
        assert str(e) == 'invalid residue sequence number: " 18A"'
    else:
        raise Exception_expected
示例#2
0
        else:
            raise Exception_expected
        try:
            pdb.hy36decode(width=width, s=s)
        except RuntimeError, e:
            assert str(e) == "unsupported width."
        else:
            raise Exception_expected
    ups = user_plus_sys_time()
    n_ok = pdb.hy36recode_width_4_all()
    ups = ups.elapsed()
    print "time hy36recode_width_4_all: %.2f s" \
      " (%.3f micro s per encode-decode cycle)" % (ups, 1.e6*ups/max(1,n_ok))
    assert n_ok == 999 + 10000 + 2 * 26 * 36**3
    #
    assert pdb.resseq_decode(s=1234) == 1234
    assert pdb.resseq_decode(s="A123") == 11371
    assert pdb.resseq_decode(s="1") == 1
    pdb.resseq_encode(value=1) == "   1"
    pdb.resseq_encode(value=11371) == "A123"
    pdb.resseq_encode(value=1234) == "1234"
    #
    try:
        pdb.resseq_decode(s="18A")
    except ValueError, e:
        assert str(e) == 'invalid residue sequence number: " 18A"'
    else:
        raise Exception_expected


def exercise_base_256_ordinal():
示例#3
0
    try: pdb.hy36encode(width=width, value=0)
    except RuntimeError, e:
      assert str(e) == "unsupported width."
    else: raise Exception_expected
    try: pdb.hy36decode(width=width, s=s)
    except RuntimeError, e:
      assert str(e) == "unsupported width."
    else: raise Exception_expected
  ups = user_plus_sys_time()
  n_ok = pdb.hy36recode_width_4_all()
  ups = ups.elapsed()
  print "time hy36recode_width_4_all: %.2f s" \
    " (%.3f micro s per encode-decode cycle)" % (ups, 1.e6*ups/max(1,n_ok))
  assert n_ok == 999+10000+2*26*36**3
  #
  assert pdb.resseq_decode(s=1234) == 1234
  assert pdb.resseq_decode(s="A123") == 11371
  assert pdb.resseq_decode(s="1") == 1
  pdb.resseq_encode(value=1) == "   1"
  pdb.resseq_encode(value=11371) == "A123"
  pdb.resseq_encode(value=1234) == "1234"
  #
  try: pdb.resseq_decode(s="18A")
  except ValueError, e:
    assert str(e) == 'invalid residue sequence number: " 18A"'
  else: raise Exception_expected

def exercise_base_256_ordinal():
  o = pdb.utils_base_256_ordinal
  assert o(None) == 48
  assert o("") == 48