Skip to content
Snippets Groups Projects
Commit ac97ae0d authored by Vasileios Karakasis's avatar Vasileios Karakasis
Browse files

Added comparison operators for cell records.

The will be useful for sorting cell records. Equality and ordering is
defined solely on records IDs.
parent 67784417
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment