2013-08-11 02:27:56 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/test.h"
|
2013-09-26 03:13:05 +00:00
|
|
|
#include "util/scoped_map.h"
|
2013-08-11 02:27:56 +00:00
|
|
|
using namespace lean;
|
|
|
|
|
|
|
|
static void tst1() {
|
|
|
|
scoped_map<int, int> s;
|
|
|
|
lean_assert(s.empty());
|
|
|
|
lean_assert(s.size() == 0);
|
|
|
|
lean_assert(s.find(10) == s.end());
|
|
|
|
s.insert(10, 20);
|
|
|
|
lean_assert(!s.empty());
|
|
|
|
lean_assert(s.size() == 1);
|
|
|
|
lean_assert(s.find(10) != s.end());
|
|
|
|
lean_assert(s.find(10)->second == 20);
|
|
|
|
lean_assert(s.num_scopes() == 0);
|
|
|
|
lean_assert(s.at_base_lvl());
|
|
|
|
s.push();
|
|
|
|
lean_assert(s.num_scopes() == 1);
|
|
|
|
lean_assert(!s.at_base_lvl());
|
|
|
|
s.insert(20, 40);
|
|
|
|
lean_assert(s.find(20) != s.end());
|
|
|
|
lean_assert(s.find(30) == s.end());
|
|
|
|
s.insert(10, 30);
|
|
|
|
lean_assert(s.find(10)->second == 30);
|
|
|
|
lean_assert(s.size() == 2);
|
|
|
|
s.pop();
|
|
|
|
lean_assert(s.size() == 1);
|
|
|
|
lean_assert(s.find(10) != s.end());
|
|
|
|
lean_assert(s.find(10)->second == 20);
|
|
|
|
lean_assert(s.find(20) == s.end());
|
|
|
|
s.push();
|
|
|
|
s.insert(30, 50);
|
|
|
|
lean_assert(s.size() == 2);
|
|
|
|
s.erase(10);
|
|
|
|
lean_assert(s.size() == 1);
|
|
|
|
s.push();
|
|
|
|
lean_assert(s.num_scopes() == 2);
|
|
|
|
lean_assert(!s.at_base_lvl());
|
|
|
|
s.erase(10);
|
|
|
|
lean_assert(s.size() == 1);
|
|
|
|
s.pop();
|
|
|
|
lean_assert(s.num_scopes() == 1);
|
|
|
|
lean_assert(s.find(10) == s.end());
|
|
|
|
lean_assert(s.find(30) != s.end());
|
|
|
|
lean_assert(s.size() == 1);
|
|
|
|
s.pop();
|
|
|
|
lean_assert(s.size() == 1);
|
|
|
|
lean_assert(s.at_base_lvl());
|
|
|
|
lean_assert(s.find(10) != s.end());
|
|
|
|
lean_assert(s.find(30) == s.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
tst1();
|
|
|
|
return has_violations() ? 1 : 0;
|
|
|
|
}
|