diff --git a/hugr/src/extension/op_def.rs b/hugr/src/extension/op_def.rs index 7e2b95cb5..1b605b86f 100644 --- a/hugr/src/extension/op_def.rs +++ b/hugr/src/extension/op_def.rs @@ -465,17 +465,17 @@ impl Extension { #[cfg(test)] mod test { - use proptest::prelude::*; - use std::collections::{HashMap, HashSet}; + + use std::num::NonZeroU64; - use smol_str::SmolStr; + - use super::{OpDef, SignatureFromArgs}; + use super::{SignatureFromArgs}; use crate::builder::{DFGBuilder, Dataflow, DataflowHugr}; use crate::extension::op_def::LowerFunc; use crate::extension::prelude::USIZE_T; - use crate::extension::{ExtensionId, ExtensionRegistry, ExtensionSet, SignatureFunc, PRELUDE}; + use crate::extension::{ExtensionRegistry, ExtensionSet, PRELUDE}; use crate::extension::{SignatureError, EMPTY_REG, PRELUDE_REGISTRY}; use crate::ops::{CustomOp, OpName}; use crate::std_extensions::collections::{EXTENSION, LIST_TYPENAME}; diff --git a/hugr/src/hugr.rs b/hugr/src/hugr.rs index 65e57ed79..8b9829fbc 100644 --- a/hugr/src/hugr.rs +++ b/hugr/src/hugr.rs @@ -356,11 +356,6 @@ pub(crate) mod test { use proptest::prelude::*; use smol_str::SmolStr; - pub enum ArbStringKind { - NonEmpty, - Ident, - } - lazy_static! { static ref ANY_IDENT_STRING: SBoxedStrategy = { use proptest::string::string_regex; @@ -386,48 +381,48 @@ pub(crate) mod test { ].sboxed() }; - static ref ANY_SERDE_YAML_VALUE: SBoxedStrategy = { - use serde_yaml::value::{Tag, TaggedValue, Value}; - proptest::collection::vec; - prop_oneof![ - Just(Value::Null), - any::().prop_map_into(), - any::().prop_map_into(), - any::().prop_map_into(), - any::().prop_map_into(), - Just(Value::Number(3.into())), - ANY_STRING.clone().prop_map_into(), - ].prop_recursive( - 3, // No more than 3 branch levels deep - 32, // Target around 32 total elements - 3, // Each collection is up to 3 elements long - |element| prop_oneof![ - (ANY_STRING.clone().prop_map(Tag::new), element.clone()).prop_map(|(tag, value)| Value::Tagged(Box::new(TaggedValue { tag, value }))), - proptest::collection::vec(element.clone(), 0..3).prop_map_into(), - ] - ).sboxed() - }; + // static ref ANY_SERDE_YAML_VALUE: SBoxedStrategy = { + // use serde_yaml::value::{Tag, TaggedValue, Value}; + // proptest::collection::vec; + // prop_oneof![ + // Just(Value::Null), + // any::().prop_map_into(), + // any::().prop_map_into(), + // any::().prop_map_into(), + // any::().prop_map_into(), + // Just(Value::Number(3.into())), + // any_string().prop_map_into(), + // ].sboxed().prop_recursive( + // 3, // No more than 3 branch levels deep + // 32, // Target around 32 total elements + // 3, // Each collection is up to 3 elements long + // |element| prop_oneof![ + // (any_string().prop_map(Tag::new), element.clone()).prop_map(|(tag, value)| Value::Tagged(Box::new(TaggedValue { tag, value }))), + // proptest::collection::vec(element.clone(), 0..3).prop_map_into(), + // ] + // ).sboxed() + // }; } - pub fn any_nonempty_string() -> impl Strategy + Sync { + pub fn any_nonempty_string() -> SBoxedStrategy { ANY_NONEMPTY_STRING.clone() } - pub fn any_nonempty_smolstr() -> impl Strategy + Sync { - ANY_NONEMPTY_STRING.clone().prop_map_into() + pub fn any_nonempty_smolstr() -> SBoxedStrategy { + ANY_NONEMPTY_STRING.clone().prop_map_into().sboxed() } - pub fn any_ident_string() -> impl Strategy + Sync { + pub fn any_ident_string() -> SBoxedStrategy { ANY_IDENT_STRING.clone() } - pub fn any_string() -> impl Strategy + Sync { - ANY_STRING.clone() - } + // pub fn any_string() -> SBoxedStrategy { + // ANY_STRING.clone() + // } - pub fn any_serde_yaml_value() -> impl Strategy { - ANY_SERDE_YAML_VALUE.clone() - } + // pub fn any_serde_yaml_value() -> SBoxedStrategy { + // ANY_SERDE_YAML_VALUE.clone() + // } } #[test] diff --git a/hugr/src/hugr/serialize.rs b/hugr/src/hugr/serialize.rs index 89f76b043..e75651bcb 100644 --- a/hugr/src/hugr/serialize.rs +++ b/hugr/src/hugr/serialize.rs @@ -82,25 +82,6 @@ struct SerTestingV1 { optype: Option, } -macro_rules! impl_sertesting_from { - ($typ:ty, $field:ident) => { - #[cfg(test)] - impl From<$typ> for SerTestingV1 { - fn from(v: $typ) -> Self { - let mut r: Self = Default::default(); - r.$field = Some(v); - r - } - } - }; -} - -impl_sertesting_from!(crate::types::Type, typ); -impl_sertesting_from!(crate::types::SumType, sum_type); -impl_sertesting_from!(crate::types::PolyFuncType, poly_func_type); -impl_sertesting_from!(crate::ops::Value, value); -impl_sertesting_from!(NodeSer, optype); - /// Errors that can occur while serializing a HUGR. #[derive(Debug, Clone, PartialEq, Error)] #[non_exhaustive] diff --git a/hugr/src/hugr/serialize/test.rs b/hugr/src/hugr/serialize/test.rs index c6d0897ca..94be5928b 100644 --- a/hugr/src/hugr/serialize/test.rs +++ b/hugr/src/hugr/serialize/test.rs @@ -3,13 +3,13 @@ use crate::builder::{ test::closed_dfg_root_hugr, Container, DFGBuilder, Dataflow, DataflowHugr, DataflowSubContainer, HugrBuilder, ModuleBuilder, }; -use crate::extension::prelude::{BOOL_T, PRELUDE_ID, QB_T, USIZE_T}; +use crate::extension::prelude::{BOOL_T, USIZE_T}; use crate::extension::simple_op::MakeRegisteredOp; use crate::extension::{EMPTY_REG, PRELUDE_REGISTRY}; use crate::hugr::hugrmut::sealed::HugrMutInternals; use crate::hugr::NodeType; use crate::ops::custom::{ExtensionOp, OpaqueOp}; -use crate::ops::{self, Value}; +use crate::ops::{Value}; use crate::ops::{dataflow::IOTrait, Input, Module, Noop, Output, DFG}; use crate::std_extensions::arithmetic::float_ops::FLOAT_OPS_REGISTRY; use crate::std_extensions::arithmetic::float_types::{ConstF64, FLOAT64_TYPE}; @@ -64,6 +64,25 @@ include_schema!( "../../../../specification/schema/testing_hugr_schema_strict_v1.json" ); +macro_rules! impl_sertesting_from { + ($typ:ty, $field:ident) => { + #[cfg(test)] + impl From<$typ> for TestingModel { + fn from(v: $typ) -> Self { + let mut r: Self = Default::default(); + r.$field = Some(v); + r + } + } + }; +} + +impl_sertesting_from!(crate::types::Type, typ); +impl_sertesting_from!(crate::types::SumType, sum_type); +impl_sertesting_from!(crate::types::PolyFuncType, poly_func_type); +impl_sertesting_from!(crate::ops::Value, value); +impl_sertesting_from!(NodeSer, optype); + #[test] fn empty_hugr_serialize() { let hg = Hugr::default(); @@ -357,11 +376,11 @@ proptest! { #[test] fn prop_roundtrip_poly_func_type(t: PolyFuncType) { - check_testing_roundtrip(t.into()) + check_testing_roundtrip(t) } #[test] fn prop_roundtrip_value(t: Value) { - check_testing_roundtrip(t.into()) + check_testing_roundtrip(t) } } diff --git a/hugr/src/ops/dataflow.rs b/hugr/src/ops/dataflow.rs index b90bb44ec..eacf664c3 100644 --- a/hugr/src/ops/dataflow.rs +++ b/hugr/src/ops/dataflow.rs @@ -323,6 +323,7 @@ impl LoadConstant { /// Load a static function in to the local dataflow graph. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[cfg_attr(test, derive(proptest_derive::Arbitrary))] pub struct LoadFunction { /// Signature of the function func_sig: PolyFuncType, diff --git a/hugr/src/types/custom.rs b/hugr/src/types/custom.rs index babfc0a34..d43614ded 100644 --- a/hugr/src/types/custom.rs +++ b/hugr/src/types/custom.rs @@ -145,7 +145,7 @@ mod test { use crate::{ extension::ExtensionId, - types::{TypeArg, TypeBound, TypeName}, + types::{TypeArg, TypeBound}, }; lazy_static! {