Skip to content

Commit

Permalink
add edge cases 0, 1, -1 to Long and Int Generator (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
abendt authored and LeoColman committed Nov 27, 2019
1 parent d233af3 commit 536cbc6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ fun Gen.Companion.string(minSize: Int = 0, maxSize: Int = 100): Gen<String> = ob
/**
* Returns a stream of values where each value is a randomly
* chosen [Int]. The values always returned include
* the following edge cases: [[Int.MIN_VALUE], [Int.MAX_VALUE], 0]
* the following edge cases: [[Int.MIN_VALUE], [Int.MAX_VALUE], 0, 1, -1]
*/
fun Gen.Companion.int() = object : Gen<Int> {
val literals = listOf(Int.MIN_VALUE, Int.MAX_VALUE, 0)
val literals = listOf(Int.MIN_VALUE, Int.MAX_VALUE, 0, 1, -1)
override fun constants(): Iterable<Int> = literals
override fun random(seed: Long?): Sequence<Int> {
val r = if (seed == null) Random.Default else Random(seed)
Expand Down Expand Up @@ -213,10 +213,10 @@ fun Gen.Companion.numericFloats(
/**
* Returns a stream of values where each value is a randomly
* chosen long. The values returned always include
* the following edge cases: [[Long.MIN_VALUE], [Long.MAX_VALUE]]
* the following edge cases: [[Long.MIN_VALUE], [Long.MAX_VALUE], 0, 1, -1]
*/
fun Gen.Companion.long(): Gen<Long> = object : Gen<Long> {
val literals = listOf(Long.MIN_VALUE, Long.MAX_VALUE)
val literals = listOf(Long.MIN_VALUE, Long.MAX_VALUE, 0L, 1L, -1L)
override fun constants(): Iterable<Long> = literals
override fun random(seed: Long?): Sequence<Long> {
val r = if (seed == null) Random.Default else Random(seed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class PropertyAssertAllTest : StringSpec({
attempts++
(a * b) * c shouldBe a * (b * c)
}
attempts shouldBe 30
attempts shouldBe 125
}

"assertAll: Three explicit generators failure at the third attempt" {
Expand Down Expand Up @@ -273,13 +273,13 @@ class PropertyAssertAllTest : StringSpec({
attempts shouldBe 1000
}

"assertAll: Four explicit generators success after 88 attempts" {
"assertAll: Four explicit generators success after 3125 attempts" {
var attempts = 0
assertAll(88, Gen.int(), Gen.int(), Gen.int(), Gen.int()) { a, b, c, d ->
assertAll(3125, Gen.int(), Gen.int(), Gen.int(), Gen.int()) { a, b, c, d ->
attempts++
a + b + c + d shouldBe d + c + b + a
}
attempts shouldBe 88
attempts shouldBe 3125
}

"assertAll: Four explicit generators failed after 4 attempts" {
Expand Down Expand Up @@ -310,36 +310,36 @@ class PropertyAssertAllTest : StringSpec({
attempts shouldBe 1000
}

"assertAll: four implicit generators with 98 attempts" {
"assertAll: four implicit generators with 600 attempts" {
var attempts = 0
assertAll(98) { _: Int, _: Int, _: Int, _: Int ->
assertAll(600) { _: Int, _: Int, _: Int, _: Int ->
attempts++
}
attempts shouldBe 98
attempts shouldBe 625
}

"assertAll: four implicit generators with 250 attempts" {
"assertAll: four implicit generators with 800 attempts" {
var attempts = 0
assertAll(250) { _: Int, _: Int, _: Int, _: Int ->
assertAll(800) { _: Int, _: Int, _: Int, _: Int ->
attempts++
}
attempts shouldBe 250
attempts shouldBe 800
}

"assertAll: five explicit generators with 999 attempts" {
"assertAll: five explicit generators with 4000 attempts" {
var attempts = 0
assertAll(999, Gen.int(), Gen.int(), Gen.int(), Gen.int(), Gen.int()) { _, _, _, _, _ ->
assertAll(4000, Gen.int(), Gen.int(), Gen.int(), Gen.int(), Gen.int()) { _, _, _, _, _ ->
attempts++
}
attempts shouldBe 999
attempts shouldBe 4000
}

"assertAll: five explicit generators with default attempts" {
var attempts = 0
assertAll(Gen.int(), Gen.int(), Gen.int(), Gen.int(), Gen.int()) { _, _, _, _, _ ->
attempts++
}
attempts shouldBe 1000
attempts shouldBe 3125
}

"assertAll: five explicit generators failed after 10 attempts" {
Expand Down Expand Up @@ -371,7 +371,7 @@ class PropertyAssertAllTest : StringSpec({
assertAll { _: Int, _: Int, _: Int, _: Int, _: Int ->
attempts++
}
attempts shouldBe 1000
attempts shouldBe 3125
}

"assertAll five implicit generators with 9999 attempts" {
Expand All @@ -387,15 +387,15 @@ class PropertyAssertAllTest : StringSpec({
assertAll(Gen.int(), Gen.int(), Gen.int(), Gen.int(), Gen.int(), Gen.int()) { _, _, _, _, _, _ ->
attempts++
}
attempts shouldBe 1000
attempts shouldBe 15625
}

"assertAll six explicit arguments with 999 attempts" {
"assertAll six explicit arguments with 16000 attempts" {
var attempts = 0
assertAll(999, Gen.int(), Gen.int(), Gen.int(), Gen.int(), Gen.int(), Gen.int()) { _, _, _, _, _, _ ->
assertAll(16000, Gen.int(), Gen.int(), Gen.int(), Gen.int(), Gen.int(), Gen.int()) { _, _, _, _, _, _ ->
attempts++
}
attempts shouldBe 999
attempts shouldBe 16000
}

"assertAll six explicit arguments failing at 40 attempts" {
Expand Down Expand Up @@ -442,20 +442,20 @@ class PropertyAssertAllTest : StringSpec({
attempts shouldBe 30000
}

"assertAll: six implicit arguments 24567 attempts" {
"assertAll: six implicit arguments 27000 attempts" {
var attempts = 0
assertAll(24567) { _: Int, _: Double, _: String, _: Long, _: Float, _: Int ->
assertAll(1000) { _: Int, _: Double, _: String, _: Long, _: Float, _: Int ->
attempts++
}
attempts shouldBe 24567
attempts shouldBe 27000
}

"assertAll: six implicit arguments default attempts" {
var attempts = 0
assertAll { _: Int, _: Double, _: String, _: Long, _: Float, _: Int ->
attempts++
}
attempts shouldBe 3888
attempts shouldBe 27000
}

"sets" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ class PropertyForAllTest : StringSpec() {
attempts shouldBe 1000
}

"forAll: Three explicit generators 30 attempts" {
"forAll: Three explicit generators 200 attempts" {
// 30 should be ignored as we have many always cases
var attempts = 0
forAll(30, Gen.int(), Gen.int(), Gen.int()) { a, b, c ->
forAll(200, Gen.int(), Gen.int(), Gen.int()) { a, b, c ->
attempts++
(a * b) * c == a * (b * c)
}
attempts shouldBe 30
attempts shouldBe 200
}

"forAll: Three explicit generators failure" {
Expand Down Expand Up @@ -259,7 +259,7 @@ class PropertyForAllTest : StringSpec() {
attempts++
a + b + c + d == d + c + b + a
}
attempts shouldBe 81
attempts shouldBe 625
}

"forAll: Four explicit generators failed after 4 attempts" {
Expand Down Expand Up @@ -291,31 +291,22 @@ class PropertyForAllTest : StringSpec() {
attempts shouldBe 1000
}

"forAll: four implicit generators with 92 attempts" {
"forAll: four implicit generators with 630 attempts" {
var attempts = 0
forAll(92) { _: Int, _: Int, _: Int, _: Int ->
forAll(630) { _: Int, _: Int, _: Int, _: Int ->
attempts++
true
}
attempts shouldBe 92
attempts shouldBe 630
}

"forAll: four implicit generators with 250 attempts" {
"forAll: five explicit generators with 4000 attempts" {
var attempts = 0
forAll(250) { _: Int, _: Int, _: Int, _: Int ->
forAll(4000, Gen.int(), Gen.int(), Gen.int(), Gen.int(), Gen.int()) { _, _, _, _, _ ->
attempts++
true
}
attempts shouldBe 250
}

"forAll: five explicit generators with 999 attempts" {
var attempts = 0
forAll(999, Gen.int(), Gen.int(), Gen.int(), Gen.int(), Gen.int()) { _, _, _, _, _ ->
attempts++
true
}
attempts shouldBe 999
attempts shouldBe 4000
}

"forAll: five explicit generators with default attempts" {
Expand All @@ -324,7 +315,7 @@ class PropertyForAllTest : StringSpec() {
attempts++
true
}
attempts shouldBe 1000
attempts shouldBe 3125
}

"forAll: five explicit generators failure" {
Expand All @@ -350,7 +341,7 @@ class PropertyForAllTest : StringSpec() {
attempts++
true
}
attempts shouldBe 1000
attempts shouldBe 3125
}

"forAll five implicit generators with 9999 attempts" {
Expand All @@ -368,7 +359,7 @@ class PropertyForAllTest : StringSpec() {
attempts++
true
}
attempts shouldBe 1000
attempts shouldBe 15625
}

"forAll six explicit arguments with 50 attempts" {
Expand All @@ -377,7 +368,7 @@ class PropertyForAllTest : StringSpec() {
attempts++
true
}
attempts shouldBe 1000
attempts shouldBe 15625
}

"forAll six explicit arguments failing at 40 attempts" {
Expand Down Expand Up @@ -429,7 +420,7 @@ class PropertyForAllTest : StringSpec() {
attempts++
true
}
attempts shouldBe 3888
attempts shouldBe 27000
}

"sets" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,16 @@ class PropertyForNoneTest : StringSpec() {
attempts++
false
}
attempts shouldBe 1000
attempts shouldBe 3600
}

"forNone: five explicit generators 3411 attempts" {
"forNone: five explicit generators 4600 attempts" {
var attempts = 0
forNone(3411, Gen.int(), Gen.string(), Gen.double(), Gen.long(), Gen.int()) { _, _, _, _, _ ->
forNone(4600, Gen.int(), Gen.string(), Gen.double(), Gen.long(), Gen.int()) { _, _, _, _, _ ->
attempts++
false
}
attempts shouldBe 3411
attempts shouldBe 4600
}

"forNone: five explicit generators fails after 2 attempts" {
Expand Down Expand Up @@ -497,7 +497,7 @@ class PropertyForNoneTest : StringSpec() {
attempts++
false
}
attempts shouldBe 1000
attempts shouldBe 3125
}

"forNone: five implicit generators 4144 attempts" {
Expand All @@ -515,7 +515,7 @@ class PropertyForNoneTest : StringSpec() {
attempts++
false
}
attempts shouldBe 1000
attempts shouldBe 15625
}

"forNone: six explicit generators 17897 attempts" {
Expand Down Expand Up @@ -581,7 +581,7 @@ class PropertyForNoneTest : StringSpec() {
attempts++
false
}
attempts shouldBe 1000
attempts shouldBe 15625
}

"forNone: six implicit generators 30000 attempts" {
Expand Down

0 comments on commit 536cbc6

Please sign in to comment.