diff --git a/src/swcio.hpp b/src/swcio.hpp index ac39de4e1f975f3029e2716fcc8f4fb78102ad7d..ff605500af8b58a72a12c3f4d03bd4da915cfc3c 100644 --- a/src/swcio.hpp +++ b/src/swcio.hpp @@ -79,18 +79,43 @@ public: cell_record(const cell_record &other) = default; cell_record &operator=(const cell_record &other) = default; + // Equality and comparison operators friend bool operator==(const cell_record &lhs, const cell_record &rhs) { return lhs.id_ == rhs.id_; } + friend bool operator<(const cell_record &lhs, + const cell_record &rhs) + { + return lhs.id_ < rhs.id_; + } + + friend bool operator<=(const cell_record &lhs, + const cell_record &rhs) + { + return (lhs < rhs) || (lhs == rhs); + } + friend bool operator!=(const cell_record &lhs, const cell_record &rhs) { return !(lhs == rhs); } + friend bool operator>(const cell_record &lhs, + const cell_record &rhs) + { + return !(lhs < rhs) && (lhs != rhs); + } + + friend bool operator>=(const cell_record &lhs, + const cell_record &rhs) + { + return !(lhs < rhs); + } + friend std::ostream &operator<<(std::ostream &os, const cell_record &cell); kind type() const diff --git a/tests/test_swcio.cpp b/tests/test_swcio.cpp index 24ff682bbc8dd9cbc0f228e927ddad8ef0298a80..00310bbf5ac33aaa8c8afb130e6636bf463c0f7e 100644 --- a/tests/test_swcio.cpp +++ b/tests/test_swcio.cpp @@ -87,6 +87,22 @@ TEST(cell_record, construction) } } +TEST(cell_record, comparison) +{ + using namespace nestmc::io; + + { + // check comparison operators + cell_record cell0(cell_record::custom, 0, 1., 1., 1., 1., -1); + cell_record cell1(cell_record::custom, 0, 2., 3., 4., 5., -1); + cell_record cell2(cell_record::custom, 1, 2., 3., 4., 5., -1); + EXPECT_EQ(cell0, cell1); + EXPECT_LT(cell0, cell2); + EXPECT_GT(cell2, cell1); + } + +} + TEST(swc_parser, invalid_input) { using namespace nestmc::io;