/trunk/Examples/test-suite/python/virtual_poly_runme.py

# · Python · 38 lines · 21 code · 11 blank · 6 comment · 6 complexity · cf4e019df53bede8f57a4c4a1c04da38 MD5 · raw file

  1. import virtual_poly
  2. d = virtual_poly.NDouble(3.5)
  3. i = virtual_poly.NInt(2)
  4. #
  5. # the copy methods return the right polymorphic types
  6. #
  7. dc = d.copy()
  8. ic = i.copy()
  9. if d.get() != dc.get():
  10. raise RuntimeError
  11. if i.get() != ic.get():
  12. raise RuntimeError
  13. virtual_poly.incr(ic)
  14. if (i.get() + 1) != ic.get():
  15. raise RuntimeError
  16. dr = d.ref_this()
  17. if d.get() != dr.get():
  18. raise RuntimeError
  19. #
  20. # 'narrowing' also works
  21. #
  22. ddc = virtual_poly.NDouble_narrow(d.nnumber())
  23. if d.get() != ddc.get():
  24. raise RuntimeError
  25. dic = virtual_poly.NInt_narrow(i.nnumber())
  26. if i.get() != dic.get():
  27. raise RuntimeError