11cb0ef41Sopenharmony_ci#!/usr/bin/env python3 21cb0ef41Sopenharmony_ci# Copyright 2019 the V8 project authors. All rights reserved. 31cb0ef41Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be 41cb0ef41Sopenharmony_ci# found in the LICENSE file. 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciimport os 71cb0ef41Sopenharmony_ciimport sys 81cb0ef41Sopenharmony_ciimport tempfile 91cb0ef41Sopenharmony_ciimport unittest 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci# Needed because the test runner contains relative imports. 121cb0ef41Sopenharmony_ciTOOLS_PATH = os.path.dirname( 131cb0ef41Sopenharmony_ci os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 141cb0ef41Sopenharmony_cisys.path.append(TOOLS_PATH) 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cifrom testrunner.testproc.shard import radix_hash 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciclass TestRadixHashing(unittest.TestCase): 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci def test_hash_character_by_radix(self): 221cb0ef41Sopenharmony_ci self.assertEqual(97, radix_hash(capacity=2**32, key="a")) 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci def test_hash_character_by_radix_with_capacity(self): 251cb0ef41Sopenharmony_ci self.assertEqual(6, radix_hash(capacity=7, key="a")) 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci def test_hash_string(self): 281cb0ef41Sopenharmony_ci self.assertEqual(6, radix_hash(capacity=7, key="ab")) 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci def test_hash_test_id(self): 311cb0ef41Sopenharmony_ci self.assertEqual( 321cb0ef41Sopenharmony_ci 5, 331cb0ef41Sopenharmony_ci radix_hash( 341cb0ef41Sopenharmony_ci capacity=7, key="test262/Map/class-private-method-Variant-0-1")) 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci def test_hash_boundaries(self): 371cb0ef41Sopenharmony_ci total_variants = 5 381cb0ef41Sopenharmony_ci cases = [] 391cb0ef41Sopenharmony_ci for case in [ 401cb0ef41Sopenharmony_ci "test262/Map/class-private-method", 411cb0ef41Sopenharmony_ci "test262/Map/class-public-method", 421cb0ef41Sopenharmony_ci "test262/Map/object-retrieval", 431cb0ef41Sopenharmony_ci "test262/Map/object-deletion", 441cb0ef41Sopenharmony_ci "test262/Map/object-creation", 451cb0ef41Sopenharmony_ci "test262/Map/garbage-collection", 461cb0ef41Sopenharmony_ci ]: 471cb0ef41Sopenharmony_ci for variant_index in range(total_variants): 481cb0ef41Sopenharmony_ci cases.append("%s-Variant-%d" % (case, variant_index)) 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci for case in cases: 511cb0ef41Sopenharmony_ci self.assertTrue(0 <= radix_hash(capacity=7, key=case) < 7) 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ciif __name__ == '__main__': 551cb0ef41Sopenharmony_ci unittest.main() 56