diff --git a/test/algorithms/path_finding/distance.cpp b/test/algorithms/path_finding/distance.cpp index 975a223cd..7aa0ea52f 100644 --- a/test/algorithms/path_finding/distance.cpp +++ b/test/algorithms/path_finding/distance.cpp @@ -7,10 +7,12 @@ #include #include +#include #include #include #include #include +#include #include #include @@ -360,6 +362,38 @@ TEST_CASE("A* distance", "[distance]") } } +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)); +} + TEST_CASE("a_star distance functor", "[distance]") { SECTION("Unsigned Cartesian layout") diff --git a/test/technology/sidb_nm_position.cpp b/test/technology/sidb_nm_position.cpp new file mode 100644 index 000000000..6fe9e3455 --- /dev/null +++ b/test/technology/sidb_nm_position.cpp @@ -0,0 +1,106 @@ +// +// Created by Jan Drewniok on 25.07.23. +// + +#include +#include + +#include +#include +#include +#include + +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(params, {1, 0, 0}); + CHECK(pos_x == params.lat_a * 0.1); + CHECK(pos_y == 0); + + const auto [pos2_x, pos2_y] = sidb_nm_position(params, {0, 1, 0}); + CHECK(pos2_x == 0); + CHECK(pos2_y == params.lat_b * 0.1); + + const auto [pos3_x, pos3_y] = sidb_nm_position(params, {0, 8, 1}); + CHECK(pos3_x == 0); + CHECK(pos3_y == params.lat_b * 0.8 + params.lat_c * 0.1); + + const auto [pos4_x, pos4_y] = sidb_nm_position(params, {1, 1}); + CHECK(pos4_x == params.lat_a * 0.1); + CHECK(pos4_y == params.lat_b * 0.1); + + const auto [pos5_x, pos5_y] = sidb_nm_position(params, {1, 1, 1}); + CHECK(pos5_x == params.lat_a * 0.1); + CHECK(pos5_y == params.lat_b * 0.1 + params.lat_c * 0.1); + + const auto [pos6_x, pos6_y] = sidb_nm_position(params, {1, 10, 1}); + CHECK(pos6_x == params.lat_a * 0.1); + CHECK(round_to_n_decimal_places(pos6_y, 4) == round_to_n_decimal_places(params.lat_b + params.lat_c * 0.1, 4)); + } + + 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(params, {-1, 0, 0}); + CHECK(pos_x == -params.lat_a * 0.1); + CHECK(pos_y == 0); + + const auto [pos2_x, pos2_y] = sidb_nm_position(params, {0, -1, 0}); + CHECK(pos2_x == 0); + CHECK(pos2_y == -params.lat_b * 0.1); + + const auto [pos3_x, pos3_y] = sidb_nm_position(params, {-5, -5}); + CHECK(pos3_x == -params.lat_a * 0.5); + CHECK(pos3_y == -params.lat_b * 0.5); + + const auto [pos4_x, pos4_y] = sidb_nm_position(params, {-1, -1, 1}); + CHECK(pos4_x == -params.lat_a * 0.1); + CHECK(round_to_n_decimal_places(pos4_y, 4) == -params.lat_b * 0.1 + params.lat_c * 0.1); + + const auto [pos5_x, pos5_y] = sidb_nm_position(params, {-1, -10, 1}); + CHECK(pos5_x == -params.lat_a * 0.1); + CHECK(round_to_n_decimal_places(pos5_y, 4) == -params.lat_b + params.lat_c * 0.1); + } + + 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(params, {-1, 0, 0}); + CHECK(pos_x == -0.1); + CHECK(pos_y == 0); + + const auto [pos1_x, pos1_y] = sidb_nm_position(params, {0, -1, 0}); + CHECK(pos1_x == 0); + CHECK(pos1_y == -0.2); + + const auto [pos2_x, pos2_y] = sidb_nm_position(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(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(params, {10, 1, 1}); + CHECK(pos4_x == 1); + CHECK(pos4_y == 0.5); + + const auto [pos5_x, pos5_y] = sidb_nm_position(params, {-1, -1, 1}); + CHECK(pos5_x == -0.1); + CHECK(pos5_y == 0.1); + + const auto [pos6_x, pos6_y] = sidb_nm_position(params, {10, -10, 1}); + CHECK(pos6_x == 1.0); + CHECK(round_to_n_decimal_places(pos6_y, 2) == -1.7); + } +}