Skip to content

Commit

Permalink
Improve docs and failure message.
Browse files Browse the repository at this point in the history
  • Loading branch information
zainab-ali committed Nov 8, 2024
1 parent ac801c6 commit 971da20
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ case class CheckConfig private (
assert(maximumDiscardRatio <= 100)
assert(minimumSuccessful > 0)

/**
* The maximum number of values that can be discarded by the generator. The
* test will fail if the generator discards more values.
*/
def maximumDiscarded = minimumSuccessful * maximumDiscardRatio / 100

/** The number of successful runs required for a test to succeed */
def withMinimumSuccessful(minimumSuccessful: Int) = copy(
minimumSuccessful = minimumSuccessful
)

/**
* The proportion of values discarded by the generator allowed before the test
* is considered failed.
*/
def withMaximumDiscardRatio(maximumDiscardRatio: Int) = copy(
maximumDiscardRatio = maximumDiscardRatio
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ trait Checkers {
failure.getOrElse {
if (succeeded < config.minimumSuccessful)
Expectations.Helpers.failure(
s"Discarded more inputs ($discarded) than allowed")
s"Discarded more inputs ($discarded) than allowed (${config.maximumDiscarded})")
else Expectations.Helpers.success
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ object PropertyDogFoodTest extends IOSuite {
}

test("Config can be overridden") { dogfood =>
val maximumDiscarded =
Meta.ConfigOverrideChecks.configOverride.maximumDiscarded
expectErrorMessage(
s"Discarded more inputs (${Meta.ConfigOverrideChecks.configOverride.maximumDiscarded + 1}) than allowed",
s"Discarded more inputs (${maximumDiscarded + 1}) than allowed (${maximumDiscarded})",
dogfood.runSuite(Meta.ConfigOverrideChecks))
}

test("Discarded counts should be accurate") { dogfood =>
val maximumDiscarded = Meta.DiscardedChecks.checkConfig.maximumDiscarded
expectErrorMessage(
s"Discarded more inputs (${Meta.DiscardedChecks.checkConfig.maximumDiscarded + 1}) than allowed",
s"Discarded more inputs (${maximumDiscarded + 1}) than allowed (${maximumDiscarded})",
dogfood.runSuite(Meta.DiscardedChecks))
}
test("Discard ratio of zero should still run tests") {
Expand Down

0 comments on commit 971da20

Please sign in to comment.