Skip to content

Commit

Permalink
test constants
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Dec 20, 2024
1 parent b556b1b commit a117dc6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions hugr-core/src/ops/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,16 +768,29 @@ pub(crate) mod test {
}

#[fixture]
fn const_array_2_bool() -> Value {
fn const_array_bool() -> Value {
ArrayValue::new(bool_t(), [Value::true_val(), Value::false_val()]).into()
}

#[fixture]
fn const_array_options() -> Value {
let some_true = Value::some([Value::true_val()]);
let none = Value::none(vec![bool_t()]);
let elem_ty = SumType::new_option(vec![bool_t()]);
ArrayValue::new(elem_ty.into(), [some_true, none]).into()
}

#[rstest]
#[case(Value::unit(), Type::UNIT, "const:seq:{}")]
#[case(const_usize(), usize_t(), "const:custom:ConstUsize(")]
#[case(serialized_float(17.4), float64_type(), "const:custom:json:Object")]
#[case(const_tuple(), Type::new_tuple(vec![usize_t(), bool_t()]), "const:seq:{")]
#[case(const_array_2_bool(), array_type(2, bool_t()), "const:custom:array")]
#[case(const_array_bool(), array_type(2, bool_t()), "const:custom:array")]
#[case(
const_array_options(),
array_type(2, SumType::new_option(vec![bool_t()]).into()),
"const:custom:array"
)]
fn const_type(
#[case] const_value: Value,
#[case] expected_type: Type,
Expand All @@ -796,7 +809,8 @@ pub(crate) mod test {
#[case(const_usize(), const_usize())]
#[case(const_serialized_usize(), const_usize())]
#[case(const_tuple_serialized(), const_tuple())]
#[case(const_array_2_bool(), const_array_2_bool())]
#[case(const_array_bool(), const_array_bool())]
#[case(const_array_options(), const_array_options())]
fn const_serde_roundtrip(#[case] const_value: Value, #[case] expected_value: Value) {
let serialized = serde_json::to_string(&const_value).unwrap();
let deserialized: Value = serde_json::from_str(&serialized).unwrap();
Expand Down

0 comments on commit a117dc6

Please sign in to comment.