2013-07-24 21:41:03 +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
|
|
|
|
*/
|
|
|
|
#include <vector>
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/test.h"
|
2013-09-26 03:13:05 +00:00
|
|
|
#include "util/buffer.h"
|
2013-07-24 21:41:03 +00:00
|
|
|
using namespace lean;
|
|
|
|
|
|
|
|
template<typename C>
|
|
|
|
static void loop(int n) {
|
|
|
|
C b;
|
|
|
|
b.push_back(n);
|
|
|
|
lean_assert(b.size() == 1);
|
|
|
|
lean_assert(b.back() == n);
|
|
|
|
lean_assert(b[0] == n);
|
|
|
|
if (n > 0)
|
|
|
|
loop<C>(n-1);
|
|
|
|
}
|
|
|
|
|
2013-09-26 15:31:31 +00:00
|
|
|
static void tst1() {
|
|
|
|
buffer<int> b1;
|
|
|
|
buffer<int> b2;
|
|
|
|
b1.push_back(10);
|
|
|
|
lean_assert(b1 != b2);
|
|
|
|
b2.push_back(20);
|
|
|
|
lean_assert(b1 != b2);
|
|
|
|
b2.pop_back();
|
|
|
|
b2.push_back(10);
|
|
|
|
lean_assert(b1 == b2);
|
|
|
|
b2.push_back(20);
|
|
|
|
b2.push_back(20);
|
|
|
|
lean_assert(b1 != b2);
|
|
|
|
b2.shrink(1);
|
|
|
|
lean_assert(b1 == b2);
|
|
|
|
b2.push_back(100);
|
|
|
|
lean_assert(b1 != b2);
|
|
|
|
b2 = b1;
|
|
|
|
lean_assert(b1 == b2);
|
|
|
|
buffer<int> b3(b1);
|
|
|
|
lean_assert(b3 == b1);
|
|
|
|
lean_assert(b1.back() == 10);
|
2013-07-24 21:41:03 +00:00
|
|
|
}
|
|
|
|
|
2013-09-29 23:58:31 +00:00
|
|
|
static void tst2() {
|
|
|
|
buffer<int> b1;
|
|
|
|
buffer<int> b2;
|
|
|
|
b1.push_back(1); b1.push_back(2); b1.push_back(3);
|
|
|
|
b2 = b1;
|
|
|
|
lean_assert(b1.size() == 3);
|
|
|
|
b2.resize(2);
|
|
|
|
lean_assert(b2.size() == 2);
|
|
|
|
b2.resize(10, 0);
|
|
|
|
lean_assert(b2.size() == 10);
|
|
|
|
b2.resize(1);
|
|
|
|
lean_assert(b2.size() == 1);
|
|
|
|
}
|
|
|
|
|
2013-07-24 21:41:03 +00:00
|
|
|
int main() {
|
|
|
|
loop<buffer<int>>(100);
|
2013-09-26 15:31:31 +00:00
|
|
|
tst1();
|
2013-09-29 23:58:31 +00:00
|
|
|
tst2();
|
2013-07-24 23:32:50 +00:00
|
|
|
return has_violations() ? 1 : 0;
|
2013-07-24 21:41:03 +00:00
|
|
|
}
|