@@ -38,16 +38,24 @@ def compare(self, x, y, name):
38
38
else :
39
39
sys .stderr .write ("{0:50s} | {1}\n " .format (leftline , rightline ))
40
40
self .assertEqual (Factory .fromJson (x ), Factory .fromJson (y ))
41
-
41
+
42
42
def runTest (self ):
43
43
testdata = json .load (open ("../histogrammar-multilang/test-data.json" ))
44
44
for x in testdata :
45
45
for k , v in x .items ():
46
46
if k != "strings" and v in ("nan" , "inf" , "-inf" ):
47
47
x [k ] = float (v )
48
-
48
+
49
49
testresults = json .load (open ("../histogrammar-multilang/test-results.json" ))
50
50
51
+ def stripNames (x ):
52
+ if hasattr (x , "quantity" ):
53
+ x .quantity .name = None
54
+ elif hasattr (x , "quantityName" ):
55
+ x .quantityName = None
56
+ for xi in x .children :
57
+ stripNames (xi )
58
+
51
59
for testresult in testresults :
52
60
sys .stderr .write (testresult ["expr" ] + "\n " )
53
61
@@ -57,15 +65,48 @@ def runTest(self):
57
65
58
66
h1 = eval (testresult ["expr" ])
59
67
h2 = eval (testresult ["expr" ])
68
+
60
69
self .compare (h1 .toJson (), zero , "NAMED ZERO" )
70
+ self .compare ((h1 + h1 ).toJson (), zero , "NAMED ZERO + ZERO" )
71
+ self .compare (h1 .zero ().toJson (), zero , "NAMED ZERO.zero()" )
61
72
62
73
for x in testdata :
63
74
h1 .fill (x )
64
75
h2 .fill (x )
65
76
self .compare (h1 .toJson (), one , "NAMED ONE" )
77
+ self .compare (h1 .zero ().toJson (), zero , "NAMED ONE.zero()" )
78
+ self .compare ((h1 + h1 .zero ()).toJson (), one , "NAMED ONE + ZERO" )
79
+ self .compare ((h1 .zero () + h1 ).toJson (), one , "NAMED ZERO + ONE" )
66
80
67
81
self .compare ((h1 + h2 ).toJson (), two , "NAMED TWO VIA PLUS" )
68
82
69
83
for x in testdata :
70
84
h1 .fill (x )
71
85
self .compare (h1 .toJson (), two , "NAMED TWO VIA FILL" )
86
+
87
+ zero = testresult ["zero-anonymous" ]
88
+ one = testresult ["one-anonymous" ]
89
+ two = testresult ["two-anonymous" ]
90
+
91
+ h1 = eval (testresult ["expr" ])
92
+ stripNames (h1 )
93
+ h2 = eval (testresult ["expr" ])
94
+ stripNames (h2 )
95
+
96
+ self .compare (h1 .toJson (), zero , "ANONYMOUS ZERO" )
97
+ self .compare ((h1 + h1 ).toJson (), zero , "ANONYMOUS ZERO + ZERO" )
98
+ self .compare (h1 .zero ().toJson (), zero , "ANONYMOUS ZERO.zero()" )
99
+
100
+ for x in testdata :
101
+ h1 .fill (x )
102
+ h2 .fill (x )
103
+ self .compare (h1 .toJson (), one , "ANONYMOUS ONE" )
104
+ self .compare (h1 .zero ().toJson (), zero , "ANONYMOUS ONE.zero()" )
105
+ self .compare ((h1 + h1 .zero ()).toJson (), one , "ANONYMOUS ONE + ZERO" )
106
+ self .compare ((h1 .zero () + h1 ).toJson (), one , "ANONYMOUS ZERO + ONE" )
107
+
108
+ self .compare ((h1 + h2 ).toJson (), two , "ANONYMOUS TWO VIA PLUS" )
109
+
110
+ for x in testdata :
111
+ h1 .fill (x )
112
+ self .compare (h1 .toJson (), two , "ANONYMOUS TWO VIA FILL" )
0 commit comments