chore: fill in cost model

test: Add case and constr eval tests
This commit is contained in:
microproofs 2023-09-01 22:31:40 -04:00 committed by Kasey
parent 85901dc141
commit c9b01ab365
2 changed files with 71 additions and 8 deletions

View File

@ -480,4 +480,67 @@ mod tests {
); );
} }
} }
#[test]
fn case_constr_case_0() {
let make_program =
|fun: DefaultFunction, tag: usize, n: i32, m: i32| Program::<NamedDeBruijn> {
version: (0, 0, 0),
term: Term::Case {
constr: Term::Constr {
tag,
fields: vec![
Term::Constant(Constant::Integer(n.into()).into()),
Term::Constant(Constant::Integer(m.into()).into()),
],
}
.into(),
branches: vec![Term::Builtin(fun), Term::sub_integer()],
},
};
let test_data = vec![
(DefaultFunction::AddInteger, 0, 8, 3, 11),
(DefaultFunction::AddInteger, 1, 8, 3, 5),
];
for (fun, tag, n, m, result) in test_data {
let eval_result = make_program(fun, tag, n, m).eval(ExBudget::default());
assert_eq!(
eval_result.result().unwrap(),
Term::Constant(Constant::Integer(result.into()).into())
);
}
}
#[test]
fn case_constr_case_1() {
let make_program = |tag: usize| Program::<NamedDeBruijn> {
version: (0, 0, 0),
term: Term::Case {
constr: Term::Constr {
tag,
fields: vec![],
}
.into(),
branches: vec![
Term::integer(5.into()),
Term::integer(10.into()),
Term::integer(15.into()),
],
},
};
let test_data = vec![(0, 5), (1, 10), (2, 15)];
for (tag, result) in test_data {
let eval_result = make_program(tag).eval(ExBudget::default());
assert_eq!(
eval_result.result().unwrap(),
Term::Constant(Constant::Integer(result.into()).into())
);
}
}
} }

View File

@ -147,12 +147,12 @@ impl MachineCosts {
}, },
// Placeholder values // Placeholder values
constr: ExBudget { constr: ExBudget {
mem: 30000000000, mem: 100,
cpu: 30000000000, cpu: 23000,
}, },
case: ExBudget { case: ExBudget {
mem: 30000000000, mem: 100,
cpu: 30000000000, cpu: 23000,
}, },
} }
} }
@ -193,12 +193,12 @@ impl Default for MachineCosts {
}, },
// Placeholder values // Placeholder values
constr: ExBudget { constr: ExBudget {
mem: 30000000000, mem: 100,
cpu: 30000000000, cpu: 23000,
}, },
case: ExBudget { case: ExBudget {
mem: 30000000000, mem: 100,
cpu: 30000000000, cpu: 23000,
}, },
} }
} }