Skip to content

Commit

Permalink
Add Stack::begin to quickcheck test (#21)
Browse files Browse the repository at this point in the history
* add Stack::begin to quickcheck test

* add note about quickcheck test randomness
  • Loading branch information
KodrAus authored Jan 15, 2019
1 parent 39c0244 commit 53b2a18
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/stream/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,17 @@ mod tests {
Arbitrary,
Gen,
};

// FIXME: This test isn't very clever about how a
// sequence of commands is generated. It's more likely
// to come up with a set that fails early than one
// that manages to push and pop the stack depth a lot.
// We could instead weight commands so we're more likely
// to generate something valid with a degree of randomness.

#[derive(Clone, Copy, Debug)]
enum Command {
Begin,
Primitive,
MapBegin,
MapKey,
Expand All @@ -600,7 +608,7 @@ mod tests {

impl Arbitrary for Command {
fn arbitrary<G: Gen>(g: &mut G) -> Command {
match g.next_u32() % 9 {
match g.next_u32() % 10 {
0 => Command::Primitive,
1 => Command::MapBegin,
2 => Command::MapKey,
Expand All @@ -610,6 +618,7 @@ mod tests {
6 => Command::SeqElem,
7 => Command::SeqEnd,
8 => Command::End,
9 => Command::Begin,
_ => unreachable!(),
}
}
Expand All @@ -621,6 +630,9 @@ mod tests {

for cmd in cmd {
match cmd {
Command::Begin => {
let _ = stack.begin();
},
Command::Primitive => {
let _ = stack.primitive();
},
Expand Down

0 comments on commit 53b2a18

Please sign in to comment.