Skip to content

Commit cdd8473

Browse files
committed
Fix: Apply and remove clippy warnings
1 parent 9fd7cc6 commit cdd8473

File tree

6 files changed

+35
-31
lines changed

6 files changed

+35
-31
lines changed

DOCUMENTATION.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -403,28 +403,28 @@ trait directly, or just make use of [shrink::from_fn].
403403
## Key design principles of Monkey Test
404404

405405
* *configurability and flexibility* - Leave a high degree of configurability
406-
and flexibility to the user by letting most details to be specified
407-
programatically. The aim is to have an declarative builder-style API like
408-
the Java library
409-
QuickTheories [(github)](https://github.com/quicktheories/QuickTheories).
406+
and flexibility to the user by letting most details to be specified
407+
programatically. The aim is to have an declarative builder-style API like
408+
the Java library
409+
QuickTheories [(github)](https://github.com/quicktheories/QuickTheories).
410410

411411
* *powerful shinking* - Good shrinkers is a really important aspect of a
412-
property based testing tool. Let say that the failing example is a vector
413-
of 1000 elements and only 3 of the elements in combination is the actual
414-
failure cause. You are then unlikely to find the 3-element combination,
415-
if the shrinking is not powerful enough.
412+
property based testing tool. Let say that the failing example is a vector
413+
of 1000 elements and only 3 of the elements in combination is the actual
414+
failure cause. You are then unlikely to find the 3-element combination,
415+
if the shrinking is not powerful enough.
416416

417417
* *composability for complex test examples* - Basic type generators and
418-
shrinkers are provided out of the box.
419-
User should also be able to genereate and shrink more complex types, by
420-
composing together more primitive generators and shrinkers into more
421-
complex ones.
422-
The main inspiration here is the Scala library ScalaCheck
423-
[(homepage)](https://scalacheck.org/),
424-
which is fenomenal in this aspect, having the power to for example easily
425-
generate and shrink recursive data structures, by using composition.
418+
shrinkers are provided out of the box.
419+
User should also be able to genereate and shrink more complex types, by
420+
composing together more primitive generators and shrinkers into more
421+
complex ones.
422+
The main inspiration here is the Scala library ScalaCheck
423+
[(homepage)](https://scalacheck.org/),
424+
which is fenomenal in this aspect, having the power to for example easily
425+
generate and shrink recursive data structures, by using composition.
426426

427427
* *minimize macro magic* - In order to keep the tool simple, just avoid macros
428-
if same developer experience can be provided using normal Rust code.
429-
Macros-use is an complex escape hatch only to be used when normal syntax
430-
is insufficient.
428+
if same developer experience can be provided using normal Rust code.
429+
Macros-use is an complex escape hatch only to be used when normal syntax
430+
is insufficient.

src/runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ where
9494
do_shrink(prop, first_example.clone(), cg.gen.shrinker());
9595

9696
// All but last shrinked value, up to a max limit
97-
let other_count = shrinked_values.len().min(100).max(1) as u64 - 1;
97+
let other_count = shrinked_values.len().clamp(1, 100) as u64 - 1;
9898
let some_other_failures = shrinked_values
9999
.clone()
100100
.into_iter()

src/shrink/integer.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn shrink_target<E: PrimInt>(range_min: E, range_max: E) -> E {
144144
}
145145

146146
/// Mirror a value `x` around the `mirror`, returning `2*mirror-x`, if possible
147-
/// witout overflow.
147+
/// witout overflow.
148148
fn mirror_around<E: PrimInt>(mirror: E, x: E) -> Option<E> {
149149
let diff = x.saturating_sub(mirror);
150150
let x_mirrored = mirror.saturating_sub(diff);
@@ -273,7 +273,7 @@ mod test {
273273
#[test]
274274
fn eager_tries_iteratively_smaller_decrement_both_positive_and_negative() {
275275
assert_iter_eq(
276-
super::eager(16, i64::min_value(), i64::max_value()),
276+
super::eager(16, i64::MIN, i64::MAX),
277277
vec![8, -8, 12, -12, 14, -14],
278278
"shrinks toward zero, interleave positive and negative canidates \
279279
if not restricted by given range",
@@ -284,7 +284,7 @@ mod test {
284284
fn eager_tries_iteratively_smaller_decrement_with_positive_only_for_unsigned(
285285
) {
286286
assert_iter_eq(
287-
super::eager(16, u64::min_value(), u64::max_value()),
287+
super::eager(16, u64::MIN, u64::MAX),
288288
vec![8, 12, 14],
289289
"shrinks toward zero, with only positive canidates for unsigned \
290290
integer typed",
@@ -294,26 +294,26 @@ mod test {
294294
#[test]
295295
fn eager_only_returns_candidates_within_range() {
296296
assert_iter_eq(
297-
super::eager(16, -5, i64::max_value()),
297+
super::eager(16, -5, i64::MAX),
298298
vec![8, 12, 14],
299299
"shrinks down toward zero, but only positives are in range",
300300
);
301301

302302
assert_iter_eq(
303-
super::eager(17, 1, i64::max_value()),
303+
super::eager(17, 1, i64::MAX),
304304
vec![9, 13, 15],
305305
"shrink as in first but translated 1 to rateger 1 from 17, so \
306306
difference from original_failure to target is still 16",
307307
);
308308

309309
assert_iter_eq(
310-
super::eager(-16, i64::min_value(), 5),
310+
super::eager(-16, i64::MIN, 5),
311311
vec![-8, -12, -14],
312312
"same shrinking as in first assert, but only negative are in range."
313313
);
314314

315315
assert_iter_eq(
316-
super::eager(16, -12, i64::max_value()),
316+
super::eager(16, -12, i64::MAX),
317317
vec![8, -8, 12, -12, 14],
318318
"same shrinking as in first assert, but some (!) negative are in range."
319319
);
@@ -326,6 +326,6 @@ mod test {
326326
#[test]
327327
#[should_panic = "Given example 1337 is not in range 0..=16."]
328328
fn eager_with_example_out_of_range_should_panic() {
329-
let _ = super::eager(1337, u64::min_value(), 16);
329+
let _ = super::eager(1337, u64::MIN, 16);
330330
}
331331
}

src/shrink/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<E> EagerIterator<E> {
9494
self.len_to_remove = match self.len_to_remove {
9595
usize::MAX => usize::MAX / 2,
9696
1 => 0,
97-
_ => (self.len_to_remove + 1) / 2,
97+
_ => self.len_to_remove.div_ceil(2),
9898
}
9999
}
100100

src/testing/integer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn assert_even_distr<E>(
2020

2121
let expected_range = (expected_max - expected_min + E::one())
2222
.to_usize()
23-
.unwrap_or(usize::max_value());
23+
.unwrap_or(usize::MAX);
2424

2525
// Pick so many elements such there should be roughly x instances of
2626
// each value.

tests/basic_usage.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ fn can_assert_eq() {
8585
.assert_eq(|n| n, |n| n / 2 * 2);
8686
}
8787

88+
/// Shows how to test for the proper of values being not equal, here shown as a
89+
/// faulty property due to positive odd numbers divided by two are rounded down.
90+
///
91+
/// Here for n=0, both 2/2=1 and 3/2=1.
8892
#[test]
8993
#[should_panic(
9094
expected = "Reason: Actual value should not equal expected 1, but got 1."
@@ -93,7 +97,7 @@ fn can_assert_ne() {
9397
monkey_test()
9498
.with_example_count(1_000)
9599
.with_generator(gen::u32::ranged(0..10_000))
96-
.assert_ne(|n| (n + 1) / 2, |n| (n + 2) / 2);
100+
.assert_ne(|n| (n + 2) / 2, |n| (n + 3) / 2);
97101
}
98102

99103
#[test]

0 commit comments

Comments
 (0)