| 65 | TEST_CASE( "setMaxNumReportedSigFigs", TEST_CATEGORY ) { |
| 66 | |
| 67 | SECTION( LABEL_CORRECTNESS ) { |
| 68 | |
| 69 | qcomp scalar = getQcomp(0.12345, 0.12345); |
| 70 | |
| 71 | vector<std::string> refs = { |
| 72 | "0.1+0.1i", |
| 73 | "0.12+0.12i", |
| 74 | "0.123+0.123i", |
| 75 | "0.1235+0.1235i", // rounded |
| 76 | "0.12345+0.12345i" |
| 77 | }; |
| 78 | |
| 79 | // disable auto \n after lines |
| 80 | setNumReportedNewlines(0); |
| 81 | |
| 82 | for (size_t numSigFigs=1; numSigFigs<=refs.size(); numSigFigs++) { |
| 83 | |
| 84 | setMaxNumReportedSigFigs(numSigFigs); |
| 85 | |
| 86 | // redirect stdout to buffer |
| 87 | std::stringstream buffer; |
| 88 | std::streambuf * old = std::cout.rdbuf(buffer.rdbuf()); |
| 89 | reportScalar("", scalar); |
| 90 | std::cout.rdbuf(old); |
| 91 | std::string out = buffer.str(); |
| 92 | |
| 93 | std::string ref = refs[numSigFigs-1]; |
| 94 | |
| 95 | CAPTURE( numSigFigs, ref ); |
| 96 | REQUIRE( out == ref ); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | SECTION( LABEL_VALIDATION ) { |
| 101 |
no test coverage detected