Skip to content

Commit

Permalink
Apply clang-format to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arcondello committed Nov 19, 2020
1 parent 1fdf7b6 commit 1978cfc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
38 changes: 15 additions & 23 deletions testscpp/tests/test_bqm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@
#include <vector>

#include "../Catch2/single_include/catch2/catch.hpp"
#include "dimod/adjvectorbqm.h"
#include "dimod/adjmapbqm.h"
#include "dimod/adjarraybqm.h"
#include "dimod/adjmapbqm.h"
#include "dimod/adjvectorbqm.h"

namespace dimod {

TEMPLATE_TEST_CASE("Tests for BQM Classes",
"[bqm]",
(AdjVectorBQM<int, float>), (AdjMapBQM<int, float>), (AdjArrayBQM<int, float>)) {

TEMPLATE_TEST_CASE("Tests for BQM Classes", "[bqm]", (AdjVectorBQM<int, float>),
(AdjMapBQM<int, float>), (AdjArrayBQM<int, float>)) {
SECTION("Test neighborhood()") {
float Q[9] = {1.0, 0.0, 3.0,
2.0, 1.5, 6.0,
1.0, 0.0, 0.0};
float Q[9] = {1.0, 0.0, 3.0, 2.0, 1.5, 6.0, 1.0, 0.0, 0.0};
auto bqm = TestType(Q, 3);

std::vector<typename TestType::variable_type> neighbors;
Expand Down Expand Up @@ -81,11 +77,9 @@ TEMPLATE_TEST_CASE("Tests for BQM Classes",
}

SECTION("Test neighborhood() start") {
float Q[25] = {0.0, 0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0, 0.0};
float Q[25] = {0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0,
0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0};
auto bqm = TestType(Q, 5);

std::vector<typename TestType::variable_type> neighbors;
Expand Down Expand Up @@ -141,35 +135,33 @@ TEMPLATE_TEST_CASE("Tests for BQM Classes",
float Q[4] = {1, 0, -1, 2};
auto bqm = TestType(Q, 2);

REQUIRE(bqm.get_linear(1) == 2);
REQUIRE(bqm.get_linear(1) == 2);
}

SECTION("Test get_quadratic()") {
float Q[4] = {1, 0, -1, 2};
auto bqm = TestType(Q, 2);

auto q = bqm.get_quadratic(0,1);
auto q = bqm.get_quadratic(0, 1);
REQUIRE(q.first == -1);
REQUIRE(q.second);
}
}

TEMPLATE_TEST_CASE("Tests for Shapeable BQM Classes",
"[shapeablebqm][bqm]",
TEMPLATE_TEST_CASE("Tests for Shapeable BQM Classes", "[shapeablebqm][bqm]",
(AdjVectorBQM<int, float>), (AdjMapBQM<int, float>)) {

auto bqm = TestType();
auto bqm = TestType();
bqm.add_variable();

SECTION("Test add_variable()") {
bqm.add_variable();
REQUIRE(bqm.num_variables() == 2);
REQUIRE(bqm.num_variables() == 2);
}

SECTION("Test pop_variable()") {
bqm.pop_variable();
REQUIRE(bqm.num_variables() == 0);
REQUIRE(bqm.num_variables() == 0);
}
}

} // namespace dimod
} // namespace dimod
24 changes: 10 additions & 14 deletions testscpp/tests/test_roofduality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,24 @@
//
// =============================================================================

#include "../Catch2/single_include/catch2/catch.hpp"
#include "../../dimod/roof_duality/src/fix_variables.hpp"
#include "../Catch2/single_include/catch2/catch.hpp"

namespace fix_variables_ {

TEST_CASE("Test roof_duality's fixQuboVariables()", "[roofduality]") {
SECTION("Test invalid cases") {
auto nonsquare_matrix = compressed_matrix::CompressedMatrix<double>(2,3);
REQUIRE_THROWS_AS(
fixQuboVariables(nonsquare_matrix, 2),
std::invalid_argument
);
auto nonsquare_matrix =
compressed_matrix::CompressedMatrix<double>(2, 3);
REQUIRE_THROWS_AS(fixQuboVariables(nonsquare_matrix, 2),
std::invalid_argument);

auto matrix = compressed_matrix::CompressedMatrix<double>(2,2);
REQUIRE_THROWS_AS(
fixQuboVariables(matrix, 0),
std::invalid_argument
);
auto matrix = compressed_matrix::CompressedMatrix<double>(2, 2);
REQUIRE_THROWS_AS(fixQuboVariables(matrix, 0), std::invalid_argument);
}

SECTION("Test empty case") {
auto empty_matrix = compressed_matrix::CompressedMatrix<double>(0,0);
auto empty_matrix = compressed_matrix::CompressedMatrix<double>(0, 0);
FixVariablesResult result = fixQuboVariables(empty_matrix, 2);

REQUIRE(result.offset == 0);
Expand All @@ -44,5 +40,5 @@ TEST_CASE("Test roof_duality's fixQuboVariables()", "[roofduality]") {
REQUIRE(result.newQ.numRows() == 0);
}
}
} // namespace fix_variables_

} // namespace fix_variables_

0 comments on commit 1978cfc

Please sign in to comment.