-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from frenetic-lang/qc
Update and expand quickcheck subpackage
- Loading branch information
Showing
8 changed files
with
145 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
open QuickCheck | ||
module Gen = QuickCheck_gen | ||
|
||
(* arbitrary instance for usigned integers, using `int` type. *) | ||
let arbitrary_uint = Gen.sized (fun n -> Gen.choose_int (0, n)) | ||
|
||
(* arbitrary instance for unsigned int4, using the `int` type. *) | ||
let arbitrary_uint4 = Gen.choose_int (0, 0xf) | ||
|
||
(* arbitrary instance for unsigned int8, using the `int` type. *) | ||
let arbitrary_uint8 = Gen.choose_int (0, 0xff) | ||
|
||
(* arbitrary instance for unsigned int12, using the `int` type. *) | ||
let arbitrary_uint12 = Gen.choose_int (0, 0xfff) | ||
|
||
(* arbitrary instance for unsigned int16, using the `int` type. *) | ||
let arbitrary_uint16 = Gen.choose_int (0, 0xffff) | ||
|
||
(* arbitrary instance for unsigned int32, using the `int32` type. *) | ||
let arbitrary_uint32 = | ||
let open Gen in | ||
arbitrary_uint16 >>= fun a -> | ||
arbitrary_uint16 >>= fun b -> | ||
let open Int32 in | ||
let hi = shift_left (of_int a) 16 in | ||
let lo = of_int b in | ||
ret_gen (logor hi lo) | ||
|
||
(* arbitrary first `b` bits set in an Int32 *) | ||
let arbitrary_uint32_bits b = | ||
Gen.choose_int32 (Int32.zero, Int32.of_int ((0x1 lsl b) - 1) ) | ||
|
||
(* arbitrary instance for unsigned int48, using the `int64` type. *) | ||
let arbitrary_uint48 = | ||
let open Gen in | ||
arbitrary_uint16 >>= fun a -> | ||
arbitrary_uint16 >>= fun b -> | ||
arbitrary_uint16 >>= fun c -> | ||
let open Int64 in | ||
let hi = shift_left (of_int a) 32 in | ||
let mid = shift_left (of_int b) 16 in | ||
let lo = of_int c in | ||
ret_gen Int64.(logor (logor hi mid) lo) | ||
|
||
(* arbitrary instance for unsigned int48, using the `int64` type. *) | ||
let arbitrary_uint64 = | ||
let open Gen in | ||
arbitrary_uint16 >>= fun a -> | ||
arbitrary_uint16 >>= fun b -> | ||
arbitrary_uint16 >>= fun c -> | ||
arbitrary_uint16 >>= fun d -> | ||
let open Int64 in | ||
let hi = shift_left (of_int a) 48 in | ||
let mid1 = shift_left (of_int b) 32 in | ||
let mid2 = shift_left (of_int c) 16 in | ||
let lo = of_int d in | ||
ret_gen Int64.(logor (logor hi (logor mid1 mid2)) lo) | ||
|
||
|
||
(* arbitrary instance for option type, favoring `Some` rather than `None` *) | ||
let arbitrary_option arb = | ||
let open Gen in | ||
frequency [ | ||
(1, ret_gen None); | ||
(3, arb >>= fun e -> ret_gen (Some e)) ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
open QuickCheck | ||
|
||
(* arbitrary instance for usigned integers. Still uses the `int` type. *) | ||
val arbitrary_uint : int arbitrary | ||
|
||
(* arbitrary instance for unsigned int4, using the `int` type. *) | ||
val arbitrary_uint4 : int arbitrary | ||
|
||
(* arbitrary instance for unsigned int8, using the `int` type. *) | ||
val arbitrary_uint8 : int arbitrary | ||
|
||
(* arbitrary instance for unsigned int12, using the `int` type. *) | ||
val arbitrary_uint12 : int arbitrary | ||
|
||
(* arbitrary instance for unsigned int16, using the `int` type. *) | ||
val arbitrary_uint16 : int arbitrary | ||
|
||
(* arbitrary instance for unsigned int32, using the `int32` type. *) | ||
val arbitrary_uint32 : int32 arbitrary | ||
|
||
(* arbitrary first [b] bits for unsigned int32 type. [b] must be less than 32. *) | ||
val arbitrary_uint32_bits : int -> int32 arbitrary | ||
|
||
(* arbitrary instance for unsigned int48, using the `int64` type. *) | ||
val arbitrary_uint48 : int64 arbitrary | ||
|
||
(* arbitrary instance for unsigned int64, using the `int64` type. *) | ||
val arbitrary_uint64 : int64 arbitrary | ||
|
||
(* arbitrary instance for option type, favoring `Some` rather than `None` *) | ||
val arbitrary_option : 'a arbitrary -> 'a option arbitrary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
open QuickCheck | ||
|
||
val arbitrary_dlAddr : Packet.dlAddr arbitrary | ||
val arbitrary_dlTyp : Packet.dlTyp arbitrary | ||
val arbitrary_dlVlan : (int option * bool * int) arbitrary | ||
val arbitrary_nwAddr : Packet.nwAddr arbitrary | ||
val arbitrary_nwTos : Packet.nwTos arbitrary | ||
val arbitrary_nwProto : Packet.nwProto arbitrary | ||
val arbitrary_tpPort : Packet.tpPort arbitrary | ||
|
||
val arbitrary_payload : int -> Packet.bytes arbitrary | ||
val arbitrary_arp : Packet.Arp.t arbitrary | ||
|
||
val arbitrary_udp : Packet.bytes arbitrary -> Packet.Udp.t arbitrary | ||
val arbitrary_tcp : Packet.bytes arbitrary -> Packet.Tcp.t arbitrary | ||
|
||
val arbitrary_ip_unparsable : Packet.Ip.tp arbitrary | ||
val arbitrary_ip : Packet.Ip.tp arbitrary -> Packet.Ip.t arbitrary | ||
|
||
val arbitrary_dl_unparsable : Packet.nw arbitrary | ||
val arbitrary_packet : Packet.nw arbitrary -> Packet.packet arbitrary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# OASIS_START | ||
# DO NOT EDIT (digest: efc75b648e29fe9a8789eaa30621aa1d) | ||
Packet_Arbitrary | ||
# DO NOT EDIT (digest: 330820d542742d1a91c67ac9e7db617c) | ||
Arbitrary_Base | ||
Arbitrary_Packet | ||
# OASIS_STOP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters