pub fn next_bound_int(
bound: i32,
) -> Result<RangeCallTypeBuilder<i32>, ReversalError>Expand description
Creates a new builder equivalent to nextInt(bound).
This builder’s bounds are [0, bound).
Will throw an error if the bound is < 1.
Examples found in repository?
examples/dynamic_program.rs (line 16)
6fn main() -> Result<(), ReversalError> {
7 let mut program = DynamicProgram::create(JAVA);
8
9 // nextInt() == 0
10 program.add(java::next_int().equal_to(0)?)?;
11
12 // nextFloat() <= 0.5
13 program.add(java::next_float().less_than_eq(0.5)?)?;
14
15 // nextInt(16) == 2
16 program.add(java::next_bound_int(16)?.equal_to(2)?)?;
17
18 // Ignore one call, e.g. an unknown nextInt() call
19 program.skip(1);
20
21 // nextInt(4) != 1
22 program.add_filter(java::next_bound_int(4)?.equal_to(1)?.invert())?;
23
24 let mut iterator = program.reverse();
25
26 for _ in 0..25 {
27 let mut random = Random::of_seed(JAVA, iterator.next().unwrap());
28 let r = &mut random;
29
30 assert_eq!(java_random::next_int(r), 0);
31 assert!(java_random::next_float(r) <= 0.5);
32 assert_eq!(java_random::next_bound_int(r, 16), 2);
33 java_random::next_int(r); // ignore one call
34 assert_ne!(java_random::next_int(r), 1);
35 }
36
37 Ok(())
38}