diff --git a/src/tests/library/CMakeLists.txt b/src/tests/library/CMakeLists.txt index 5295d8c5b..2e77de8b4 100644 --- a/src/tests/library/CMakeLists.txt +++ b/src/tests/library/CMakeLists.txt @@ -7,3 +7,6 @@ add_test(ho_unifier ${CMAKE_CURRENT_BINARY_DIR}/ho_unifier) add_executable(formatter formatter.cpp) target_link_libraries(formatter ${EXTRA_LIBS}) add_test(formatter ${CMAKE_CURRENT_BINARY_DIR}/formatter) +add_executable(max_sharing max_sharing.cpp) +target_link_libraries(max_sharing ${EXTRA_LIBS}) +add_test(max_sharing ${CMAKE_CURRENT_BINARY_DIR}/max_sharing) diff --git a/src/tests/library/max_sharing.cpp b/src/tests/library/max_sharing.cpp new file mode 100644 index 000000000..c0df46234 --- /dev/null +++ b/src/tests/library/max_sharing.cpp @@ -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 +#include "util/test.h" +#include "kernel/abstract.h" +#include "library/max_sharing.h" +#include "library/printer.h" +using namespace lean; + +static void tst1() { + max_sharing_fn max_fn; + expr a1 = Const("a"); + expr a2 = Const("a"); + expr F1 = Eq(a1, a2); + lean_assert(!is_eqp(eq_lhs(F1), eq_rhs(F1))); + expr F2 = max_fn(F1); + lean_assert(is_eqp(eq_lhs(F2), eq_rhs(F2))); + expr x = Const("x"); + expr y = Const("y"); + expr f = Const("f"); + expr N = Const("N"); + F1 = f(Fun({x, N}, f(x, x)), Fun({y, N}, f(y, y))); + lean_assert(!is_eqp(arg(F1, 1), arg(F1, 2))); + F2 = max_fn(F1); + std::cout << F2 << "\n"; + lean_assert(is_eqp(arg(F2, 1), arg(F2, 2))); + max_fn.clear(); + meta_ctx ctx{mk_lift(1, 1), mk_inst(0, a1)}; + expr m1 = mk_metavar(0, ctx); + expr m2 = mk_metavar(0, ctx); + F1 = f(m1, m2); + lean_assert(!is_eqp(arg(F1, 1), arg(F1, 2))); + F2 = max_fn(F1); + std::cout << F2 << "\n"; + lean_assert(is_eqp(arg(F2, 1), arg(F2, 2))); + F1 = f(Let({x, f(a1)}, f(x, x)), Let({y, f(a1)}, f(y, y))); + lean_assert(!is_eqp(arg(F1, 1), arg(F1, 2))); + F2 = max_fn(F1); + std::cout << F2 << "\n"; + lean_assert(is_eqp(arg(F2, 1), arg(F2, 2))); +} + +int main() { + tst1(); + return has_violations() ? 1 : 0; +}