2013-07-29 05:34:39 +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 <locale>
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/test.h"
|
|
|
|
#include "util/exception.h"
|
|
|
|
#include "kernel/environment.h"
|
|
|
|
#include "library/printer.h"
|
2013-07-29 05:34:39 +00:00
|
|
|
using namespace lean;
|
|
|
|
|
2013-08-17 18:29:43 +00:00
|
|
|
static void tst0() {
|
|
|
|
environment env;
|
|
|
|
lean_assert(env.begin_objects() == env.end_objects());
|
|
|
|
std::for_each(env.begin_objects(), env.end_objects(), [&](object const & obj) {
|
|
|
|
std::cout << obj.keyword() << "\n";
|
|
|
|
});
|
|
|
|
level l1 = env.add_uvar(name(name("l1"), "suffix"), level());
|
|
|
|
lean_assert(env.begin_objects() != env.end_objects());
|
|
|
|
std::for_each(env.begin_objects(), env.end_objects(), [&](object const & obj) {
|
|
|
|
std::cout << obj.keyword() << "\n";
|
|
|
|
});
|
|
|
|
std::cout << env;
|
|
|
|
}
|
|
|
|
|
2013-07-29 05:34:39 +00:00
|
|
|
static void tst1() {
|
|
|
|
environment env;
|
2013-08-09 22:33:34 +00:00
|
|
|
level l1 = env.add_uvar(name(name("l1"), "suffix"), level());
|
|
|
|
level l2 = env.add_uvar("l2", l1 + 10);
|
|
|
|
level l3 = env.add_uvar("l3", max(l2, l1 + 3));
|
|
|
|
level l4 = env.add_uvar("l4", max(l1 + 8, max(l2 + 2, l3 + 20)));
|
2013-08-08 02:10:12 +00:00
|
|
|
std::cout << pp(max(l1 + 8, max(l2 + 2, l3 + 20))) << "\n";
|
|
|
|
std::cout << pp(level()) << "\n";
|
|
|
|
std::cout << pp(level()+1) << "\n";
|
2013-08-16 22:09:26 +00:00
|
|
|
std::cout << env;
|
2013-07-30 02:05:43 +00:00
|
|
|
lean_assert(env.is_ge(l4 + 10, l3 + 30));
|
|
|
|
lean_assert(!env.is_ge(l4 + 9, l3 + 30));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tst2() {
|
|
|
|
environment env;
|
2013-08-09 22:33:34 +00:00
|
|
|
level l1 = env.add_uvar("l1", level());
|
2013-07-30 02:05:43 +00:00
|
|
|
try {
|
2013-08-09 22:33:34 +00:00
|
|
|
level l2 = env.add_uvar("l1", level());
|
2013-07-30 02:05:43 +00:00
|
|
|
lean_unreachable();
|
|
|
|
}
|
|
|
|
catch (exception ex) {
|
|
|
|
std::cout << "ok\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tst3() {
|
|
|
|
environment env;
|
2013-08-09 22:33:34 +00:00
|
|
|
level l1 = env.add_uvar("l1", level());
|
|
|
|
level l2 = env.add_uvar("l2", l1 + ((1<<30) + 1024));
|
2013-07-30 02:05:43 +00:00
|
|
|
try {
|
2013-08-09 22:33:34 +00:00
|
|
|
level l3 = env.add_uvar("l3", l2 + (1<<30));
|
2013-07-30 02:05:43 +00:00
|
|
|
lean_unreachable();
|
|
|
|
}
|
|
|
|
catch (exception ex) {
|
|
|
|
std::cout << "ok\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tst4() {
|
|
|
|
environment env;
|
2013-08-09 22:33:34 +00:00
|
|
|
level l1 = env.add_uvar("l1", level() + 1);
|
|
|
|
level l2 = env.add_uvar("l2", level() + 1);
|
|
|
|
level l3 = env.add_uvar("l3", max(l1, l2) + 1);
|
|
|
|
level l4 = env.add_uvar("l4", l3 + 1);
|
|
|
|
level l5 = env.add_uvar("l5", l3 + 1);
|
|
|
|
level l6 = env.add_uvar("l6", max(l4, l5) + 1);
|
2013-07-30 02:05:43 +00:00
|
|
|
lean_assert(!env.is_ge(l5 + 1, l6));
|
|
|
|
lean_assert(env.is_ge(l6, l5));
|
|
|
|
lean_assert(env.is_ge(l6, max({l1, l2, l3, l4, l5})));
|
|
|
|
lean_assert(env.is_ge(l6, l6));
|
|
|
|
lean_assert(!env.is_ge(l5, l4));
|
|
|
|
lean_assert(env.is_ge(max({l1, l2, l4, l5}), max({l1, l2, l3, l4, l5})));
|
|
|
|
lean_assert(env.is_ge(max({l4, l5}), max({l1, l2, l3})));
|
|
|
|
lean_assert(!env.is_ge(max({l1, l2, l5}), max({l1, l2, l3, l4, l5})));
|
|
|
|
lean_assert(!env.is_ge(max({l2, l4}), max({l1, l2, l3, l4, l5})));
|
|
|
|
lean_assert(env.is_ge(max(l2, l3) + 1, max(l1, l1+1)));
|
|
|
|
lean_assert(env.is_ge(max(l2, l3) + 1, max(l1+2, l1+1)));
|
|
|
|
lean_assert(env.is_ge(max(l2, l3) + 1, max(l2+2, l1+1)));
|
|
|
|
lean_assert(!env.is_ge(max(l4, l5) + 1, max(l2+4, l1+1)));
|
|
|
|
lean_assert(!env.is_ge(max(l6, l5), max(l2+4, l1+1)));
|
|
|
|
lean_assert(env.is_ge(max(l6, l5), max(l2+3, l1+1)));
|
|
|
|
lean_assert(!env.is_ge(max(l6, l5), max(l2, l1+1)+3));
|
|
|
|
lean_assert(env.is_ge(max(l6+1, l5), max(l2, l1+1)+3));
|
2013-08-16 22:09:26 +00:00
|
|
|
std::cout << env;
|
2013-07-29 05:34:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 01:52:28 +00:00
|
|
|
static void tst5() {
|
|
|
|
environment env;
|
2013-08-09 22:33:34 +00:00
|
|
|
level l1 = env.add_uvar("l1", level() + 1);
|
|
|
|
level l2 = env.add_uvar("l2", level() + 1);
|
2013-08-02 01:52:28 +00:00
|
|
|
std::cout << max(l1, l1) << "\n";
|
|
|
|
lean_assert(max(l1, l1) == l1);
|
|
|
|
lean_assert(max(l1+1, l1+1) == l1+1);
|
|
|
|
std::cout << max(l1, l1+1) << "\n";
|
|
|
|
std::cout << max(l2, max(l1, l1+1)) << "\n";
|
|
|
|
lean_assert(max(l1, l1+1) == l1+1);
|
|
|
|
lean_assert(max(l2, max(l1, l1+1)) == max(l2, l1+1));
|
|
|
|
std::cout << max(l1, max(l2, l1+1)) << "\n";
|
|
|
|
lean_assert(max(l1, max(l2, l1+1)) == max(l1+1, l2));
|
|
|
|
}
|
|
|
|
|
2013-07-29 05:34:39 +00:00
|
|
|
int main() {
|
2013-08-17 18:29:43 +00:00
|
|
|
tst0();
|
2013-07-29 05:34:39 +00:00
|
|
|
tst1();
|
2013-07-30 02:05:43 +00:00
|
|
|
tst2();
|
|
|
|
tst3();
|
|
|
|
tst4();
|
2013-08-02 01:52:28 +00:00
|
|
|
tst5();
|
2013-07-29 05:34:39 +00:00
|
|
|
return has_violations() ? 1 : 0;
|
|
|
|
}
|