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

Commit

Permalink
deprecate: Generator.create and simplifier
Browse files Browse the repository at this point in the history
Since both `Generator` and `Simplfier` are fun interfaces, theses
factory methods are no longer needed.
  • Loading branch information
jcornaz committed Aug 13, 2020
1 parent 6454e57 commit 11aa0ae
Show file tree
Hide file tree
Showing 43 changed files with 242 additions and 210 deletions.
2 changes: 1 addition & 1 deletion codecov.yml
Expand Up @@ -10,7 +10,7 @@ coverage:
status:
project:
default:
target: 80%
target: 79%

generator:
target: 86%
Expand Down
Expand Up @@ -76,7 +76,7 @@ abstract class AbstractRunnerTest {

@Test
fun canSkipEvaluation() {
Generator.create { it.nextInt() }
Generator { it: Random -> it.nextInt() }

val values = mutableSetOf<Int>()
var invocations = 0
Expand Down
@@ -1,14 +1,15 @@
package com.github.jcornaz.kwik.evaluator

import com.github.jcornaz.kwik.generator.api.Generator
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue

class CheckForAll1Test : AbstractRunnerTest() {

private val testGenerator = Generator.create { it.nextInt() }
private val testGenerator = Generator { it: Random -> it.nextInt() }

override fun evaluate(iterations: Int, seed: Long, invocation: PropertyEvaluationContext.() -> Boolean) {
checkForAll(testGenerator, iterations, seed) { assertTrue(invocation()) }
Expand All @@ -19,7 +20,7 @@ class CheckForAll1Test : AbstractRunnerTest() {
val exception = assertFailsWith<FalsifiedPropertyError> {
var i = 0
checkForAll<Int>(
Generator.create { 42 },
Generator { it: Random -> 42 },
iterations = 123,
seed = 78
) { assertTrue(++i < 12) }
Expand All @@ -46,7 +47,7 @@ class CheckForAll1Test : AbstractRunnerTest() {

@Test
fun isPredictable() {
val gen = Generator.create { it.nextInt() }
val gen = Generator { it: Random -> it.nextInt() }

val pass1 = mutableListOf<Int>()
val pass2 = mutableListOf<Int>()
Expand Down
@@ -1,15 +1,16 @@
package com.github.jcornaz.kwik.evaluator

import com.github.jcornaz.kwik.generator.api.Generator
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue

class CheckForAll2Test : AbstractRunnerTest() {

private val testGenerator1 = Generator.create { it.nextInt() }
private val testGenerator2 = Generator.create { it.nextDouble() }
private val testGenerator1 = Generator { it: Random -> it.nextInt() }
private val testGenerator2 = Generator { it: Random -> it.nextDouble() }

override fun evaluate(iterations: Int, seed: Long, invocation: PropertyEvaluationContext.() -> Boolean) {
checkForAll(testGenerator1, testGenerator2, iterations, seed) { _, _ -> assertTrue(invocation()) }
Expand All @@ -20,8 +21,8 @@ class CheckForAll2Test : AbstractRunnerTest() {
val exception = assertFailsWith<FalsifiedPropertyError> {
var i = 0
checkForAll(
Generator.create { 42 },
Generator.create { -4.1 },
Generator { it: Random -> 42 },
Generator { it: Random -> -4.1 },
iterations = 123, seed = 78
) { _, _ ->
if (++i >= 12) error("failed")
Expand Down
@@ -1,16 +1,17 @@
package com.github.jcornaz.kwik.evaluator

import com.github.jcornaz.kwik.generator.api.Generator
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue

class CheckForAll3Test : AbstractRunnerTest() {

private val testGenerator1 = Generator.create { it.nextInt() }
private val testGenerator2 = Generator.create { it.nextDouble() }
private val testGenerator3 = Generator.create { it.nextLong() }
private val testGenerator1 = Generator { it: Random -> it.nextInt() }
private val testGenerator2 = Generator { it: Random -> it.nextDouble() }
private val testGenerator3 = Generator { it: Random -> it.nextLong() }

override fun evaluate(iterations: Int, seed: Long, invocation: PropertyEvaluationContext.() -> Boolean) {
checkForAll(
Expand All @@ -27,9 +28,9 @@ class CheckForAll3Test : AbstractRunnerTest() {
val exception = assertFailsWith<FalsifiedPropertyError> {
var i = 0
checkForAll(
Generator.create { 42 },
Generator.create { -4.1 },
Generator.create { 100L },
Generator { it: Random -> 42 },
Generator { it: Random -> -4.1 },
Generator { it: Random -> 100L },
iterations = 123, seed = 78
) { _, _, _ ->
if (++i >= 12 ) error("failed")
Expand Down
@@ -1,17 +1,18 @@
package com.github.jcornaz.kwik.evaluator

import com.github.jcornaz.kwik.generator.api.Generator
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue

class CheckForAll4Test : AbstractRunnerTest() {

private val testGenerator1 = Generator.create { it.nextInt() }
private val testGenerator2 = Generator.create { it.nextDouble() }
private val testGenerator3 = Generator.create { it.nextLong() }
private val testGenerator4 = Generator.create { it.nextFloat() }
private val testGenerator1 = Generator { it: Random -> it.nextInt() }
private val testGenerator2 = Generator { it: Random -> it.nextDouble() }
private val testGenerator3 = Generator { it: Random -> it.nextLong() }
private val testGenerator4 = Generator { it: Random -> it.nextFloat() }

override fun evaluate(iterations: Int, seed: Long, invocation: PropertyEvaluationContext.() -> Boolean) {
checkForAll(
Expand All @@ -31,10 +32,10 @@ class CheckForAll4Test : AbstractRunnerTest() {
val exception = assertFailsWith<FalsifiedPropertyError> {
var i = 0
checkForAll(
Generator.create { 42 },
Generator.create { -4.1 },
Generator.create { 100L },
Generator.create { "hello world" },
Generator { it: Random -> 42 },
Generator { it: Random -> -4.1 },
Generator { it: Random -> 100L },
Generator { it: Random -> "hello world" },
iterations = 123, seed = 78
) { _, _, _, _ ->
if (++i >= 12) error("failed")
Expand Down
@@ -1,14 +1,15 @@
package com.github.jcornaz.kwik.evaluator

import com.github.jcornaz.kwik.generator.api.Generator
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue

class ForAll1Test : AbstractRunnerTest() {

private val testGenerator = Generator.create { it.nextInt() }
private val testGenerator = Generator { it: Random -> it.nextInt() }

override fun evaluate(iterations: Int, seed: Long, invocation: PropertyEvaluationContext.() -> Boolean) {
forAll(testGenerator, iterations, seed) { invocation() }
Expand All @@ -19,7 +20,7 @@ class ForAll1Test : AbstractRunnerTest() {
val exception = assertFailsWith<FalsifiedPropertyError> {
var i = 0
forAll<Int>(
Generator.create { 42 },
Generator { it: Random -> 42 },
iterations = 123,
seed = 78
) { ++i < 12 }
Expand All @@ -40,7 +41,7 @@ class ForAll1Test : AbstractRunnerTest() {
var iterations = 0

forAll(
Generator.create { ++iterations },
Generator { it: Random -> ++iterations },
iterations = 10
) { x ->
ensureAtLeastOne { x >= 100 }
Expand All @@ -55,7 +56,7 @@ class ForAll1Test : AbstractRunnerTest() {
var iterations = 0

forAll(
Generator.create { ++iterations },
Generator { it: Random -> ++iterations },
iterations = 10
) { x ->
ensureAtLeastOne { x >= 100 }
Expand All @@ -71,7 +72,7 @@ class ForAll1Test : AbstractRunnerTest() {
var iterations = 0

forAll(
Generator.create { ++iterations },
Generator { it: Random -> ++iterations },
iterations = 10
) { x ->
ensureAtLeastOne { x >= 10 }
Expand All @@ -87,7 +88,7 @@ class ForAll1Test : AbstractRunnerTest() {
var iteration = 0

forAll(
Generator.create { 42 },
Generator { it: Random -> 42 },
iterations = 123
) { x ->
++iteration
Expand All @@ -103,7 +104,7 @@ class ForAll1Test : AbstractRunnerTest() {
var iteration = 0
val exception = assertFailsWith<FalsifiedPropertyError> {
forAll(
Generator.create { 42 },
Generator { it: Random -> 42 },
iterations = 123,
seed = 78
) { x ->
Expand All @@ -129,7 +130,7 @@ class ForAll1Test : AbstractRunnerTest() {
val exception = assertFailsWith<FalsifiedPropertyError> {
var i = 0
forAll<Int>(
Generator.create { 42 },
Generator { it: Random -> 42 },
iterations = 123,
seed = 78
) {
Expand Down Expand Up @@ -162,7 +163,7 @@ class ForAll1Test : AbstractRunnerTest() {

@Test
fun isPredictable() {
val gen = Generator.create { it.nextInt() }
val gen = Generator { it: Random -> it.nextInt() }

val pass1 = mutableListOf<Int>()
val pass2 = mutableListOf<Int>()
Expand Down
@@ -1,15 +1,16 @@
package com.github.jcornaz.kwik.evaluator

import com.github.jcornaz.kwik.generator.api.Generator
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue

class ForAll2Test : AbstractRunnerTest() {

private val testGenerator1 = Generator.create { it.nextInt() }
private val testGenerator2 = Generator.create { it.nextDouble() }
private val testGenerator1 = Generator { it: Random -> it.nextInt() }
private val testGenerator2 = Generator { it: Random -> it.nextDouble() }

override fun evaluate(iterations: Int, seed: Long, invocation: PropertyEvaluationContext.() -> Boolean) {
forAll(
Expand All @@ -25,8 +26,8 @@ class ForAll2Test : AbstractRunnerTest() {
val exception = assertFailsWith<FalsifiedPropertyError> {
var i = 0
forAll(
Generator.create { 42 },
Generator.create { -4.1 },
Generator { it: Random -> 42 },
Generator { it: Random -> -4.1 },
iterations = 123, seed = 78
) { _, _ -> ++i < 12 }
}
Expand All @@ -47,8 +48,8 @@ class ForAll2Test : AbstractRunnerTest() {
val exception = assertFailsWith<FalsifiedPropertyError> {
var i = 0
forAll(
Generator.create { 42 },
Generator.create { -4.1 },
Generator { it: Random -> 42 },
Generator { it: Random -> -4.1 },
iterations = 123, seed = 78
) { _, _ ->
if (++i >= 12) error("failed")
Expand Down
@@ -1,16 +1,17 @@
package com.github.jcornaz.kwik.evaluator

import com.github.jcornaz.kwik.generator.api.Generator
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue

class ForAll3Test : AbstractRunnerTest() {

private val testGenerator1 = Generator.create { it.nextInt() }
private val testGenerator2 = Generator.create { it.nextDouble() }
private val testGenerator3 = Generator.create { it.nextLong() }
private val testGenerator1 = Generator { it: Random -> it.nextInt() }
private val testGenerator2 = Generator { it: Random -> it.nextDouble() }
private val testGenerator3 = Generator { it: Random -> it.nextLong() }

override fun evaluate(iterations: Int, seed: Long, invocation: PropertyEvaluationContext.() -> Boolean) {
forAll(
Expand All @@ -27,9 +28,9 @@ class ForAll3Test : AbstractRunnerTest() {
val exception = assertFailsWith<FalsifiedPropertyError> {
var i = 0
forAll(
Generator.create { 42 },
Generator.create { -4.1 },
Generator.create { 100L },
Generator { it: Random -> 42 },
Generator { it: Random -> -4.1 },
Generator { it: Random -> 100L },
iterations = 123, seed = 78
) { _, _, _ -> ++i < 12 }
}
Expand All @@ -51,9 +52,9 @@ class ForAll3Test : AbstractRunnerTest() {
val exception = assertFailsWith<FalsifiedPropertyError> {
var i = 0
forAll(
Generator.create { 42 },
Generator.create { -4.1 },
Generator.create { 100L },
Generator { it: Random -> 42 },
Generator { it: Random -> -4.1 },
Generator { it: Random -> 100L },
iterations = 123, seed = 78
) { _, _, _ ->
if (++i >= 12 ) error("failed")
Expand Down
@@ -1,17 +1,18 @@
package com.github.jcornaz.kwik.evaluator

import com.github.jcornaz.kwik.generator.api.Generator
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue

class ForAll4Test : AbstractRunnerTest() {

private val testGenerator1 = Generator.create { it.nextInt() }
private val testGenerator2 = Generator.create { it.nextDouble() }
private val testGenerator3 = Generator.create { it.nextLong() }
private val testGenerator4 = Generator.create { it.nextFloat() }
private val testGenerator1 = Generator { it: Random -> it.nextInt() }
private val testGenerator2 = Generator { it: Random -> it.nextDouble() }
private val testGenerator3 = Generator { it: Random -> it.nextLong() }
private val testGenerator4 = Generator { it: Random -> it.nextFloat() }

override fun evaluate(iterations: Int, seed: Long, invocation: PropertyEvaluationContext.() -> Boolean) {
forAll(
Expand All @@ -31,10 +32,10 @@ class ForAll4Test : AbstractRunnerTest() {
val exception = assertFailsWith<FalsifiedPropertyError> {
var i = 0
forAll(
Generator.create { 42 },
Generator.create { -4.1 },
Generator.create { 100L },
Generator.create { "hello world" },
Generator { it: Random -> 42 },
Generator { it: Random -> -4.1 },
Generator { it: Random -> 100L },
Generator { it: Random -> "hello world" },
iterations = 123, seed = 78
) { _, _, _, _ -> ++i < 12 }
}
Expand All @@ -57,10 +58,10 @@ class ForAll4Test : AbstractRunnerTest() {
val exception = assertFailsWith<FalsifiedPropertyError> {
var i = 0
forAll(
Generator.create { 42 },
Generator.create { -4.1 },
Generator.create { 100L },
Generator.create { "hello world" },
Generator { it: Random -> 42 },
Generator { it: Random -> -4.1 },
Generator { it: Random -> 100L },
Generator { it: Random -> "hello world" },
iterations = 123, seed = 78
) { _, _, _, _ ->
if (++i >= 12) error("failed")
Expand Down

0 comments on commit 11aa0ae

Please sign in to comment.