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

Side by Side Diff: tools/py_event_log_analyzer/misc_unittest.py

Issue 1999113002: New rtc dump analyzing tool in Python (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added copying to BUILD.gn 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 """Run the tests with
10
11 python -m unittest misc_unittest
12 or
13 python3 -m unittest misc_unittest
14 """
15
16 from __future__ import division
17 import random
18 import unittest
19
20 import misc
21
22
23 class TestMisc(unittest.TestCase):
phoglund 2016/06/03 08:11:07 We need to get these tests actually running on pre
aleloi 2016/06/09 12:00:44 I did that. The test had to be renamed to end with
24
25 def testUnwrapMod3(self):
phoglund 2016/06/03 08:11:07 Nice!
26 data = [0, 1, 2, 0, -1, -2, -3, -4]
27 unwrapped_3 = misc.unwrap(data, 3)
28 self.assertEqual([0, 1, 2, 3, 2, 1, 0, -1], unwrapped_3)
29
30 def testUnwrapMod4(self):
31 data = [0, 1, 2, 0, -1, -2, -3, -4]
32 unwrapped_4 = misc.unwrap(data, 4)
33 self.assertEqual([0, 1, 2, 0, -1, -2, -3, -4], unwrapped_4)
34
35 def testDataShouldNotChangeAfterUnwrap(self):
36 data = [0, 1, 2, 0, -1, -2, -3, -4]
37 _ = misc.unwrap(data, 4)
38
39 self.assertEqual([0, 1, 2, 0, -1, -2, -3, -4], data)
40
41 def testRandomlyMultiplesOfModAdded(self):
42 # `unwrap` definition says only multiples of mod are added.
43 random_data = [random.randint(0, 9) for _ in range(100)]
44
45 for mod in range(1, 100):
46 random_data_unwrapped_mod = misc.unwrap(random_data, mod)
47
48 for (old_a, a) in zip(random_data, random_data_unwrapped_mod):
49 self.assertEqual((old_a - a) % mod, 0)
50
51 def testRandomlyAgainstInequalityDefinition(self):
52 # Data has to satisfy -mod/2 <= difference < mod/2 for every
53 # difference between consecutive values after unwrap.
54 random_data = [random.randint(0, 9) for _ in range(100)]
55
56 for mod in range(1, 100):
57 random_data_unwrapped_mod = misc.unwrap(random_data, mod)
58
59 for (a, b) in zip(random_data_unwrapped_mod,
60 random_data_unwrapped_mod[1:]):
61 self.assertTrue(-mod / 2 <= b - a < mod / 2)
62
63 def testRandomlyDataShouldNotChangeAfterUnwrap(self):
64 random_data = [random.randint(0, 9) for _ in range(100)]
65 random_data_copy = random_data[:]
66 for mod in range(1, 100):
67 _ = misc.unwrap(random_data, mod)
68
69 self.assertEqual(random_data, random_data_copy)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698