Added operator== and != to Common::Array

svn-id: r45247
This commit is contained in:
Max Horn 2009-10-19 17:46:50 +00:00
parent 2824e302ba
commit 4d43c8a121
2 changed files with 32 additions and 0 deletions

View File

@ -199,6 +199,21 @@ public:
return (_size == 0);
}
bool operator==(const Array<T> &other) const {
if (this == &other)
return true;
if (_size != other._size)
return false;
for (uint i = 0; i < _size; ++i) {
if (_storage[i] != other._storage[i])
return false;
}
return true;
}
bool operator!=(const Array<T> &other) const {
return !(*this == other);
}
iterator begin() {
return _storage;

View File

@ -164,6 +164,23 @@ class ArrayTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(array2.size(), (unsigned int)3);
}
void test_equals() {
Common::Array<int> array1;
// Some data for both
array1.push_back(-3);
array1.push_back(5);
array1.push_back(9);
Common::Array<int> array2(array1);
TS_ASSERT(array1 == array2);
array1.push_back(42);
TS_ASSERT(array1 != array2);
array2.push_back(42);
TS_ASSERT(array1 == array2);
}
void test_array_constructor() {
const int array1[] = { -3, 5, 9 };