Skip to content

Commit

Permalink
add tests for self-evaluating expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino committed Nov 1, 2023
1 parent 062a427 commit a423ace
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 26 deletions.
52 changes: 37 additions & 15 deletions src/lem/tests/eval_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,45 @@ fn do_test<C: Coprocessor<Fr>>(
}

#[test]
fn simple_evaluation() {
fn self_evaluating() {
let s = &Store::<Fr>::default();
let expr_num = "999";
let expt_num = Ptr::num_u64(999);

let expr = "999";
let expected = Ptr::num_u64(999);
test_aux::<Coproc<Fr>>(s, expr, Some(expected), None, None, None, 1, &None);
let expr_u64 = "999u64";
let expt_u64 = Ptr::u64(999);

let expr_char = "'a'";
let expt_char = Ptr::char('a');

let expr_str = "\"abc\"";
let expt_str = s.intern_string("abc");

let expr_nil = "nil";
let expt_nil = s.intern_nil();

let expr_t = "t";
let expt_t = s.intern_lurk_symbol("t");

let expr_key = ":key";
let expt_key = s.key("key");

[
(expr_num, expt_num),
(expr_u64, expt_u64),
(expr_char, expt_char),
(expr_str, expt_str),
(expr_nil, expt_nil),
(expr_t, expt_t),
(expr_key, expt_key),
]
.into_iter()
.for_each(|(expr, expt)| {
test_aux::<Coproc<Fr>>(s, expr, Some(expt), None, None, None, 1, &None);
});

let fun = s.intern_fun(s.intern_user_symbol("x"), s.list(vec![expt_nil]), expt_nil);
do_test_aux::<Coproc<Fr>>(s, &fun, Some(fun), None, None, None, 1, &None);
}

#[test]
Expand Down Expand Up @@ -2282,17 +2315,6 @@ fn test_eval_env_regression() {
test_aux::<Coproc<Fr>>(s, expr2, Some(res), None, Some(terminal), None, 6, &None);
}

#[test]
fn test_u64_self_evaluating() {
let s = &Store::<Fr>::default();

let expr = "123u64";
let res = Ptr::u64(123);
let terminal = s.cont_terminal();

test_aux::<Coproc<Fr>>(s, expr, Some(res), None, Some(terminal), None, 1, &None);
}

#[test]
fn test_u64_mul() {
let s = &Store::<Fr>::default();
Expand Down
65 changes: 54 additions & 11 deletions src/proof/tests/nova_tests_lem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,60 @@ use super::{nova_test_full_aux, nova_test_full_aux2, test_aux, DEFAULT_REDUCTION

type M1<'a, Fr> = C1LEM<'a, Fr, Coproc<Fr>>;

#[test]
fn test_prove_self_evaluating() {
let s = &Store::<Fr>::default();
let expr_num = "999";
let expt_num = Ptr::num_u64(999);

let expr_u64 = "999u64";
let expt_u64 = Ptr::u64(999);

let expr_char = "'a'";
let expt_char = Ptr::char('a');

let expr_str = "\"abc\"";
let expt_str = s.intern_string("abc");

let expr_nil = "nil";
let expt_nil = s.intern_nil();

let expr_t = "t";
let expt_t = s.intern_lurk_symbol("t");

let expr_key = ":key";
let expt_key = s.key("key");

[
(expr_num, expt_num),
(expr_u64, expt_u64),
(expr_char, expt_char),
(expr_str, expt_str),
(expr_nil, expt_nil),
(expr_t, expt_t),
(expr_key, expt_key),
]
.into_iter()
.for_each(|(expr, expt)| {
test_aux::<_, _, M1<'_, _>>(s, expr, Some(expt), None, None, None, 1, &None);
});

let fun = s.intern_fun(s.intern_user_symbol("x"), s.list(vec![expt_nil]), expt_nil);
nova_test_full_aux2::<_, _, M1<'_, _>>(
s,
fun,
Some(fun),
None,
None,
None,
1,
DEFAULT_REDUCTION_COUNT,
false,
None,
Lang::new().into(),
);
}

#[test]
fn test_prove_binop() {
let s = &Store::<Fr>::default();
Expand Down Expand Up @@ -2837,17 +2891,6 @@ fn test_prove_test_eval_bad_form() {
test_aux::<_, _, M1<'_, _>>(s, expr, None, None, Some(error), None, 8, &None);
}

#[test]
fn test_prove_test_u64_self_evaluating() {
let s = &Store::<Fr>::default();

let expr = "123u64";
let res = Ptr::u64(123);
let terminal = s.cont_terminal();

test_aux::<_, _, M1<'_, _>>(s, expr, Some(res), None, Some(terminal), None, 1, &None);
}

#[test]
fn test_prove_test_u64_mul() {
let s = &Store::<Fr>::default();
Expand Down

0 comments on commit a423ace

Please sign in to comment.