@@ -38,16 +38,24 @@ def compare(self, x, y, name):
3838 else :
3939 sys .stderr .write ("{0:50s} | {1}\n " .format (leftline , rightline ))
4040 self .assertEqual (Factory .fromJson (x ), Factory .fromJson (y ))
41-
41+
4242 def runTest (self ):
4343 testdata = json .load (open ("../histogrammar-multilang/test-data.json" ))
4444 for x in testdata :
4545 for k , v in x .items ():
4646 if k != "strings" and v in ("nan" , "inf" , "-inf" ):
4747 x [k ] = float (v )
48-
48+
4949 testresults = json .load (open ("../histogrammar-multilang/test-results.json" ))
5050
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+
5159 for testresult in testresults :
5260 sys .stderr .write (testresult ["expr" ] + "\n " )
5361
@@ -57,15 +65,48 @@ def runTest(self):
5765
5866 h1 = eval (testresult ["expr" ])
5967 h2 = eval (testresult ["expr" ])
68+
6069 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()" )
6172
6273 for x in testdata :
6374 h1 .fill (x )
6475 h2 .fill (x )
6576 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" )
6680
6781 self .compare ((h1 + h2 ).toJson (), two , "NAMED TWO VIA PLUS" )
6882
6983 for x in testdata :
7084 h1 .fill (x )
7185 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