Parcourir la source

[2781] correct inappropriate condition (not related to this ticket)

correct inappropriate condition in the internal function and add
related tests, and update the copyright years
Naoki Kambe il y a 11 ans
Parent
commit
5498431f4d
2 fichiers modifiés avec 6 ajouts et 4 suppressions
  1. 3 3
      src/bin/stats/stats.py.in
  2. 3 1
      src/bin/stats/tests/stats_test.py

+ 3 - 3
src/bin/stats/stats.py.in

@@ -1,6 +1,6 @@
 #!@PYTHON@
 
-# Copyright (C) 2010, 2011, 2012  Internet Systems Consortium.
+# Copyright (C) 2010-2013  Internet Systems Consortium.
 #
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -124,8 +124,8 @@ def _accum(a, b):
                              if len(a) <= i ]
     # If both of args are integer or float type, two
     # values are added.
-    elif (type(a) is int and type(b) is int) \
-            or (type(a) is float or type(b) is float):
+    elif (type(a) is int or type(a) is float) \
+            and (type(b) is int or type(b) is float):
         return a + b
 
     # If both of args are string type,

+ 3 - 1
src/bin/stats/tests/stats_test.py

@@ -1,4 +1,4 @@
-# Copyright (C) 2010, 2011, 2012  Internet Systems Consortium.
+# Copyright (C) 2010-2013  Internet Systems Consortium.
 #
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -132,6 +132,8 @@ class TestUtilties(unittest.TestCase):
         self.assertEqual(stats._accum("a", None), "a")
         self.assertEqual(stats._accum(1, 2), 3)
         self.assertEqual(stats._accum(0.5, 0.3), 0.8)
+        self.assertEqual(stats._accum(1, 0.3), 1.3)
+        self.assertEqual(stats._accum(0.5, 2), 2.5)
         self.assertEqual(stats._accum('aa','bb'), 'bb')
         self.assertEqual(stats._accum('1970-01-01T09:00:00Z','2012-08-09T09:33:31Z'),
                          '2012-08-09T09:33:31Z')