Skip to content

Commit

Permalink
✅ add a few more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Drewniok committed Jul 25, 2023
1 parent ab73daa commit 0cb32e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
12 changes: 6 additions & 6 deletions include/fiction/technology/charge_distribution_surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ class charge_distribution_surface<Lyt, false> : public Lyt
* @param index1 The second index.
* @return The chargeless electrostatic potential between `index1` and `index2` (unit: V).
*/
[[nodiscard]] double chargeless_potential_between_sidbs_by_index(const uint64_t index1,
const uint64_t index2) const noexcept
[[nodiscard]] double calculate_chargeless_potential_between_sidbs_by_index(const uint64_t index1,
const uint64_t index2) const noexcept
{
if (strg->nm_dist_mat[index1][index2] == 0.0)
{
Expand All @@ -454,13 +454,13 @@ class charge_distribution_surface<Lyt, false> : public Lyt
* @param c2 The second cell.
* @return The potential between c1 and c2 (unit: eV).
*/
[[nodiscard]] double chargeless_potential_between_sidbs(const typename Lyt::cell& c1,
const typename Lyt::cell& c2) const noexcept
[[nodiscard]] double calculate_chargeless_potential_between_sidbs(const typename Lyt::cell& c1,
const typename Lyt::cell& c2) const noexcept
{
const auto index1 = static_cast<std::size_t>(cell_to_index(c1));
const auto index2 = static_cast<std::size_t>(cell_to_index(c2));

return chargeless_potential_between_sidbs_by_index(index1, index2);
return calculate_chargeless_potential_between_sidbs_by_index(index1, index2);
}
/**
* Returns the chargeless electrostatic potential between two cells.
Expand Down Expand Up @@ -891,7 +891,7 @@ class charge_distribution_surface<Lyt, false> : public Lyt
{
for (uint64_t j = 0u; j < strg->sidb_order.size(); j++)
{
strg->pot_mat[i][j] = chargeless_potential_between_sidbs_by_index(i, j);
strg->pot_mat[i][j] = calculate_chargeless_potential_between_sidbs_by_index(i, j);
}
}
}
Expand Down
21 changes: 14 additions & 7 deletions test/technology/charge_distribution_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ TEMPLATE_TEST_CASE(
charge_layout.set_all_charge_states(sidb_charge_state::POSITIVE);

// calculate potential between two sidbs (charge sign not included)
CHECK(charge_layout.chargeless_potential_between_sidbs({5, 4}, {5, 5}) > 0.0);
CHECK_THAT(charge_layout.chargeless_potential_between_sidbs({5, 4}, {5, 4}),
CHECK(charge_layout.calculate_chargeless_potential_between_sidbs({5, 4}, {5, 5}) > 0.0);
CHECK_THAT(charge_layout.calculate_chargeless_potential_between_sidbs({5, 4}, {5, 4}),
Catch::Matchers::WithinAbs(0.0, 0.00001));
CHECK(charge_layout.chargeless_potential_between_sidbs({5, 4}, {5, 6}) > 0);
CHECK(charge_layout.chargeless_potential_between_sidbs({5, 5}, {5, 6}) > 0);
CHECK_THAT(charge_layout.chargeless_potential_between_sidbs({5, 6}, {5, 5}) -
charge_layout.chargeless_potential_between_sidbs({5, 5}, {5, 6}),
CHECK(charge_layout.calculate_chargeless_potential_between_sidbs({5, 4}, {5, 6}) > 0);
CHECK(charge_layout.calculate_chargeless_potential_between_sidbs({5, 5}, {5, 6}) > 0);
CHECK_THAT(charge_layout.calculate_chargeless_potential_between_sidbs({5, 6}, {5, 5}) -
charge_layout.calculate_chargeless_potential_between_sidbs({5, 5}, {5, 6}),
Catch::Matchers::WithinAbs(0.0, 0.00001));
// read SiDBs' charge states
CHECK(charge_layout.get_charge_state({5, 4}) == sidb_charge_state::POSITIVE);
Expand Down Expand Up @@ -422,7 +422,7 @@ TEMPLATE_TEST_CASE(
lyt_new.assign_cell_type({1, 3, 0}, TestType::cell_type::NORMAL);
lyt_new.assign_cell_type({10, 5, 1}, TestType::cell_type::NORMAL);

charge_distribution_surface charge_layout_new{lyt_new, params};
const charge_distribution_surface charge_layout_new{lyt_new, params};

charge_layout_new.assign_charge_state({0, 0, 1}, sidb_charge_state::NEGATIVE);
charge_layout_new.assign_charge_state({1, 3, 0}, sidb_charge_state::POSITIVE);
Expand All @@ -432,6 +432,13 @@ TEMPLATE_TEST_CASE(
CHECK(charge_layout_new.get_charge_state({1, 3, 0}) == sidb_charge_state::POSITIVE);
CHECK(charge_layout_new.get_charge_state({10, 5, 1}) == sidb_charge_state::NEUTRAL);

CHECK_THAT(charge_layout_new.get_chargeless_potential_between_sidbs({0, 0, 1}, {1, 3, 0}) -
charge_layout_new.calculate_chargeless_potential_between_sidbs({0, 0, 1}, {1, 3, 0}),
Catch::Matchers::WithinAbs(0.0, 0.000001));

CHECK(charge_layout_new.get_chargeless_potential_between_sidbs({0, 0, 1}, {0, 0, 1}) == 0.0);
CHECK(charge_layout_new.get_potential_between_sidbs({0, 0, 1}, {0, 0, 1}) == 0.0);

CHECK(charge_layout_new.get_chargeless_potential_between_sidbs({0, 0, 1}, {1, 3, 0}) > 0.0);
CHECK(charge_layout_new.get_potential_between_sidbs({0, 0, 1}, {1, 3, 0}) > 0.0);

Expand Down

0 comments on commit 0cb32e2

Please sign in to comment.