• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright 2019 the V8 project authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import os
7import sys
8import tempfile
9import unittest
10
11# Needed because the test runner contains relative imports.
12TOOLS_PATH = os.path.dirname(
13    os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
14sys.path.append(TOOLS_PATH)
15
16from testrunner.testproc.shard import radix_hash
17
18
19class TestRadixHashing(unittest.TestCase):
20
21  def test_hash_character_by_radix(self):
22    self.assertEqual(97, radix_hash(capacity=2**32, key="a"))
23
24  def test_hash_character_by_radix_with_capacity(self):
25    self.assertEqual(6, radix_hash(capacity=7, key="a"))
26
27  def test_hash_string(self):
28    self.assertEqual(6, radix_hash(capacity=7, key="ab"))
29
30  def test_hash_test_id(self):
31    self.assertEqual(
32        5,
33        radix_hash(
34            capacity=7, key="test262/Map/class-private-method-Variant-0-1"))
35
36  def test_hash_boundaries(self):
37    total_variants = 5
38    cases = []
39    for case in [
40        "test262/Map/class-private-method",
41        "test262/Map/class-public-method",
42        "test262/Map/object-retrieval",
43        "test262/Map/object-deletion",
44        "test262/Map/object-creation",
45        "test262/Map/garbage-collection",
46    ]:
47      for variant_index in range(total_variants):
48        cases.append("%s-Variant-%d" % (case, variant_index))
49
50    for case in cases:
51      self.assertTrue(0 <= radix_hash(capacity=7, key=case) < 7)
52
53
54if __name__ == '__main__':
55  unittest.main()
56