Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-q committed May 2, 2024
1 parent 855f1bb commit 6257a90
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 65 deletions.
10 changes: 5 additions & 5 deletions hugr/src/extension/op_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
67 changes: 31 additions & 36 deletions hugr/src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = {
use proptest::string::string_regex;
Expand All @@ -386,48 +381,48 @@ pub(crate) mod test {
].sboxed()
};

static ref ANY_SERDE_YAML_VALUE: SBoxedStrategy<serde_yaml::Value> = {
use serde_yaml::value::{Tag, TaggedValue, Value};
proptest::collection::vec;
prop_oneof![
Just(Value::Null),
any::<bool>().prop_map_into(),
any::<u64>().prop_map_into(),
any::<i64>().prop_map_into(),
any::<f64>().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<serde_yaml::Value> = {
// use serde_yaml::value::{Tag, TaggedValue, Value};
// proptest::collection::vec;
// prop_oneof![
// Just(Value::Null),
// any::<bool>().prop_map_into(),
// any::<u64>().prop_map_into(),
// any::<i64>().prop_map_into(),
// any::<f64>().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<Value = String> + Sync {
pub fn any_nonempty_string() -> SBoxedStrategy<String> {
ANY_NONEMPTY_STRING.clone()
}

pub fn any_nonempty_smolstr() -> impl Strategy<Value = SmolStr> + Sync {
ANY_NONEMPTY_STRING.clone().prop_map_into()
pub fn any_nonempty_smolstr() -> SBoxedStrategy<SmolStr> {
ANY_NONEMPTY_STRING.clone().prop_map_into().sboxed()
}

pub fn any_ident_string() -> impl Strategy<Value = String> + Sync {
pub fn any_ident_string() -> SBoxedStrategy<String> {
ANY_IDENT_STRING.clone()
}

pub fn any_string() -> impl Strategy<Value = String> + Sync {
ANY_STRING.clone()
}
// pub fn any_string() -> SBoxedStrategy<String> {
// ANY_STRING.clone()
// }

pub fn any_serde_yaml_value() -> impl Strategy<Value = serde_yaml::Value> {
ANY_SERDE_YAML_VALUE.clone()
}
// pub fn any_serde_yaml_value() -> SBoxedStrategy<serde_yaml::Value> {
// ANY_SERDE_YAML_VALUE.clone()
// }
}

#[test]
Expand Down
19 changes: 0 additions & 19 deletions hugr/src/hugr/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,6 @@ struct SerTestingV1 {
optype: Option<NodeSer>,
}

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]
Expand Down
27 changes: 23 additions & 4 deletions hugr/src/hugr/serialize/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
}
}
1 change: 1 addition & 0 deletions hugr/src/ops/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion hugr/src/types/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mod test {

use crate::{
extension::ExtensionId,
types::{TypeArg, TypeBound, TypeName},
types::{TypeArg, TypeBound},
};

lazy_static! {
Expand Down

0 comments on commit 6257a90

Please sign in to comment.