diff options
author | Max Horn | 2009-10-19 17:46:50 +0000 |
---|---|---|
committer | Max Horn | 2009-10-19 17:46:50 +0000 |
commit | 4d43c8a121d40a1e66640e0d137a7808dca4b0f1 (patch) | |
tree | bf0c8edd0b843cef63613c7109d9b5881bd05cbe | |
parent | 2824e302baa6f69a0b40c4679e8b5bde30f8202f (diff) | |
download | scummvm-rg350-4d43c8a121d40a1e66640e0d137a7808dca4b0f1.tar.gz scummvm-rg350-4d43c8a121d40a1e66640e0d137a7808dca4b0f1.tar.bz2 scummvm-rg350-4d43c8a121d40a1e66640e0d137a7808dca4b0f1.zip |
Added operator== and != to Common::Array
svn-id: r45247
-rw-r--r-- | common/array.h | 15 | ||||
-rw-r--r-- | test/common/array.h | 17 |
2 files changed, 32 insertions, 0 deletions
diff --git a/common/array.h b/common/array.h index 0b5a65e9bd..4cc5369f9f 100644 --- a/common/array.h +++ b/common/array.h @@ -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; diff --git a/test/common/array.h b/test/common/array.h index bce4e8cba1..5ab6b73ef1 100644 --- a/test/common/array.h +++ b/test/common/array.h @@ -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 }; |