Explorar el Código

base: add Array::Swap() method and the corresponding unit test.

legacy
Sam Hocevar sam hace 11 años
padre
commit
5ea012c192
Se han modificado 2 ficheros con 28 adiciones y 0 borrados
  1. +15
    -0
      src/lol/base/array.h
  2. +13
    -0
      test/unit/array.cpp

+ 15
- 0
src/lol/base/array.h Ver fichero

@@ -168,6 +168,21 @@ public:
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)
{
ASSERT(pos >= 0);


+ 13
- 0
test/unit/array.cpp Ver fichero

@@ -100,6 +100,19 @@ LOLUNIT_FIXTURE(ArrayTest)
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)
{
Array<int> a, b;


Cargando…
Cancelar
Guardar