@@ -25,6 +25,8 @@ use bitcoin_units::{
2525 amount, block, fee_rate, locktime, parse, weight, Amount , BlockHeight , BlockInterval , FeeRate ,
2626 SignedAmount , Weight ,
2727} ;
28+ #[ cfg( feature = "arbitrary" ) ]
29+ use arbitrary:: { Arbitrary , Unstructured } ;
2830
2931/// A struct that includes all public non-error enums.
3032#[ derive( Debug ) ] // All public types implement Debug (C-DEBUG).
@@ -263,3 +265,42 @@ fn regression_default() {
263265 } ;
264266 assert_eq ! ( got, want) ;
265267}
268+
269+ #[ cfg( feature = "arbitrary" ) ]
270+ impl < ' a > Arbitrary < ' a > for Types {
271+ fn arbitrary ( u : & mut Unstructured < ' a > ) -> arbitrary:: Result < Self > {
272+ let a = Types { a : Enums :: arbitrary ( u) ?, b : Structs :: arbitrary ( u) ? } ;
273+ Ok ( a)
274+ }
275+ }
276+
277+ #[ cfg( feature = "arbitrary" ) ]
278+ impl < ' a > Arbitrary < ' a > for Structs {
279+ fn arbitrary ( u : & mut Unstructured < ' a > ) -> arbitrary:: Result < Self > {
280+ let a = Structs {
281+ a : Amount :: arbitrary ( u) ?,
282+ // Skip the `Display` type.
283+ b : Amount :: MAX . display_in ( amount:: Denomination :: Bitcoin ) ,
284+ c : SignedAmount :: arbitrary ( u) ?,
285+ d : BlockHeight :: arbitrary ( u) ?,
286+ e : BlockInterval :: arbitrary ( u) ?,
287+ f : FeeRate :: arbitrary ( u) ?,
288+ g : absolute:: Height :: arbitrary ( u) ?,
289+ h : absolute:: Time :: arbitrary ( u) ?,
290+ i : relative:: Height :: arbitrary ( u) ?,
291+ j : relative:: Time :: arbitrary ( u) ?,
292+ k : Weight :: arbitrary ( u) ?,
293+ } ;
294+ Ok ( a)
295+ }
296+ }
297+
298+ #[ cfg( feature = "arbitrary" ) ]
299+ impl < ' a > Arbitrary < ' a > for Enums {
300+ fn arbitrary ( u : & mut Unstructured < ' a > ) -> arbitrary:: Result < Self > {
301+ let a = Enums {
302+ a : amount:: Denomination :: arbitrary ( u) ?,
303+ } ;
304+ Ok ( a)
305+ }
306+ }
0 commit comments