PageRenderTime 33ms CodeModel.GetById 27ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Python | 100 lines | 58 code | 32 blank | 10 comment | 35 complexity | bec5a33d918ff1f2c70bcfb4585a61cc MD5 | raw file
  1import python_richcompare
  2
  3base1 = python_richcompare.BaseClass(1)
  4base2 = python_richcompare.BaseClass(2)
  5base3 = python_richcompare.BaseClass(3)
  6a1 = python_richcompare.SubClassA(1)
  7a2 = python_richcompare.SubClassA(2)
  8a3 = python_richcompare.SubClassA(3)
  9b1 = python_richcompare.SubClassB(1)
 10b2 = python_richcompare.SubClassB(2)
 11b3 = python_richcompare.SubClassB(3)
 12
 13# Check == and != within a single type
 14#-------------------------------------------------------------------------------
 15
 16if not (base1 == base1) :
 17    raise RuntimeError("Object not == to itself")
 18
 19if not (base1 == python_richcompare.BaseClass(1)) :
 20    raise RuntimeError("Object not == to an equivalent object")
 21
 22if (base1 == base2) :
 23    raise RuntimeError("Comparing non-equivalent objects of the same type, == returned True")
 24
 25if (base1 != base1) :
 26    raise RuntimeError("Object is != itself")
 27
 28if (base1 != python_richcompare.BaseClass(1)) :
 29    raise RuntimeError("Object is != an equivalent object")
 30
 31if not (base1 != base2) :
 32    raise RuntimeError("Comparing non-equivalent objects of the same type, != returned False")
 33
 34
 35# Check redefined operator== in SubClassA
 36#-------------------------------------------------------------------------------
 37
 38if (a2 == base2) :
 39    raise RuntimeError("Redefined operator== in SubClassA failed")
 40
 41if (a2 == b2) :
 42    raise RuntimeError("Redefined operator== in SubClassA failed")
 43
 44if not (a1 == a2) :
 45    raise RuntimeError("Redefined operator== in SubClassA failed")
 46
 47# Check up-casting of subclasses
 48#-------------------------------------------------------------------------------
 49
 50if (base2 != a2) :
 51    raise RuntimeError("Comparing equivalent base and subclass instances, != returned True")
 52
 53if (a2 == base2) :
 54    raise RuntimeError("Comparing non-equivalent base and subclass instances, == returned True")
 55
 56if (a1 == b1) :
 57    raise RuntimeError("Comparing equivalent instances of different subclasses, == returned True")
 58
 59if (b1 == a1) :
 60    raise RuntimeError("Comparing equivalent instances of different subclasses, == returned True")
 61    
 62# Check inequalities
 63#-------------------------------------------------------------------------------
 64
 65if (a2 > b2) :
 66    raise RuntimeError("operator> failed")
 67
 68if (a2 < b2) :
 69    raise RuntimeError("operator< failed")
 70
 71if not (a2 >= b2) :
 72    raise RuntimeError("operator>= failed")
 73
 74if not (a2 <= b2) :
 75    raise RuntimeError("operator<= failed")
 76
 77# Check inequalities used for ordering
 78#-------------------------------------------------------------------------------
 79
 80x = sorted([a2, a3, a1])
 81
 82if not (x[0] is a1) :
 83    raise RuntimeError("Ordering failed")
 84
 85if not (x[1] is a2) :
 86    raise RuntimeError("Ordering failed")
 87
 88if not (x[2] is a3) :
 89    raise RuntimeError("Ordering failed")
 90
 91x = sorted([base2, a3, b1])
 92
 93if not (x[0] is b1) :
 94    raise RuntimeError("Ordering failed")
 95
 96if not (x[1] is base2) :
 97    raise RuntimeError("Ordering failed")
 98
 99if not (x[2] is a3) :
100    raise RuntimeError("Ordering failed")