Parcourir la source

map: adding test for random failure with add/remove updates

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> il y a 9 ans
Parent
révision
73c3d8d524
1 fichiers modifiés avec 46 ajouts et 0 suppressions
  1. +46
    -0
      src/t/base/map.cpp

+ 46
- 0
src/t/base/map.cpp Voir le fichier

@@ -109,6 +109,52 @@ lolunit_declare_fixture(MapTest)
lolunit_assert_equal(m[8], 8);
}

lolunit_declare_test(MapRandomAddRemove)
{
map<unsigned char, unsigned char> m;

unsigned char a = 1, b = 1, c = 1;

char presence[256];
char value[256];

for (int i = 0 ; i < 256 ; ++i)
{
presence[i] = 0;
}

for (int i = 0 ; i < 10000 ; ++i)
{
m[a] = b;
m.remove(b);

presence[a] = 1;
value[a] = b;
presence[b] = 0;

a = a * b + c;
b = b * c + a;
c = c * a + b;

// debug output
// std::cout << "a " << (int)a << ", b " << (int)b << std::endl;

for (int j = 0 ; j < 256 ; ++j)
{
unsigned char v;
if (presence[j])
{
lolunit_assert(m.try_get(j, v));
lolunit_assert_equal((int) value[j], (int) v);
}
else
{
lolunit_assert(!m.try_get(j, v));
}
}
}
}

lolunit_declare_test(StringMap)
{
map<char const *, int> m;


Chargement…
Annuler
Enregistrer