Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Add missing unit test for sidb distance #259

Merged
merged 44 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9622e83
:arrow_up: Bump libs/Catch2 from `6783411` to `1f881ab` (#27)
dependabot[bot] Apr 2, 2023
2da4f7e
Merge branch 'marcelwa:main' into main
Drewniok Apr 14, 2023
8f5f52f
:arrow_up: Bump libs/parallel-hashmap from `7883cb6` to `d2bed96` (#33)
dependabot[bot] Apr 14, 2023
a8cbc27
Merge branch 'marcelwa:main' into main
Drewniok Apr 18, 2023
3b11f93
Merge branch 'marcelwa:main' into main
Drewniok Apr 18, 2023
e9e2fa3
Merge branch 'marcelwa:main' into main
Drewniok Apr 18, 2023
37c881e
Merge branch 'marcelwa:main' into main
Drewniok Apr 19, 2023
4aa8489
Merge branch 'marcelwa:main' into main
Drewniok Apr 19, 2023
1587ef3
Merge branch 'marcelwa:main' into main
Drewniok Apr 20, 2023
04ed1c3
Merge branch 'marcelwa:main' into main
Drewniok Apr 21, 2023
9eaaf1f
Merge branch 'marcelwa:main' into main
Drewniok Apr 25, 2023
0dca9cf
Merge branch 'marcelwa:main' into main
Drewniok Apr 26, 2023
ce8b2e2
Merge branch 'marcelwa:main' into main
Drewniok May 1, 2023
64501c1
Merge branch 'marcelwa:main' into main
Drewniok May 10, 2023
68f6885
Merge branch 'marcelwa:main' into main
Drewniok May 11, 2023
84634cd
Merge branch 'marcelwa:main' into main
Drewniok May 12, 2023
597b1a7
Merge branch 'marcelwa:main' into main
Drewniok May 12, 2023
1920794
Merge branch 'marcelwa:main' into main
Drewniok May 14, 2023
5d74ac6
Merge branch 'marcelwa:main' into main
Drewniok May 21, 2023
f408962
Merge branch 'marcelwa:main' into main
Drewniok May 24, 2023
b4138de
Merge branch 'marcelwa:main' into main
Drewniok May 25, 2023
930fcf2
Merge branch 'marcelwa:main' into main
Drewniok Jun 5, 2023
cbd8345
Merge branch 'marcelwa:main' into main
Drewniok Jun 7, 2023
2903532
Merge branch 'marcelwa:main' into main
Drewniok Jun 12, 2023
f70ceb6
Merge branch 'marcelwa:main' into main
Drewniok Jun 14, 2023
24ff3a7
Merge branch 'marcelwa:main' into main
Drewniok Jun 16, 2023
a4f3150
Merge branch 'marcelwa:main' into main
Drewniok Jun 19, 2023
9c78984
Merge branch 'marcelwa:main' into main
Drewniok Jun 23, 2023
c3f4e96
Merge branch 'marcelwa:main' into main
Drewniok Jun 28, 2023
853be74
Merge branch 'cda-tum:main' into main
Drewniok Jul 5, 2023
13eab3c
Merge branch 'cda-tum:main' into main
Drewniok Jul 10, 2023
1c59a58
Merge branch 'cda-tum:main' into main
Drewniok Jul 18, 2023
1f87c22
Merge branch 'cda-tum:main' into main
Drewniok Jul 20, 2023
d300bc1
Merge branch 'cda-tum:main' into main
Drewniok Jul 24, 2023
2dc75ac
Merge branch 'cda-tum:main' into main
Drewniok Jul 25, 2023
2f6990e
:heavy_minus_sign: Remove ``unit`` library due to increasing simulati…
Drewniok Jul 25, 2023
04d6607
:white_check_mark: add test for sidb_nm_position.hpp and ``sidb_nanom…
Drewniok Jul 25, 2023
ce63b2d
:art: implement Marcel's suggestions.
Drewniok Jul 25, 2023
6270e4f
Merge branch 'remove_unit_library' into add_unit_test_sidb_distance
Drewniok Jul 25, 2023
9fc5819
Merge branch 'cda-tum:main' into main
Drewniok Jul 26, 2023
bd5cfc3
Merge branch 'cda-tum:main' into main
Drewniok Jul 26, 2023
f8b9a0d
Merge branch 'main' into add_unit_test_sidb_distance
Drewniok Jul 26, 2023
e2fe89d
:art: convert lattice constants to ``nm`.
Drewniok Jul 26, 2023
654fa8a
:art: implement Marcel's suggestions.
Drewniok Jul 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions test/algorithms/path_finding/distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

#include <fiction/algorithms/path_finding/a_star.hpp>
#include <fiction/algorithms/path_finding/distance.hpp>
#include <fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp>
#include <fiction/layouts/cartesian_layout.hpp>
#include <fiction/layouts/cell_level_layout.hpp>
#include <fiction/layouts/clocked_layout.hpp>
#include <fiction/layouts/coordinates.hpp>
#include <fiction/types.hpp>

#include <cmath>
#include <limits>
Expand Down Expand Up @@ -360,6 +362,38 @@
}
}

TEST_CASE("SiDB nanometer distance", "[distance]")
{
const sidb_cell_clk_lyt_siqad layout{};

CHECK(sidb_nanometer_distance(layout, {0, 0}, {0, 0}) == 0);
CHECK(sidb_nanometer_distance(layout, {1, 0}, {1, 0}) == 0);
CHECK(sidb_nanometer_distance(layout, {0, 1}, {0, 1}) == 0);

CHECK(sidb_nanometer_distance(layout, {-3, 0}, {-3, 0}) == 0);
CHECK(sidb_nanometer_distance(layout, {0, -5}, {0, -5}) == 0);

CHECK(sidb_nanometer_distance(layout, {0, 1, 1}, {0, 1, 1}) == 0);
CHECK(sidb_nanometer_distance(layout, {0, 0}, {1, 0}) == sidb_simulation_parameters{}.lat_a * 0.1);
CHECK(sidb_nanometer_distance(layout, {0, 0}, {0, 1}) == sidb_simulation_parameters{}.lat_b * 0.1);
CHECK(sidb_nanometer_distance(layout, {0, 0}, {0, 0, 1}) == sidb_simulation_parameters{}.lat_c * 0.1);

CHECK(sidb_nanometer_distance(layout, {0, 0}, {-1, 0}) == sidb_simulation_parameters{}.lat_a * 0.1);
CHECK(sidb_nanometer_distance(layout, {0, 0}, {0, -1}) == sidb_simulation_parameters{}.lat_b * 0.1);
CHECK(sidb_nanometer_distance(layout, {0, 0}, {0, 0, -1}) == sidb_simulation_parameters{}.lat_c * 0.1);

CHECK(sidb_nanometer_distance(layout, {0, 0}, {0, 2, 1}) ==
sidb_simulation_parameters{}.lat_b * 0.2 + sidb_simulation_parameters{}.lat_c * 0.1);
CHECK(sidb_nanometer_distance(layout, {0, 0}, {0, -2, 1}) ==
sidb_simulation_parameters{}.lat_b * 0.2 - sidb_simulation_parameters{}.lat_c * 0.1);
CHECK(sidb_nanometer_distance(layout, {0, -2, 1}, {0, 0}) ==
sidb_simulation_parameters{}.lat_b * 0.2 - sidb_simulation_parameters{}.lat_c * 0.1);

CHECK(sidb_nanometer_distance(layout, {0, 2, 1}, {-5, 1, 0}) ==
std::hypot(sidb_simulation_parameters{}.lat_a * 0.5,
sidb_simulation_parameters{}.lat_b * 0.1 + sidb_simulation_parameters{}.lat_c * 0.1));

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
}

TEST_CASE("a_star distance functor", "[distance]")
{
SECTION("Unsigned Cartesian layout")
Expand Down
106 changes: 106 additions & 0 deletions test/technology/sidb_nm_position.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// Created by Jan Drewniok on 25.07.23.
//

#include <catch2/catch_template_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>

#include <fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp>
#include <fiction/technology/sidb_nm_position.hpp>
#include <fiction/types.hpp>
#include <fiction/utils/math_utils.hpp>

using namespace fiction;

TEST_CASE("SiDB position in nanometer", "[sidb_nm_position]")
{
SECTION("Default lattice constants, positive cell coordinates")
{
const sidb_cell_clk_lyt_siqad layout{};
const sidb_simulation_parameters params{};

const auto [pos_x, pos_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {1, 0, 0});
CHECK(pos_x == params.lat_a * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
CHECK(pos_y == 0);

const auto [pos2_x, pos2_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {0, 1, 0});
CHECK(pos2_x == 0);
CHECK(pos2_y == params.lat_b * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.

const auto [pos3_x, pos3_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {0, 8, 1});
CHECK(pos3_x == 0);
CHECK(pos3_y == params.lat_b * 0.8 + params.lat_c * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.

const auto [pos4_x, pos4_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {1, 1});
CHECK(pos4_x == params.lat_a * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
CHECK(pos4_y == params.lat_b * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.

const auto [pos5_x, pos5_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {1, 1, 1});
CHECK(pos5_x == params.lat_a * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
CHECK(pos5_y == params.lat_b * 0.1 + params.lat_c * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.

const auto [pos6_x, pos6_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {1, 10, 1});
CHECK(pos6_x == params.lat_a * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
CHECK(round_to_n_decimal_places(pos6_y, 4) == round_to_n_decimal_places(params.lat_b + params.lat_c * 0.1, 4));

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
}

SECTION("Default lattice constants, negative cell coordinates")
{
const sidb_cell_clk_lyt_siqad layout{};
const sidb_simulation_parameters params{};

const auto [pos_x, pos_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {-1, 0, 0});
CHECK(pos_x == -params.lat_a * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
CHECK(pos_y == 0);

const auto [pos2_x, pos2_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {0, -1, 0});
CHECK(pos2_x == 0);
CHECK(pos2_y == -params.lat_b * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.

const auto [pos3_x, pos3_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {-5, -5});
CHECK(pos3_x == -params.lat_a * 0.5);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
CHECK(pos3_y == -params.lat_b * 0.5);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.

const auto [pos4_x, pos4_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {-1, -1, 1});
CHECK(pos4_x == -params.lat_a * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
CHECK(round_to_n_decimal_places(pos4_y, 4) == -params.lat_b * 0.1 + params.lat_c * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.

const auto [pos5_x, pos5_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {-1, -10, 1});
CHECK(pos5_x == -params.lat_a * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
CHECK(round_to_n_decimal_places(pos5_y, 4) == -params.lat_b + params.lat_c * 0.1);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
}

SECTION("Special lattice constants, positive and negative cell coordinates")
{
const sidb_cell_clk_lyt_siqad layout{};
const sidb_simulation_parameters params{3, -0.32, 5.6, 5.0, 1, 2, 3};

const auto [pos_x, pos_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {-1, 0, 0});
CHECK(pos_x == -0.1);
CHECK(pos_y == 0);

const auto [pos1_x, pos1_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {0, -1, 0});
CHECK(pos1_x == 0);
CHECK(pos1_y == -0.2);

const auto [pos2_x, pos2_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {0, 0, 1});
CHECK(pos2_x == 0);
CHECK(round_to_n_decimal_places(pos2_y, 2) == 0.3);

const auto [pos3_x, pos3_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {0, 0, 1});
CHECK(pos3_x == 0);
CHECK(round_to_n_decimal_places(pos3_y, 2) == 0.3);

const auto [pos4_x, pos4_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {10, 1, 1});
CHECK(pos4_x == 1);
CHECK(pos4_y == 0.5);

const auto [pos5_x, pos5_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {-1, -1, 1});
CHECK(pos5_x == -0.1);
CHECK(pos5_y == 0.1);

const auto [pos6_x, pos6_y] = sidb_nm_position<sidb_cell_clk_lyt_siqad>(params, {10, -10, 1});
CHECK(pos6_x == 1.0);
CHECK(round_to_n_decimal_places(pos6_y, 2) == -1.7);
}
}
Loading