File: python_richcompare_runme.py

package info (click to toggle)
renderdoc 1.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 79,584 kB
  • sloc: cpp: 491,671; ansic: 285,823; python: 12,617; java: 11,345; cs: 7,181; makefile: 6,703; yacc: 5,682; ruby: 4,648; perl: 3,461; php: 2,119; sh: 2,068; lisp: 1,835; tcl: 1,068; ml: 747; xml: 137
file content (106 lines) | stat: -rw-r--r-- 2,983 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import python_richcompare

base1 = python_richcompare.BaseClass(1)
base2 = python_richcompare.BaseClass(2)
base3 = python_richcompare.BaseClass(3)
a1 = python_richcompare.SubClassA(1)
a2 = python_richcompare.SubClassA(2)
a3 = python_richcompare.SubClassA(3)
b1 = python_richcompare.SubClassB(1)
b2 = python_richcompare.SubClassB(2)
b3 = python_richcompare.SubClassB(3)

# Check == and != within a single type
#-------------------------------------------------------------------------

if not (base1 == base1):
    raise RuntimeError("Object not == to itself")

if not (base1 == python_richcompare.BaseClass(1)):
    raise RuntimeError("Object not == to an equivalent object")

if (base1 == base2):
    raise RuntimeError(
        "Comparing non-equivalent objects of the same type, == returned True")

if (base1 != base1):
    raise RuntimeError("Object is != itself")

if (base1 != python_richcompare.BaseClass(1)):
    raise RuntimeError("Object is != an equivalent object")

if not (base1 != base2):
    raise RuntimeError(
        "Comparing non-equivalent objects of the same type, != returned False")


# Check redefined operator== in SubClassA
#-------------------------------------------------------------------------

if (a2 == base2):
    raise RuntimeError("Redefined operator== in SubClassA failed")

if (a2 == b2):
    raise RuntimeError("Redefined operator== in SubClassA failed")

if not (a1 == a2):
    raise RuntimeError("Redefined operator== in SubClassA failed")

# Check up-casting of subclasses
#-------------------------------------------------------------------------

if (base2 != a2):
    raise RuntimeError(
        "Comparing equivalent base and subclass instances, != returned True")

if (a2 == base2):
    raise RuntimeError(
        "Comparing non-equivalent base and subclass instances, == returned True")

if (a1 == b1):
    raise RuntimeError(
        "Comparing equivalent instances of different subclasses, == returned True")

if (b1 == a1):
    raise RuntimeError(
        "Comparing equivalent instances of different subclasses, == returned True")

# Check inequalities
#-------------------------------------------------------------------------

if (a2 > b2):
    raise RuntimeError("operator> failed")

if (a2 < b2):
    raise RuntimeError("operator< failed")

if not (a2 >= b2):
    raise RuntimeError("operator>= failed")

if not (a2 <= b2):
    raise RuntimeError("operator<= failed")

# Check inequalities used for ordering
#-------------------------------------------------------------------------

x = sorted([a2, a3, a1])

if not (x[0] is a1):
    raise RuntimeError("Ordering failed")

if not (x[1] is a2):
    raise RuntimeError("Ordering failed")

if not (x[2] is a3):
    raise RuntimeError("Ordering failed")

x = sorted([base2, a3, b1])

if not (x[0] is b1):
    raise RuntimeError("Ordering failed")

if not (x[1] is base2):
    raise RuntimeError("Ordering failed")

if not (x[2] is a3):
    raise RuntimeError("Ordering failed")