Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Commit

Permalink
Fix few minor code-smells
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornaz committed Jul 1, 2019
1 parent 8fcd6a1 commit ba97d04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fun <T> forAll(
while (attempts < iterations) {
val argument = iterator.next()

@Suppress("SwallowedException") // SkipEvaluation is used to silently skip an evaluation
val isSatisfied = try {
context.property(argument).also { ++attempts }
} catch (skip: SkipEvaluation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ private class ListGenerator<T>(
}

init {
require(minSize >= 0) { "Invalid size: $minSize" }
require(maxSize >= minSize) { "Invalid max size: $minSize" }
requireValidSizes(minSize, maxSize)
}

override fun randoms(seed: Long): Sequence<List<T>> = sequence {
Expand Down Expand Up @@ -124,8 +123,7 @@ private class SetGenerator<T>(
}

init {
require(minSize >= 0) { "Invalid size: $minSize" }
require(maxSize >= minSize) { "Invalid max size: $minSize" }
requireValidSizes(minSize, maxSize)
}

override fun randoms(seed: Long): Sequence<Set<T>> = sequence {
Expand All @@ -146,7 +144,8 @@ private class SetGenerator<T>(
++extraAttempt
}

if (set.size < minSize) throw Exception("Failed to create a set with the requested minimum of element")
if (set.size < minSize)
error("Failed to create a set with the requested minimum of element")

yield(set)
}
Expand Down Expand Up @@ -216,8 +215,7 @@ private class MapGenerator<K, V>(
}

init {
require(minSize >= 0) { "Invalid size: $minSize" }
require(maxSize >= minSize) { "Invalid max size: $minSize" }
requireValidSizes(minSize, maxSize)
}

override fun randoms(seed: Long): Sequence<Map<K, V>> = sequence {
Expand All @@ -239,9 +237,15 @@ private class MapGenerator<K, V>(
++extraAttempt
}

if (map.size < minSize) throw Exception("Failed to create a set with the requested minimum of element")
if (map.size < minSize)
error("Failed to create a set with the requested minimum of element")

yield(map)
}
}
}

private fun requireValidSizes(minSize: Int, maxSize: Int) {
require(minSize >= 0) { "Invalid min size: $minSize" }
require(maxSize >= minSize) { "Invalid max size: $minSize" }
}

0 comments on commit ba97d04

Please sign in to comment.