|  | 
| 1 | 1 | package com.fwdekker.randomness.template | 
| 2 | 2 | 
 | 
|  | 3 | +import com.fwdekker.randomness.CapitalizationMode | 
| 3 | 4 | import com.fwdekker.randomness.DataGenerationException | 
| 4 | 5 | import com.fwdekker.randomness.Settings | 
| 5 | 6 | import com.fwdekker.randomness.array.ArrayDecorator | 
| 6 | 7 | import com.fwdekker.randomness.integer.IntegerScheme | 
| 7 | 8 | import com.fwdekker.randomness.stateDeepCopyTestFactory | 
|  | 9 | +import com.fwdekker.randomness.string.StringScheme | 
| 8 | 10 | import com.fwdekker.randomness.testhelpers.DummyScheme | 
| 9 | 11 | import com.fwdekker.randomness.testhelpers.shouldValidateAsBundle | 
|  | 12 | +import com.fwdekker.randomness.word.WordScheme | 
| 10 | 13 | import io.kotest.assertions.throwables.shouldThrow | 
| 11 | 14 | import io.kotest.core.NamedTag | 
| 12 | 15 | import io.kotest.core.spec.style.FunSpec | 
| 13 | 16 | import io.kotest.data.row | 
| 14 | 17 | import io.kotest.datatest.withData | 
|  | 18 | +import io.kotest.matchers.collections.shouldContainExactly | 
| 15 | 19 | import io.kotest.matchers.ints.shouldBeGreaterThan | 
| 16 | 20 | import io.kotest.matchers.shouldBe | 
| 17 | 21 | import io.kotest.matchers.types.shouldBeSameInstanceAs | 
|  | 22 | +import kotlin.random.Random | 
| 18 | 23 | 
 | 
| 19 | 24 | 
 | 
| 20 | 25 | /** | 
| @@ -99,6 +104,46 @@ object TemplateTest : FunSpec({ | 
| 99 | 104 | 
 | 
| 100 | 105 |             shouldThrow<DataGenerationException> { template.generateStrings() } | 
| 101 | 106 |         } | 
|  | 107 | + | 
|  | 108 | +        context("rng") { | 
|  | 109 | +            test("returns the same given the same seed") { | 
|  | 110 | +                val template = Template(schemes = mutableListOf(StringScheme("[a-zA-Z]{10}"), IntegerScheme())) | 
|  | 111 | + | 
|  | 112 | +                val outputs1 = template.also { it.random = Random(1) }.generateStrings(5) | 
|  | 113 | +                val outputs2 = template.also { it.random = Random(1) }.generateStrings(5) | 
|  | 114 | + | 
|  | 115 | +                outputs1 shouldContainExactly outputs2 | 
|  | 116 | +            } | 
|  | 117 | + | 
|  | 118 | +            test("sets the rng of a scheme independent of scheme order") { | 
|  | 119 | +                val schemeA = IntegerScheme() | 
|  | 120 | +                val glue = StringScheme("-") | 
|  | 121 | +                val schemeB = IntegerScheme() | 
|  | 122 | + | 
|  | 123 | +                val output1 = Template(schemes = mutableListOf(schemeA, glue, schemeB)) | 
|  | 124 | +                    .also { it.random = Random(1) } | 
|  | 125 | +                    .generateStrings()[0] | 
|  | 126 | +                val output2 = Template(schemes = mutableListOf(schemeB, glue, schemeA)) | 
|  | 127 | +                    .also { it.random = Random(1) } | 
|  | 128 | +                    .generateStrings()[0] | 
|  | 129 | + | 
|  | 130 | +                output1.split("-").reversed() shouldContainExactly output2.split("-") | 
|  | 131 | +            } | 
|  | 132 | + | 
|  | 133 | +            test("sets the rng independent of the rng of other schemes") { | 
|  | 134 | +                val prefix = WordScheme(words = listOf("pre")) | 
|  | 135 | +                val scheme = IntegerScheme() | 
|  | 136 | +                val postfix = WordScheme(words = listOf("post")) | 
|  | 137 | +                val template = Template(schemes = mutableListOf(prefix, scheme, postfix)) | 
|  | 138 | + | 
|  | 139 | +                val output1 = template.also { it.random = Random(1) }.generateStrings()[0] | 
|  | 140 | +                prefix.capitalization = CapitalizationMode.RANDOM | 
|  | 141 | +                postfix.capitalization = CapitalizationMode.RANDOM | 
|  | 142 | +                val output2 = template.also { it.random = Random(1) }.generateStrings()[0] | 
|  | 143 | + | 
|  | 144 | +                output1.drop(3).dropLast(4) shouldBe output2.drop(3).dropLast(4) | 
|  | 145 | +            } | 
|  | 146 | +        } | 
| 102 | 147 |     } | 
| 103 | 148 | 
 | 
| 104 | 149 |     context("doValidate") { | 
|  | 
0 commit comments