// Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 mod common; use bee_ternary::{raw::*, *}; use common::{gen_buf_balanced, gen_buf_unbalanced}; use serde::{de::DeserializeOwned, *}; fn serialize_generic() where ::Trit: Serialize, { let (a, a_i8) = gen_buf_balanced::(0..1000); assert_eq!( serde_json::to_string(&a).unwrap(), format!("[{}]", a_i8.iter().map(|t| t.to_string()).collect::>().join(",")), ); } fn serialize_generic_unbalanced() where ::Trit: Serialize, { let (a, a_i8) = gen_buf_unbalanced::(0..1000); assert_eq!( serde_json::to_string(&a).unwrap(), format!("[{}]", a_i8.iter().map(|t| t.to_string()).collect::>().join(",")), ); } fn deserialize_generic() where ::Trit: DeserializeOwned, { let (a, a_i8) = gen_buf_balanced::(0..1000); assert_eq!( serde_json::from_str::>(&format!( "[{}]", a_i8.iter().map(|t| t.to_string()).collect::>().join(",") )) .unwrap(), a, ); } fn deserialize_generic_unbalanced() where ::Trit: DeserializeOwned, { let (a, a_i8) = gen_buf_unbalanced::(0..1000); assert_eq!( serde_json::from_str::>(&format!( "[{}]", a_i8.iter().map(|t| t.to_string()).collect::>().join(",") )) .unwrap(), a, ); } #[test] fn serialize() { serialize_generic::>(); serialize_generic_unbalanced::>(); serialize_generic::(); serialize_generic::(); serialize_generic::(); serialize_generic::(); } #[test] fn deserialize() { deserialize_generic::>(); deserialize_generic_unbalanced::>(); deserialize_generic::(); deserialize_generic::(); deserialize_generic::(); deserialize_generic::(); }