Add tests for kernel expression
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
c32dfe22b6
commit
c4cd6c4f84
3 changed files with 55 additions and 2 deletions
|
@ -29,7 +29,7 @@ expr_var::expr_var(unsigned idx):
|
|||
m_vidx(idx) {}
|
||||
|
||||
expr_const::expr_const(name const & n, unsigned pos):
|
||||
expr_cell(expr_kind::Constant, m_name.hash()),
|
||||
expr_cell(expr_kind::Constant, n.hash()),
|
||||
m_name(n),
|
||||
m_pos(pos) {}
|
||||
|
||||
|
@ -44,7 +44,7 @@ expr_app::~expr_app() {
|
|||
expr app(unsigned num_args, expr const * args) {
|
||||
lean_assert(num_args > 1);
|
||||
unsigned _num_args;
|
||||
unsigned _num_args0;
|
||||
unsigned _num_args0 = 0;
|
||||
expr const & arg0 = args[0];
|
||||
// Remark: we represet ((app a b) c) as (app a b c)
|
||||
if (is_app(arg0)) {
|
||||
|
|
3
src/tests/kernel/CMakeLists.txt
Normal file
3
src/tests/kernel/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
add_executable(expr_tst expr.cpp)
|
||||
target_link_libraries(expr_tst ${EXTRA_LIBS})
|
||||
add_test(expr ${CMAKE_CURRENT_BINARY_DIR}/expr_tst)
|
50
src/tests/kernel/expr.cpp
Normal file
50
src/tests/kernel/expr.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
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 "expr.h"
|
||||
#include "test.h"
|
||||
using namespace lean;
|
||||
|
||||
static void tst1() {
|
||||
expr a;
|
||||
a = numeral(mpz(10));
|
||||
expr f;
|
||||
f = var(0);
|
||||
expr fa = app({f, a});
|
||||
std::cout << fa << "\n";
|
||||
std::cout << app({fa, a}) << "\n";
|
||||
lean_assert(eqp(get_arg(fa, 0), f));
|
||||
lean_assert(eqp(get_arg(fa, 1), a));
|
||||
lean_assert(!eqp(fa, app({f, a})));
|
||||
lean_assert(app({fa, a}) == app({f, a, a}));
|
||||
std::cout << app({fa, fa, fa}) << "\n";
|
||||
std::cout << lambda(name("x"), prop(), var(0)) << "\n";
|
||||
}
|
||||
|
||||
expr mk_dag(unsigned depth) {
|
||||
expr f = constant(name("f"));
|
||||
expr a = var(0);
|
||||
while (depth > 0) {
|
||||
depth--;
|
||||
a = app({f, a, a});
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
static void tst2() {
|
||||
expr r1 = mk_dag(24);
|
||||
expr r2 = mk_dag(24);
|
||||
lean_verify(r1 == r2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// continue_on_violation(true);
|
||||
std::cout << "sizeof(expr): " << sizeof(expr) << "\n";
|
||||
std::cout << "sizeof(expr_app): " << sizeof(expr_app) << "\n";
|
||||
tst1();
|
||||
tst2();
|
||||
return has_violations() ? 1 : 0;
|
||||
}
|
Loading…
Reference in a new issue