@@ -168,6 +168,21 @@ public: | |||||
Remove(m_count - 1, 1); | Remove(m_count - 1, 1); | ||||
} | } | ||||
void Swap(int pos1, int pos2) | |||||
{ | |||||
ASSERT(pos1 >= 0); | |||||
ASSERT(pos2 >= 0); | |||||
ASSERT(pos1 < m_count); | |||||
ASSERT(pos2 < m_count); | |||||
if (pos1 != pos2) | |||||
{ | |||||
Element tmp = (*this)[pos1]; | |||||
(*this)[pos1] = (*this)[pos2]; | |||||
(*this)[pos2] = tmp; | |||||
} | |||||
} | |||||
void Remove(int pos, int todelete = 1) | void Remove(int pos, int todelete = 1) | ||||
{ | { | ||||
ASSERT(pos >= 0); | ASSERT(pos >= 0); | ||||
@@ -100,6 +100,19 @@ LOLUNIT_FIXTURE(ArrayTest) | |||||
LOLUNIT_ASSERT_EQUAL(a[0].m8, 0); | LOLUNIT_ASSERT_EQUAL(a[0].m8, 0); | ||||
} | } | ||||
LOLUNIT_TEST(ArraySwap) | |||||
{ | |||||
Array<int, int> a; | |||||
a.Push(10, 20); | |||||
a.Push(30, 40); | |||||
a.Swap(0, 1); | |||||
LOLUNIT_ASSERT_EQUAL(30, a[0].m1); | |||||
LOLUNIT_ASSERT_EQUAL(40, a[0].m2); | |||||
LOLUNIT_ASSERT_EQUAL(10, a[1].m1); | |||||
LOLUNIT_ASSERT_EQUAL(20, a[1].m2); | |||||
} | |||||
LOLUNIT_TEST(ArrayConcat) | LOLUNIT_TEST(ArrayConcat) | ||||
{ | { | ||||
Array<int> a, b; | Array<int> a, b; | ||||