diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /third_party/libwebrtc/rtc_tools/py_event_log_analyzer/misc_test.py | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/rtc_tools/py_event_log_analyzer/misc_test.py')
-rwxr-xr-x | third_party/libwebrtc/rtc_tools/py_event_log_analyzer/misc_test.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/third_party/libwebrtc/rtc_tools/py_event_log_analyzer/misc_test.py b/third_party/libwebrtc/rtc_tools/py_event_log_analyzer/misc_test.py new file mode 100755 index 0000000000..1ee17419a2 --- /dev/null +++ b/third_party/libwebrtc/rtc_tools/py_event_log_analyzer/misc_test.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# 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. +"""Run the tests with + + python misc_test.py +or + python3 misc_test.py +""" + +from __future__ import division +from __future__ import absolute_import +import random +import unittest +from six.moves import range +from six.moves import zip + +import misc + +class TestMisc(unittest.TestCase): + def testUnwrapMod3(self): + data = [0, 1, 2, 0, -1, -2, -3, -4] + unwrapped_3 = misc.Unwrap(data, 3) + self.assertEqual([0, 1, 2, 3, 2, 1, 0, -1], unwrapped_3) + + def testUnwrapMod4(self): + data = [0, 1, 2, 0, -1, -2, -3, -4] + unwrapped_4 = misc.Unwrap(data, 4) + self.assertEqual([0, 1, 2, 0, -1, -2, -3, -4], unwrapped_4) + + def testDataShouldNotChangeAfterUnwrap(self): + data = [0, 1, 2, 0, -1, -2, -3, -4] + _ = misc.Unwrap(data, 4) + + self.assertEqual([0, 1, 2, 0, -1, -2, -3, -4], data) + + def testRandomlyMultiplesOfModAdded(self): + # `unwrap` definition says only multiples of mod are added. + random_data = [random.randint(0, 9) for _ in range(100)] + + for mod in range(1, 100): + random_data_unwrapped_mod = misc.Unwrap(random_data, mod) + + for (old_a, a) in zip(random_data, random_data_unwrapped_mod): + self.assertEqual((old_a - a) % mod, 0) + + def testRandomlyAgainstInequalityDefinition(self): + # Data has to satisfy -mod/2 <= difference < mod/2 for every + # difference between consecutive values after unwrap. + random_data = [random.randint(0, 9) for _ in range(100)] + + for mod in range(1, 100): + random_data_unwrapped_mod = misc.Unwrap(random_data, mod) + + for (a, b) in zip(random_data_unwrapped_mod, + random_data_unwrapped_mod[1:]): + self.assertTrue(-mod / 2 <= b - a < mod / 2) + + def testRandomlyDataShouldNotChangeAfterUnwrap(self): + random_data = [random.randint(0, 9) for _ in range(100)] + random_data_copy = random_data[:] + for mod in range(1, 100): + _ = misc.Unwrap(random_data, mod) + + self.assertEqual(random_data, random_data_copy) + + +if __name__ == "__main__": + unittest.main() |