Skip to content
Snippets Groups Projects
Commit c1866aa4 authored by Owen Arnold's avatar Owen Arnold
Browse files

UnitCell operator== and operator!=

parent 5bd2965a
No related branches found
No related tags found
No related merge requests found
...@@ -161,6 +161,8 @@ public: ...@@ -161,6 +161,8 @@ public:
double volume() const; double volume() const;
double recVolume() const; double recVolume() const;
virtual void recalculateFromGstar(const Kernel::Matrix<double> &NewGstar); virtual void recalculateFromGstar(const Kernel::Matrix<double> &NewGstar);
bool operator==(const UnitCell &other) const;
bool operator!=(const UnitCell &other) const;
protected: protected:
/// Lattice parameter a,b,c,alpha,beta,gamma (in \f$ \mbox{ \AA } \f$ and /// Lattice parameter a,b,c,alpha,beta,gamma (in \f$ \mbox{ \AA } \f$ and
......
...@@ -880,6 +880,13 @@ void UnitCell::recalculateFromGstar(const DblMatrix &NewGstar) { ...@@ -880,6 +880,13 @@ void UnitCell::recalculateFromGstar(const DblMatrix &NewGstar) {
calculateB(); calculateB();
} }
bool UnitCell::operator==(const UnitCell &other) const {
return da == other.da; // da error not used in comparison
}
bool UnitCell::operator!=(const UnitCell &other) const {
return !this->operator==(other);
}
std::ostream &operator<<(std::ostream &out, const UnitCell &unitCell) { std::ostream &operator<<(std::ostream &out, const UnitCell &unitCell) {
// always show the lattice constants // always show the lattice constants
out << "Lattice Parameters:" << std::fixed << std::setprecision(6) out << "Lattice Parameters:" << std::fixed << std::setprecision(6)
......
...@@ -170,4 +170,53 @@ public: ...@@ -170,4 +170,53 @@ public:
TS_ASSERT_DIFFERS(precisionLimit.c(), precisionLimitOther.c()); TS_ASSERT_DIFFERS(precisionLimit.c(), precisionLimitOther.c());
TS_ASSERT_DELTA(precisionLimit.c(), precisionLimitOther.c(), 1e-9); TS_ASSERT_DELTA(precisionLimit.c(), precisionLimitOther.c(), 1e-9);
} }
void test_equals_when_unitcell_identical() {
const UnitCell a(2.0, 4.0, 5.0, 90.0, 100.0, 102.0);
const UnitCell b(a);
TS_ASSERT_EQUALS(a, b);
TS_ASSERT(!(a != b));
}
void test_not_equals_when_unitcell_differs_in_a() {
const UnitCell a(1.0, 1.0, 1.0, 90.0, 90.0, 90.0);
UnitCell b(a);
b.seta(2.0);
TS_ASSERT_DIFFERS(a, b);
}
void test_not_equals_when_unitcell_differs_in_b() {
const UnitCell a(1.0, 1.0, 1.0, 90.0, 90.0, 90.0);
UnitCell b(a);
b.setb(2.0);
TS_ASSERT_DIFFERS(a, b);
}
void test_not_equals_when_unitcell_differs_in_c() {
const UnitCell a(1.0, 1.0, 1.0, 90.0, 90.0, 90.0);
UnitCell b(a);
b.setc(2.0);
TS_ASSERT_DIFFERS(a, b);
}
void test_not_equals_when_unitcell_differs_in_alpha() {
const UnitCell a(1.0, 1.0, 1.0, 90.0, 90.0, 90.0);
UnitCell b(a);
b.setalpha(100);
TS_ASSERT_DIFFERS(a, b);
}
void test_not_equals_when_unitcell_differs_in_beta() {
const UnitCell a(1.0, 1.0, 1.0, 90.0, 90.0, 90.0);
UnitCell b(a);
b.setbeta(100);
TS_ASSERT_DIFFERS(a, b);
}
void test_not_equals_when_unitcell_differs_in_gamma() {
const UnitCell a(1.0, 1.0, 1.0, 90.0, 90.0, 90.0);
UnitCell b(a);
b.setgamma(100);
TS_ASSERT_DIFFERS(a, b);
}
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment