| 718 | protected: |
| 719 | template <typename Int> |
| 720 | void split( Int const n ) |
| 721 | { |
| 722 | cds::algo::number_splitter< Int > splitter( n ); |
| 723 | |
| 724 | // split by hex digit |
| 725 | for ( unsigned count = 4; count < sizeof( Int ) * 8; count += 4 ) { |
| 726 | EXPECT_EQ( splitter.cut( 4 ), static_cast<Int>( count / 4 - 1 )); |
| 727 | } |
| 728 | |
| 729 | // random cut |
| 730 | for ( int i = 0; i < 100; ++i ) { |
| 731 | splitter.reset(); |
| 732 | EXPECT_EQ( splitter.source(), n ); |
| 733 | EXPECT_EQ( splitter.bit_offset(), 0u ); |
| 734 | EXPECT_EQ( splitter.rest_count(), sizeof( Int ) * 8 ); |
| 735 | |
| 736 | unsigned total = 0; |
| 737 | Int result = 0; |
| 738 | |
| 739 | while ( total < sizeof( Int ) * 8 ) { |
| 740 | unsigned count = std::rand() % 16; |
| 741 | |
| 742 | unsigned shift = count; |
| 743 | if ( total + count > sizeof( Int ) * 8 ) |
| 744 | shift = sizeof( Int ) * 8 - total; |
| 745 | |
| 746 | result += splitter.safe_cut( count ) << total; |
| 747 | total += shift; |
| 748 | } |
| 749 | |
| 750 | EXPECT_EQ( result, n ); |
| 751 | |
| 752 | EXPECT_EQ( splitter.bit_offset(), sizeof( Int ) * 8 ); |
| 753 | EXPECT_EQ( splitter.rest_count(), 0u ); |
| 754 | } |
| 755 | } |
| 756 | }; |
| 757 | |
| 758 |
no test coverage detected