-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Nicolas Cornu <nicolas.cornu@epfl.ch>
- Loading branch information
Showing
3 changed files
with
50 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <algorithm> | ||
#include <vector> | ||
|
||
#include "oc_ansi.h" | ||
|
||
#include <catch2/catch.hpp> | ||
|
||
// This function is the one that is used in all nrn-modeldb-ci | ||
// Keep as is | ||
int cmpdfn(double a, double b) { | ||
return ((a) <= (b)) ? (((a) == (b)) ? 0 : -1) : 1; | ||
} | ||
|
||
TEST_CASE("Test nrn_mlh_gsort output", "[nrn_gsort]") { | ||
std::vector<double> input{1.2, -2.5, 5.1}; | ||
|
||
{ | ||
std::vector<int> indices(input.size()); | ||
// all values from 0 to size - 1 | ||
std::iota(indices.begin(), indices.end(), 0); | ||
|
||
// for comparison | ||
auto sorted_input = input; | ||
std::sort(sorted_input.begin(), sorted_input.end()); | ||
|
||
SECTION("Test sorting") { | ||
nrn_mlh_gsort(input.data(), indices.data(), input.size(), cmpdfn); | ||
for (auto i = 0; i < input.size(); ++i) { | ||
REQUIRE(sorted_input[i] == input[indices[i]]); | ||
} | ||
} | ||
} | ||
|
||
{ | ||
std::vector<int> indices{2, 1, 1}; | ||
std::vector<int> expected_result{1, 1, 2}; // as -2,5 < 5.1 | ||
|
||
SECTION("Test sorting with repeated indices") { | ||
nrn_mlh_gsort(input.data(), indices.data(), input.size(), cmpdfn); | ||
for (auto i = 0; i < input.size(); ++i) { | ||
REQUIRE(indices[i] == expected_result[i]); | ||
} | ||
} | ||
} | ||
} |