Commit a952b783 authored by Mccaskey, Alex's avatar Mccaskey, Alex

started switching to google test since we have it in cpr

Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 5a8f39ba
......@@ -18,12 +18,11 @@ message(STATUS "C++ version ${CXX_STANDARD} configured.")
option(XACC_BUILD_TESTS "Build test programs" OFF)
# Make sure all build libraries have reference to their dependents
set(CMAKE_SKIP_INSTALL_RPATH OFF)
set(CMAKE_SKIP_RPATH OFF)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_install_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "@loader_path")
ENDIF("${isSystemDir}" STREQUAL "-1")
......@@ -37,6 +36,7 @@ endif()
include(ExternalProject)
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
......@@ -58,13 +58,41 @@ if(NOT WIN32)
endif()
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "$ENV{HOME}/.xacc" CACHE PATH "default install path" FORCE )
set (CMAKE_install_PREFIX "$ENV{HOME}/.xacc" CACHE PATH "default install path" FORCE )
endif()
message(STATUS "${BoldGreen}Installing XACC to ${CMAKE_INSTALL_PREFIX}. Override with -DCMAKE_INSTALL_PREFIX=...${ColorReset}")
message(STATUS "${BoldGreen}Installing XACC to ${CMAKE_install_PREFIX}. Override with -DCMAKE_install_PREFIX=...${ColorReset}")
if (XACC_BUILD_TESTS)
enable_testing()
macro(add_xacc_test _TEST_NAME)
set(XACC_LIBRARIES "${CMAKE_BINARY_DIR}/quantum/gate/libxacc-quantum-gate.dylib")
add_executable(${_TEST_NAME}Tester ${_TEST_NAME}Tester.cpp)
add_test(NAME xacc_${_TEST_NAME}Tester COMMAND ${_TEST_NAME}Tester)
target_link_libraries(${_TEST_NAME}Tester ${GTEST_LIBRARIES} xacc ${XACC_LIBRARIES}) #xacc-quantum-gate xacc-quantum-aqc)
endmacro()
macro(set_cache_variable VAR_NAME VAR_DESCRIPTION)
set(${VAR_NAME} ${${VAR_NAME}} CACHE INTERNAL ${VAR_DESCRIPTION})
message(STATUS "Set ${VAR_NAME} to ${${VAR_NAME}}.")
endmacro()
message(STATUS "Not using system gtest, using built-in googletest project instead.")
add_subdirectory(tpls/cpr/opt/googletest)
set(GTEST_FOUND TRUE)
set(GTEST_LIBRARIES gtest)
set(GTEST_MAIN_LIBRARIES gtest_main)
set(GTEST_BOTH_LIBRARIES gtest gtest_main)
set(GTEST_INCLUDE_DIRS ${gtest_SOURCE_DIR}/include)
set_property(TARGET gtest PROPERTY FOLDER "tests/gtest")
set_property(TARGET gtest_main PROPERTY FOLDER "tests/gtest")
set_cache_variable(GTEST_FOUND "Set if libgtest was found or built")
set_cache_variable(GTEST_LIBRARIES "Location of libgtest")
set_cache_variable(GTEST_MAIN_LIBRARIES "Location of libgtest-main")
set_cache_variable(GTEST_BOTH_LIBRARIES "Location of both gtest libraries")
set_cache_variable(GTEST_INCLUDE_DIRS "Location of gtest include files")
include_directories(${GTEST_INCLUDE_DIRS})
endif()
# Setup Doxygen
......@@ -89,42 +117,8 @@ include_directories(${CMAKE_SOURCE_DIR}/tpls/eigen)
add_subdirectory(xacc)
add_subdirectory(quantum)
#ExternalProject_Add(xacc-quantum
# DEPENDS xacc
# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/quantum
# CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
# -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
# -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
# -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
# -DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
# -DXACC_BINARY_DIR=${CMAKE_BINARY_DIR}
# -DBOOST_ROOT=${BOOST_ROOT}
# CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
# BUILD_ALWAYS 1
# INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage
# TEST_AFTER_INSTALL 1
# )
#find_package(PythonLibs)
if(PYTHON_INCLUDE_DIR) #PYTHONLIBS_FOUND)
add_subdirectory(python)
# ExternalProject_Add(xacc-python
# DEPENDS xacc-quantum
# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/python
# CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
# -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
# -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
# -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
# -DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
# -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
# -DXACC_BINARY_DIR=${CMAKE_BINARY_DIR}
# -DFROM_SETUP_PY=${FROM_SETUP_PY}
# -DXACC_PYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR}
# -DBOOST_ROOT=${BOOST_ROOT}
# CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
# BUILD_ALWAYS 1
# INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage
# TEST_AFTER_INSTALL 1
#)
if(PYTHON_INCLUDE_DIR)
# add_subdirectory(python)
endif()
# Install the config file for external projects to use
......@@ -134,14 +128,9 @@ endif()
configure_file("${CMAKE_SOURCE_DIR}/cmake/xacc-config.cmake.in" "${CMAKE_BINARY_DIR}/xacc-config.cmake" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/xacc-config.cmake" DESTINATION .)
install(FILES "${CMAKE_SOURCE_DIR}/cmake/Modules/tests.cmake" DESTINATION share/xacc/)
#if(APPLE)
#install(FILES ${CMAKE_BINARY_DIR}/lib/libcpr.dylib DESTINATION lib)
#else()
#install(FILES ${CMAKE_BINARY_DIR}/lib/libcpr.so DESTINATION lib)
#endif()
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/spdlog" DESTINATION include )
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/exprtk" DESTINATION include )
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/eigen" DESTINATION include )
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/rapidjson" DESTINATION include )
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/pybind11" DESTINATION include )
install( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/spdlog" DESTINATION include )
install( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/exprtk" DESTINATION include )
install( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/eigen" DESTINATION include )
install( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/rapidjson" DESTINATION include )
install( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/pybind11" DESTINATION include )
install(PROGRAMS "${CMAKE_SOURCE_DIR}/tools/framework/xacc-framework" DESTINATION bin)
......@@ -12,7 +12,6 @@
# *******************************************************************************/
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_BINARY_DIR}/tpls/cppmicroservices")
#include(${CMAKE_BINARY_DIR}/tpls/cppmicroservices/CppMicroServicesConfig.cmake)
include(CppMicroServicesConfig)
......@@ -28,9 +27,5 @@ include_directories(${CMAKE_SOURCE_DIR}/tpls/exprtk)
include_directories(${CMAKE_SOURCE_DIR}/tpls/spdlog)
include_directories(${CMAKE_SOURCE_DIR}/tpls/eigen)
#link_directories(${CMAKE_INSTALL_PREFIX}/lib)
#link_directories(${XACC_BINARY_DIR}/xacc)
#link_directories(${XACC_BINARY_DIR}/lib)
add_subdirectory(gate)
add_subdirectory(aqc)
#add_subdirectory(aqc)
......@@ -12,6 +12,5 @@
# *******************************************************************************/
# Gather tests
if(XACC_BUILD_TESTS)
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};dl;pthread;xacc-quantum-aqc;xacc;${CppUsLib};cpr;curl")
add_subdirectory(tests)
endif()
add_xacc_test(Embedding)
add_xacc_test(TrivialEmbeddingAlgorithm)
......@@ -10,15 +10,12 @@
* Contributors:
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE EmbeddingTester
#include <boost/test/included/unit_test.hpp>
#include <gtest/gtest.h>
#include "Embedding.hpp"
using namespace xacc::quantum;
BOOST_AUTO_TEST_CASE(checkLoadPersist) {
TEST(EmbeddingTester,checkLoadPersist) {
Embedding embedding;
......@@ -40,7 +37,7 @@ BOOST_AUTO_TEST_CASE(checkLoadPersist) {
"4: 7\n";
BOOST_VERIFY(ss.str() == expected);
EXPECT_TRUE(ss.str() == expected);
Embedding toBeLoaded;
std::istringstream iss(expected);
......@@ -48,9 +45,13 @@ BOOST_AUTO_TEST_CASE(checkLoadPersist) {
toBeLoaded.load(iss);
toBeLoaded.persist(std::cout);
BOOST_VERIFY(toBeLoaded == embedding);
EXPECT_TRUE(toBeLoaded == embedding);
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......@@ -10,15 +10,12 @@
* Contributors:
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE TrivialEmbeddingAlgorithm
#include <boost/test/included/unit_test.hpp>
#include <gtest/gtest.h>
#include "TrivialEmbeddingAlgorithm.hpp"
using namespace xacc::quantum;
BOOST_AUTO_TEST_CASE(checkSimpleEmbed) {
TEST(TrivialEmbeddingAlgorithmTester,checkSimpleEmbed) {
TrivialEmbeddingAlgorithm algo;
auto k44 = std::make_shared<K44Bipartite>();
......@@ -62,11 +59,11 @@ BOOST_AUTO_TEST_CASE(checkSimpleEmbed) {
std::cout << kv.first << ": ";
for (auto h : kv.second) {
std::cout << h << " ";
BOOST_VERIFY(h == i);
EXPECT_TRUE(h == i);
}
std::cout << "\n";
BOOST_VERIFY(kv.first == i);
BOOST_VERIFY(kv.second.size() == 1);
EXPECT_TRUE(kv.first == i);
EXPECT_TRUE(kv.second.size() == 1);
i++;
}
......@@ -74,9 +71,13 @@ BOOST_AUTO_TEST_CASE(checkSimpleEmbed) {
embedding = algo.embed(complete5, k44->getAcceleratorGraph(), params);
BOOST_VERIFY(embedding.empty());
EXPECT_TRUE(embedding.empty());
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......@@ -12,6 +12,5 @@
# *******************************************************************************/
# Gather tests
if(XACC_BUILD_TESTS)
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "xacc;${Boost_LIBRARIES};xacc-quantum-aqc;${CppUsLib};cpr;curl")
add_subdirectory(tests)
endif()
add_xacc_test(DWKernel)
add_xacc_test(DWQMI)
......@@ -10,15 +10,12 @@
* Contributors:
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE DWKernelTester
#include <boost/test/included/unit_test.hpp>
#include <gtest/gtest.h>
#include "DWKernel.hpp"
using namespace xacc::quantum;
BOOST_AUTO_TEST_CASE(checkDWKernelConstruction) {
TEST(DWKernelTester,checkDWKernelConstruction) {
auto qmi = std::make_shared<DWQMI>(0, 1, 2.2);
auto qmi2 = std::make_shared<DWQMI>(0);
......@@ -29,14 +26,18 @@ BOOST_AUTO_TEST_CASE(checkDWKernelConstruction) {
kernel.addInstruction(qmi2);
kernel.addInstruction(qmi3);
BOOST_VERIFY(kernel.nInstructions() == 3);
BOOST_VERIFY(kernel.name() == "foo");
BOOST_VERIFY(kernel.getInstruction(0) == qmi);
BOOST_VERIFY(kernel.getInstruction(1) == qmi2);
BOOST_VERIFY(kernel.getInstruction(2) == qmi3);
EXPECT_TRUE(kernel.nInstructions() == 3);
EXPECT_TRUE(kernel.name() == "foo");
EXPECT_TRUE(kernel.getInstruction(0) == qmi);
EXPECT_TRUE(kernel.getInstruction(1) == qmi2);
EXPECT_TRUE(kernel.getInstruction(2) == qmi3);
const std::string expected = "0 1 2.2\n0 0 0\n22 22 3.3\n";
BOOST_VERIFY(kernel.toString("") == expected);
EXPECT_TRUE(kernel.toString("") == expected);
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......@@ -10,37 +10,38 @@
* Contributors:
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE DWQMITester
#include <boost/test/included/unit_test.hpp>
#include <gtest/gtest.h>
#include "DWQMI.hpp"
using namespace xacc::quantum;
BOOST_AUTO_TEST_CASE(checkDWQMIConstruction) {
TEST(DWQMITester,checkDWQMIConstruction) {
DWQMI qmi(0, 1, 2.2);
BOOST_VERIFY(qmi.bits()[0] == 0);
BOOST_VERIFY(qmi.bits()[1] == 1);
BOOST_VERIFY(boost::get<double>(qmi.getParameter(0)) == 2.2);
BOOST_VERIFY(qmi.toString("") == "0 1 2.2");
EXPECT_TRUE(qmi.bits()[0] == 0);
EXPECT_TRUE(qmi.bits()[1] == 1);
EXPECT_TRUE(boost::get<double>(qmi.getParameter(0)) == 2.2);
EXPECT_TRUE(qmi.toString("") == "0 1 2.2");
DWQMI qmi2(0);
BOOST_VERIFY(qmi2.bits()[0] == 0);
BOOST_VERIFY(qmi2.bits()[1] == 0);
BOOST_VERIFY(boost::get<double>(qmi2.getParameter(0)) == 0.0);
BOOST_VERIFY(qmi2.toString("") == "0 0 0");
EXPECT_TRUE(qmi2.bits()[0] == 0);
EXPECT_TRUE(qmi2.bits()[1] == 0);
EXPECT_TRUE(boost::get<double>(qmi2.getParameter(0)) == 0.0);
EXPECT_TRUE(qmi2.toString("") == "0 0 0");
DWQMI qmi3(22, 3.3);
BOOST_VERIFY(qmi3.bits()[0] == 22);
BOOST_VERIFY(qmi3.bits()[1] == 22);
BOOST_VERIFY(boost::get<double>(qmi3.getParameter(0)) == 3.3);
BOOST_VERIFY(qmi3.toString("") == "22 22 3.3");
EXPECT_TRUE(qmi3.bits()[0] == 22);
EXPECT_TRUE(qmi3.bits()[1] == 22);
EXPECT_TRUE(boost::get<double>(qmi3.getParameter(0)) == 3.3);
EXPECT_TRUE(qmi3.toString("") == "22 22 3.3");
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......@@ -53,11 +53,7 @@ usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
manifest.json
)
#set(BOOST_ROOT ${CMAKE_INSTALL_PREFIX})
#find_package(Boost COMPONENTS system program_options filesystem chrono regex graph REQUIRED)
target_link_libraries(${LIBRARY_NAME} PUBLIC CppMicroServices xacc ${Boost_LIBRARIES}) #${CppUsLib}) #${Boost_LIBRARIES} xacc ${CppUsLib} restclient-cpp) #cpprest ${OPENSSL_LIBRARIES})
target_link_libraries(${LIBRARY_NAME} PUBLIC xacc)
if(APPLE)
set_target_properties(xacc-quantum-gate PROPERTIES INSTALL_RPATH "@loader_path")
......
......@@ -12,6 +12,5 @@
# *******************************************************************************/
# Gather tests
if(XACC_BUILD_TESTS)
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${Boost_LIBRARIES};xacc-quantum-gate;xacc;${CppUsLib};cpr;curl")
add_subdirectory(tests)
endif()
add_xacc_test(ReadoutErrorAcceleratorBufferPostprocessor)
......@@ -10,10 +10,7 @@
* Contributors:
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE ReadoutErrorAcceleratorBufferPostprocessorTester
#include <boost/test/included/unit_test.hpp>
#include <gtest/gtest.h>
#include "ReadoutErrorAcceleratorBufferPostprocessor.hpp"
#include "GateIR.hpp"
#include <boost/math/constants/constants.hpp>
......@@ -114,7 +111,7 @@ public:
};
BOOST_AUTO_TEST_CASE(checkSimple) {
TEST(ReadoutErrorAcceleratorBufferPostprocessorTester,checkSimple) {
xacc::Initialize();
// Simple example H = X0
......@@ -161,6 +158,10 @@ BOOST_AUTO_TEST_CASE(checkSimple) {
std::cout << "HELLO: " << fixed[0]->getExpectationValueZ() << "\n";
xacc::Finalize();
// BOOST_VERIFY(std::fabs(fixed[0]->getExpectationValueZ() - .911111) < 1e-6);
// EXPECT_TRUE(std::fabs(fixed[0]->getExpectationValueZ() - .911111) < 1e-6);
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......@@ -13,6 +13,5 @@
# Gather tests
if(XACC_BUILD_TESTS)
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};xacc;xacc-quantum-gate;${CppUsLib};cpr;curl")
add_subdirectory(tests)
endif()
......@@ -69,8 +69,7 @@ public:
/**
* The nullary Constructor
*/
GateIR() {
}
GateIR() {}
/**
* This method takes the list of quantum instructions that this
......
add_xacc_test(CNOT)
add_xacc_test(CPhase)
add_xacc_test(ConditionalFunction)
add_xacc_test(GateFunction)
add_xacc_test(GateIR)
add_xacc_test(GateVisitor)
add_xacc_test(Hadamard)
add_xacc_test(InverseQFT)
add_xacc_test(QFT)
add_xacc_test(Measure)
add_xacc_test(QubitMapIRPreprocessor)
add_xacc_test(ReadoutErrorIRPreprocessor)
add_xacc_test(Rx)
add_xacc_test(Ry)
add_xacc_test(Rz)
add_xacc_test(Swap)
add_xacc_test(X)
add_xacc_test(Y)
add_xacc_test(Z)
......@@ -10,29 +10,30 @@
* Contributors:
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE HadamardTester
#include <boost/test/included/unit_test.hpp>
#include <gtest/gtest.h>
#include "CNOT.hpp"
using namespace xacc::quantum;
BOOST_AUTO_TEST_CASE(checkCreation) {
TEST(CNOTTester,checkCreation) {
CNOT cnot(0, 1);
BOOST_VERIFY(cnot.toString("qreg") == "CNOT qreg0,qreg1");
BOOST_VERIFY(cnot.bits().size() == 2);
BOOST_VERIFY(cnot.bits()[0] == 0);
BOOST_VERIFY(cnot.bits()[1] == 1);
BOOST_VERIFY(cnot.name() == "CNOT");
EXPECT_TRUE(cnot.toString("qreg") == "CNOT qreg0,qreg1");
EXPECT_TRUE(cnot.bits().size() == 2);
EXPECT_TRUE(cnot.bits()[0] == 0);
EXPECT_TRUE(cnot.bits()[1] == 1);
EXPECT_TRUE(cnot.name() == "CNOT");
CNOT cnot2(44, 46);
BOOST_VERIFY(cnot2.toString("qreg") == "CNOT qreg44,qreg46");
BOOST_VERIFY(cnot2.bits().size() == 2);
BOOST_VERIFY(cnot2.bits()[0] == 44);
BOOST_VERIFY(cnot2.bits()[1] == 46);
BOOST_VERIFY(cnot2.name() == "CNOT");
EXPECT_TRUE(cnot2.toString("qreg") == "CNOT qreg44,qreg46");
EXPECT_TRUE(cnot2.bits().size() == 2);
EXPECT_TRUE(cnot2.bits()[0] == 44);
EXPECT_TRUE(cnot2.bits()[1] == 46);
EXPECT_TRUE(cnot2.name() == "CNOT");
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......@@ -10,32 +10,34 @@
* Contributors:
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE CPhaseTester
#include <boost/test/included/unit_test.hpp>
#include <gtest/gtest.h>
#include "CPhase.hpp"
using namespace xacc::quantum;
BOOST_AUTO_TEST_CASE(checkCreation) {
TEST(CPhaseTester,checkCreation) {
CPhase cp(0, 1, 3.14);
BOOST_VERIFY(boost::get<double>(cp.getParameter(0)) == 3.14);
BOOST_VERIFY(cp.toString("qreg") == "CPhase(3.14) qreg0,qreg1");
BOOST_VERIFY(cp.bits().size() == 2);
BOOST_VERIFY(cp.bits()[0] == 0);
BOOST_VERIFY(cp.bits()[1] == 1);
BOOST_VERIFY(cp.name() == "CPhase");
EXPECT_TRUE(boost::get<double>(cp.getParameter(0)) == 3.14);
EXPECT_TRUE(cp.toString("qreg") == "CPhase(3.14) qreg0,qreg1");
EXPECT_TRUE(cp.bits().size() == 2);
EXPECT_TRUE(cp.bits()[0] == 0);
EXPECT_TRUE(cp.bits()[1] == 1);
EXPECT_TRUE(cp.name() == "CPhase");
CPhase cp2(44, 45, 1.71234);
BOOST_VERIFY(boost::get<double>(cp2.getParameter(0)) == 1.71234);
BOOST_VERIFY(cp2.toString("qreg") == "CPhase(1.71234) qreg44,qreg45");
BOOST_VERIFY(cp2.bits().size() == 2);
BOOST_VERIFY(cp2.bits()[0] == 44);
BOOST_VERIFY(cp2.bits()[1] == 45);
BOOST_VERIFY(cp2.name() == "CPhase");
EXPECT_TRUE(boost::get<double>(cp2.getParameter(0)) == 1.71234);
EXPECT_TRUE(cp2.toString("qreg") == "CPhase(1.71234) qreg44,qreg45");
EXPECT_TRUE(cp2.bits().size() == 2);
EXPECT_TRUE(cp2.bits()[0] == 44);
EXPECT_TRUE(cp2.bits()[1] == 45);
EXPECT_TRUE(cp2.name() == "CPhase");
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......@@ -10,10 +10,7 @@
* Contributors:
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE ConditionalFunctionTester
#include <boost/test/included/unit_test.hpp>
#include <gtest/gtest.h>
#include "ConditionalFunction.hpp"
#include "Hadamard.hpp"
#include "CNOT.hpp"
......@@ -22,7 +19,7 @@
using namespace xacc::quantum;
BOOST_AUTO_TEST_CASE(checkFunctionMethods) {
TEST(ConditionalFunctionTester,checkFunctionMethods) {
ConditionalFunction f(0);
auto h = std::make_shared<Hadamard>(1);
......@@ -34,21 +31,25 @@ BOOST_AUTO_TEST_CASE(checkFunctionMethods) {
f.addInstruction(cn1);
f.addInstruction(cn2);
f.addInstruction(h2);
BOOST_VERIFY(f.nInstructions() == 4);
EXPECT_TRUE(f.nInstructions() == 4);
for (auto i : f.getInstructions()) {
BOOST_VERIFY(!i->isEnabled());
EXPECT_TRUE(!i->isEnabled());
}
f.evaluate(0);
for (auto i : f.getInstructions()) {
BOOST_VERIFY(!i->isEnabled());
EXPECT_TRUE(!i->isEnabled());
}
f.evaluate(1);
for (auto i : f.getInstructions()) {
BOOST_VERIFY(i->isEnabled());
EXPECT_TRUE(i->isEnabled());
}
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......@@ -10,10 +10,7 @@
* Contributors:
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE GateFunctionTester
#include <boost/test/included/unit_test.hpp>
#include <gtest/gtest.h>
#include "GateFunction.hpp"
#include "Hadamard.hpp"
#include "CNOT.hpp"
......@@ -28,11 +25,11 @@ const std::string expectedQasm =
"CNOT qreg0,qreg1\n"
"H qreg0\n";