Skip to content

Commit

Permalink
Get gtest 1.10.0 and parametrize tests (#75)
Browse files Browse the repository at this point in the history
* parametrize utils tests

* name

* header

* test case version

* try gtest 1.10.0

* test suite

* parametrize maxDecimalForQubitTests
  • Loading branch information
antalszava committed Mar 3, 2021
1 parent 5b48b7f commit 5c869c3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:

- name: Install Google Test
run: |
wget -qO - https://github.com/google/googletest/archive/release-1.8.1.tar.gz | tar -xz
cmake -D CMAKE_INSTALL_PREFIX:PATH=$HOME/googletest -D CMAKE_BUILD_TYPE=Release googletest-release-1.8.1
wget -qO - https://github.com/google/googletest/archive/release-1.10.0.tar.gz | tar -xz
cmake -D CMAKE_INSTALL_PREFIX:PATH=$HOME/googletest -D CMAKE_BUILD_TYPE=Release googletest-release-1.10.0
make install
- name: Build and run unit tests
Expand Down
58 changes: 36 additions & 22 deletions pennylane_lightning/src/tests/lightning_util_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,47 @@
#include "gtest/gtest.h"
#include "../rework/Util.hpp"

#include <tuple>

namespace test_utils {

TEST(exp2, fixed_example) {
std::vector<unsigned int> inputs = {1, 2, 5, 8};
std::vector<size_t> outputs = {2, 4, 32, 256};
class Exp2TestFixture :public ::testing::TestWithParam<std::tuple<int, int>> {
};

for (size_t i = 0; i < inputs.size(); i++) {
size_t result = Pennylane::exp2(inputs[i]);
EXPECT_TRUE(result == outputs[i]);
}
TEST_P(Exp2TestFixture, CheckExp2Results) {
int input = std::get<0>(GetParam());
int expected = std::get<1>(GetParam());
ASSERT_EQ(expected, Pennylane::exp2(input));
}

TEST(maxDecimalForQubit, fixed_example) {
std::vector<std::vector<unsigned int>> inputs = {
{0, 3},
{1, 3},
{2, 3},
{0, 4},
{2, 4},
{2, 5},
};
std::vector<size_t> outputs = {4, 2, 1, 8, 2, 4};

for (size_t i = 0; i < inputs.size(); i++) {
size_t result = Pennylane::maxDecimalForQubit(inputs[i][0], inputs[i][1]);
EXPECT_TRUE(result == outputs[i]);
}
INSTANTIATE_TEST_SUITE_P (
Exp2Tests,
Exp2TestFixture,
::testing::Values(
std::make_tuple(1, 2),
std::make_tuple(2, 4),
std::make_tuple(5, 32),
std::make_tuple(8, 256)));

class maxDecimalForQubitTestFixture :public ::testing::TestWithParam<std::tuple<unsigned int, unsigned int, size_t>> {
};

TEST_P(maxDecimalForQubitTestFixture, CheckMaxDecimalResults) {
unsigned int qubitIndex = std::get<0>(GetParam());
unsigned int qubits = std::get<1>(GetParam());
size_t expected = std::get<2>(GetParam());
ASSERT_EQ(expected, Pennylane::maxDecimalForQubit(qubitIndex, qubits));
}

INSTANTIATE_TEST_SUITE_P (
maxDecimalForQubitTests,
maxDecimalForQubitTestFixture,
::testing::Values(
std::make_tuple(0, 3, 4),
std::make_tuple(1, 3, 2),
std::make_tuple(2, 3, 1),
std::make_tuple(0, 4, 8),
std::make_tuple(2, 4, 2),
std::make_tuple(2, 5, 4)));

}

0 comments on commit 5c869c3

Please sign in to comment.