14 #include "catch2/catch.hpp" 31 auto& r =
sim.getQubitRegister();
35 CAPTURE(r1_min, r1_max, r2_min, r2_max );
37 for(std::size_t pattern = 0; pattern < 1<<(
num_qubits/2); pattern ++){
38 unsigned int bitmask = 0x1;
41 for (
unsigned int i=0; i <= r1_max -1; i++){
43 a += (
unsigned int) pow(2,i);
45 for (
unsigned int j = r2_min; j <= r2_max; j++){
46 if ( (pattern & bitmask) > 0 ){
51 CAPTURE(pattern, a, bitmask);
52 arr.
sub_reg(
sim, r1_min, r1_max, r2_min, r2_max);
53 std::string result=
"";
56 for (
unsigned int j = r2_min; j <= r2_max; j++){
57 result += std::to_string( r.GetProbability( j )).at(0);
61 std::reverse(result.begin(), result.end());
62 std::cout <<
"Sub = " << std::bitset<4>(a) <<
"-" << std::bitset<4>(pattern) <<
"=> Expected:=" << std::bitset<4>(a-pattern) <<
" : Actual:=" << result << std::endl;
73 std::size_t min_idx=0, max_idx=3;
77 auto& r =
sim.getQubitRegister();
79 SECTION(
"OLD_TEST",
"[arithmetic]"){
81 for(
int pattern = 0; pattern < 1<<(
num_qubits/2); pattern ++){
82 unsigned int bitmask = 0x1;
85 for (
unsigned int i=0; i <= r1_max -1; i++){
87 a += (
unsigned int) pow(2,i);
89 for (
unsigned int j = r2_min; j <= r2_max; j++){
90 if ( (pattern & bitmask) > 0 ){
95 arr.
sum_reg(
sim, r1_min, r1_max, r2_min, r2_max);
96 std::string result=
"";
98 for (
unsigned int j = r2_min; j <= r2_max; j++){
99 result += std::to_string( r.GetProbability( j )).at(0);
101 std::reverse(result.begin(), result.end());
102 std::cout <<
"Sub = " << std::bitset<4>(a) <<
"-" << std::bitset<4>(pattern) <<
"=> Expected:=" << std::bitset<4>(a-pattern) <<
" : Actual:=" << result << std::endl;
TEST_CASE("Arithmetic subtraction","[arithmetic]")
Test Arithmetic: subtraction.
Class definition for IntelSimulator. The purpose of this class is to map the functionality of the und...
static void sum_reg(SimulatorType &qSim, CST r1_min, CST r1_max, CST r2_min, CST r2_max)
Implements |r1>|r2> -> |r1>|r1+r2>. Required bits to represent |r1+r2> should be available prior to c...
Class definition for bit-wise summation and subtraction of qubits.
static void sub_reg(SimulatorType &qReg, const unsigned int r1_min, const unsigned int r1_max, const unsigned int r2_min, const unsigned int r2_max)
Implements |r1>|r2> -> |r1>|r1-r2>. If r1 < r2 the state will underflow, with the subtraction continu...