| 53 | TEST_CASE( "getPauliStr", TEST_CATEGORY ) { |
| 54 | |
| 55 | SECTION( LABEL_CORRECTNESS ) { |
| 56 | |
| 57 | GENERATE( range(0,10) ); |
| 58 | |
| 59 | std::string charSet = GENERATE( "IXYZ", "ixyz", "0123", "iX2z" ); |
| 60 | |
| 61 | int numPaulis = GENERATE( 1, 2, 5, 10, 20, 30, 31, 32, 33, 60, 64 ); |
| 62 | auto targets = getRandomSubRange(0, 64, numPaulis); |
| 63 | |
| 64 | // not necessary to add a terminal char when we specify numPaulis |
| 65 | vector<char> pauliChars(numPaulis, 'I'); |
| 66 | vector<int> pauliInts(numPaulis, 0); |
| 67 | long long unsigned lowValue = 0; |
| 68 | long long unsigned highValue = 0; |
| 69 | |
| 70 | for (int i=0; i<numPaulis; i++) { |
| 71 | int v = getRandomInt(1, 3+1); |
| 72 | pauliInts[i] = v; |
| 73 | pauliChars[i] = charSet[v]; |
| 74 | |
| 75 | int t = targets[i]; |
| 76 | (t < 32)? |
| 77 | (lowValue += v * getPow2(2 * t)): // pow4 |
| 78 | (highValue += v * getPow2(2 * (t-32))); // pow4 |
| 79 | } |
| 80 | |
| 81 | SECTION( LABEL_C_INTERFACE ) { |
| 82 | |
| 83 | SECTION( "from chars" ) { |
| 84 | |
| 85 | CAPTURE( targets, pauliChars ); |
| 86 | |
| 87 | PauliStr str = getPauliStr(pauliChars.data(), targets.data(), numPaulis); |
| 88 | |
| 89 | REQUIRE( str.lowPaulis == lowValue ); |
| 90 | REQUIRE( str.highPaulis == highValue ); |
| 91 | } |
| 92 | |
| 93 | SECTION( "from ints" ) { |
| 94 | |
| 95 | CAPTURE( targets, pauliChars ); |
| 96 | |
| 97 | PauliStr str = getPauliStr(pauliInts.data(), targets.data(), numPaulis); |
| 98 | |
| 99 | REQUIRE( str.lowPaulis == lowValue ); |
| 100 | REQUIRE( str.highPaulis == highValue ); |
| 101 | } |
| 102 | |
| 103 | SECTION( "from literal" ) { |
| 104 | |
| 105 | // lazily ignores some above prepared vars |
| 106 | |
| 107 | int targ = targets[0]; |
| 108 | CAPTURE( targ ); |
| 109 | |
| 110 | const char* in = "X"; |
| 111 | PauliStr str = getPauliStr(in, &targ, 1); |
| 112 | REQUIRE( str.lowPaulis == ((targ < 32)? getPow2(2*targ) : 0) ); |
nothing calls this directly
no test coverage detected