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

Side by Side 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, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
2 #
3 # Use of this source code is governed by a BSD-style license
4 # that can be found in the LICENSE file in the root of the source
5 # tree. An additional intellectual property rights grant can be found
6 # in the file PATENTS. All contributing project authors may
7 # be found in the AUTHORS file in the root of the source tree.
8
9 """Unit test for `misc.unwrap`. Run with
10
11 python -m unittest analyzer_unittest
12 or
13 python3 -m unittest analyzer_unittest
14
15 """
16
17 from __future__ import division
18 import random
19 import unittest
20 import misc
21
22
23 class TestMisc(unittest.TestCase):
24
25 def testUnwrap(self):
26 data = [0, 1, 2, 0, -1, -2, -3, -4]
27 unwrapped_3 = misc.unwrap(data, 3)
28 unwrapped_4 = misc.unwrap(data, 4)
29
30 # Data should not change after unwrap.
31 self.assertEqual([0, 1, 2, 0, -1, -2, -3, -4], data)
32
33 self.assertEqual([0, 1, 2, 3, 2, 1, 0, -1], unwrapped_3)
34 self.assertEqual([0, 1, 2, 0, -1, -2, -3, -4], unwrapped_4)
35
36 # Test against the definition of unwrap:
37 random_data = [random.randint(0, 9) for _ in range(100)]
38 random_data_copy = random_data[:]
39 for mod in range(1, 100):
40 random_data_unwrapped_mod = misc.unwrap(random_data, mod)
41
42 # Check that only multiples of mod are added:
43 for (old_a, a) in zip(random_data, random_data_unwrapped_mod):
44 self.assertEqual((old_a - a) % mod, 0)
45
46 # Check unwrap wtr the inquality definition:
47 for (a, b) in zip(random_data_unwrapped_mod,
48 random_data_unwrapped_mod[1:]):
49 self.assertTrue(-mod / 2 <= b - a < mod / 2)
50
51 # Check that data is not modified:
52 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.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698