Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
SharedField: add operator== and operator!=
Browse files Browse the repository at this point in the history
fixes #186
  • Loading branch information
Mauricio Carneiro committed Aug 20, 2014
1 parent 0bc63ee commit d11b430
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
27 changes: 27 additions & 0 deletions gamgee/shared_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,33 @@ class SharedField {
SharedField(SharedField&& other) = default; ///< @brief safely moves the data from one SharedField to a new one without making any copies
SharedField& operator=(SharedField&& other) = default; ///< @brief safely moves the data from one SharedField to the other without making any copies

/**
* @brief compares two SharedField objects in the following order: memory address, size and values.
* @param other something to compare to
* @return true if the objects are the same (memory address-wise), or contain exactly the same values. Value comparison is dictated by TYPE's operator== implementation
*/
bool operator==(const SharedField& other) const {
if (this == &other)
return true;
if (size() != other.size())
return false;
for (auto i=0u; i != size(); ++i) {
if (operator[](i) != other[i])
return false;
}
return true;
}

/**
* @brief compares two SharedField objects in the following order: memory address, size and values.
* @param other something to compare to
* @return true if the objects are not the same (memory address-wise), or contain different number of values, or the values are not exactly the same. Value comparison is dictated by TYPE's operator== implementation
*/
bool operator!=(const SharedField& other) const {
return !(*this == other);
}


/**
* @brief random access to a given value for reading or writing
* @param index must be between 0 and the number of values for this record
Expand Down
14 changes: 8 additions & 6 deletions test/variant_reader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,15 @@ void check_shared_field_api(const Variant& record, const uint32_t truth_index) {
BOOST_CHECK(desc_bool_idx);
BOOST_CHECK_THROW(desc_float_idx[0], invalid_argument);
BOOST_CHECK_THROW(desc_integer_idx[0], invalid_argument);
// BOOST_CHECK_EQUAL(desc, record.shared_field_as_string("DESC")); // needs operator == on shared fields
// BOOST_CHECK_EQUAL(desc_idx, record.shared_field_as_string(desc_index)); // needs operator == on shared fields
BOOST_CHECK(desc == record.shared_field_as_string("DESC"));
BOOST_CHECK(desc_idx == record.shared_field_as_string(desc_index));
}
// BOOST_CHECK_EQUAL(an, record.shared_field_as_integer("AN")); // needs operator == on shared fields
// BOOST_CHECK_EQUAL(an, record.shared_field_as_integer(header.field_index("AN"))); // needs operator == on shared fields
// BOOST_CHECK_EQUAL(af, record.shared_field_as_float("AF")); // needs operator == on shared fields
// BOOST_CHECK_EQUAL(af, record.shared_field_as_float(header.field_index("AF"))); // needs operator == on shared fields
BOOST_CHECK(an == record.shared_field_as_integer("AN"));
BOOST_CHECK(an == record.shared_field_as_integer(header.field_index("AN")));
BOOST_CHECK(af == record.shared_field_as_float("AF"));
BOOST_CHECK(af == record.shared_field_as_float(header.field_index("AF")));
BOOST_CHECK(an != record.shared_field_as_integer("AF"));
BOOST_CHECK(af != record.shared_field_as_float(header.field_index("AN")));
}

void check_genotype_api(const Variant& record, const uint32_t truth_index) {
Expand Down

0 comments on commit d11b430

Please sign in to comment.