1#!/usr/bin/env python3 2# Copyright 2016 Google Inc. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS-IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16from absl.testing import parameterized 17from fruit_test_common import * 18 19COMMON_DEFINITIONS = ''' 20 #include "test_common.h" 21 22 struct X1 {}; 23 struct X2 {}; 24 struct X3 {}; 25 struct X4 {}; 26 struct X5 {}; 27 struct X6 {}; 28 struct X7 {}; 29 ''' 30 31class TestSemistaticMapHashSelection(parameterized.TestCase): 32 def test_semistatic_map_hash_selection(self): 33 source = ''' 34 fruit::Component<> getComponent() { 35 return fruit::createComponent() 36 .registerConstructor<X1()>() 37 .registerConstructor<X2()>() 38 .registerConstructor<X3()>() 39 .registerConstructor<X4()>() 40 .registerConstructor<X5()>() 41 .registerConstructor<X6()>() 42 .registerConstructor<X7()>(); 43 } 44 45 int main() { 46 // The component normalization generates a random hash. By looping 50 times it's very likely that we'll get at 47 // least one hash with too many collisions (and we'll generate another). 48 for (int i = 0; i < 50; i++) { 49 fruit::NormalizedComponent<> normalizedComponent(getComponent); 50 (void) normalizedComponent; 51 } 52 } 53 ''' 54 expect_success( 55 COMMON_DEFINITIONS, 56 source, 57 locals()) 58 59if __name__ == '__main__': 60 absltest.main() 61