Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Unified Diff: tools/py_event_log_analyzer/analyzer_unittest.py

Issue 1999113002: New rtc dump analyzing tool in Python (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Unit test for misc.unwrap Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/py_event_log_analyzer/analyzer_unittest.py
diff --git a/tools/py_event_log_analyzer/analyzer_unittest.py b/tools/py_event_log_analyzer/analyzer_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..5f22be46ce0505a7bbfe9831d08cfcdd48cbb0a2
--- /dev/null
+++ b/tools/py_event_log_analyzer/analyzer_unittest.py
@@ -0,0 +1,52 @@
+# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS. All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+"""Unit test for `misc.unwrap`. Run with
+
+ python -m unittest analyzer_unittest
+or
+ python3 -m unittest analyzer_unittest
+
+"""
+
+from __future__ import division
+import random
+import unittest
+import misc
+
+
+class TestMisc(unittest.TestCase):
+
+ def testUnwrap(self):
+ data = [0, 1, 2, 0, -1, -2, -3, -4]
+ unwrapped_3 = misc.unwrap(data, 3)
+ unwrapped_4 = misc.unwrap(data, 4)
+
+ # Data should not change after unwrap.
+ self.assertEqual([0, 1, 2, 0, -1, -2, -3, -4], data)
+
+ self.assertEqual([0, 1, 2, 3, 2, 1, 0, -1], unwrapped_3)
+ self.assertEqual([0, 1, 2, 0, -1, -2, -3, -4], unwrapped_4)
+
+ # Test against the definition of unwrap:
+ random_data = [random.randint(0, 9) for _ in range(100)]
+ random_data_copy = random_data[:]
+ for mod in range(1, 100):
+ random_data_unwrapped_mod = misc.unwrap(random_data, mod)
+
+ # Check that only multiples of mod are added:
+ for (old_a, a) in zip(random_data, random_data_unwrapped_mod):
+ self.assertEqual((old_a - a) % mod, 0)
+
+ # Check unwrap wtr the inquality definition:
+ for (a, b) in zip(random_data_unwrapped_mod,
+ random_data_unwrapped_mod[1:]):
+ self.assertTrue(-mod / 2 <= b - a < mod / 2)
+
+ # Check that data is not modified:
+ self.assertEqual(random_data, random_data_copy)
kwiberg-webrtc 2016/05/31 12:30:53 Excellent. But could you put the unit test in the
aleloi 2016/05/31 12:40:32 Moved in new version.

Powered by Google App Engine
This is Rietveld 408576698