Skip to content

Commit a31586c

Browse files
committed
Update docs
1 parent 6a89556 commit a31586c

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

CHANGELOG.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
[discrete]
2121
=== Fixed
2222

23+
* https://github.com/serpro69/kotlin-faker/pull/205[#205] [core] Fix `Person.birthDate` range error during leap year
2324
* https://github.com/serpro69/kotlin-faker/issues/204[#204] [core] Fix RandomClassProvider handling "constructor-less" types in collections
2425

2526
[discrete]

core/src/integration/kotlin/io/github/serpro69/kfaker/docs/Extras.kt

+30-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.github.serpro69.kfaker.Faker
44
import io.github.serpro69.kfaker.fakerConfig
55
import io.github.serpro69.kfaker.provider.misc.ConstructorFilterStrategy
66
import io.github.serpro69.kfaker.provider.misc.FallbackStrategy
7+
import io.github.serpro69.kfaker.provider.misc.RandomProvider
78
import io.kotest.core.spec.style.DescribeSpec
89
import io.kotest.matchers.shouldBe
910
import org.junit.jupiter.api.Assertions.assertEquals
@@ -25,7 +26,7 @@ class Extras : DescribeSpec({
2526

2627
context("configurable constructor arg type generation") {
2728
it("should generate pre-configured constructor params") {
28-
fun randomString() = "X3a8s813dcb";
29+
fun randomString() = "X3a8s813dcb"
2930

3031
// START extras_random_instance_two
3132
class Baz(val id: Int, val uuid: UUID, val relatedUuid: UUID, val user: String)
@@ -351,6 +352,34 @@ class Extras : DescribeSpec({
351352
// END extras_random_everything_nine
352353
}
353354

355+
it("should generate unique integers via local-unique-provider") {
356+
// START extras_random_everything_ten
357+
val ints = List(21) {
358+
faker.random.unique.nextInt(42)
359+
}
360+
assert(ints.distinct().size == 21)
361+
// cleanup of unique values via enum key for nextInt function
362+
faker.random.unique.clear(RandomProvider.Key.NEXT_INT)
363+
// END extras_random_everything_ten
364+
}
365+
366+
it("should generate unique integers via global-unique-provider") {
367+
// START extras_random_everything_eleven
368+
faker.unique.configuration { enable(faker::random) }
369+
val uniqueInts = List(21) {
370+
faker.random.nextInt(42)
371+
}
372+
assert(uniqueInts.distinct().size == 21)
373+
// cleanup global unique values for Random provider
374+
faker.unique.clear(faker::random)
375+
// disable global unique values for Random provider
376+
faker.unique.configuration { disable(faker::random) }
377+
val ints = List(21) {
378+
faker.random.nextInt(42)
379+
}
380+
assert(ints.distinct().size < 21)
381+
// END extras_random_everything_eleven
382+
}
354383
}
355384

356385
describe("Random Strings from Templates") {

docs/src/orchid/resources/wiki/extras.md

+22
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,28 @@ Faker provides its wrapper functions around `java.util.Random` (with some additi
551551

552552
{% endtabs %}
553553

554+
### Unique Random Values
555+
556+
Just like most data providers, `Faker#random` supports generation of unique values. See {{ anchor(title='Generator of Unique Values', collectionType='wiki', collectionId='', itemId='Generator of Unique Values') }} page for usage details.
557+
558+
Both "local" (provider level) and "global" (faker level) generation of unique values are supported for `RandomProvider`:
559+
560+
{% tabs %}
561+
562+
{% kotlin "Kotlin" %}
563+
{% filter compileAs('md') %}
564+
```kotlin
565+
{% snippet 'extras_random_everything_ten' %}
566+
```
567+
568+
```kotlin
569+
{% snippet 'extras_random_everything_eleven' %}
570+
```
571+
{% endfilter %}
572+
{% endkotlin %}
573+
574+
{% endtabs %}
575+
554576
{% btc %}{% endbtc %}
555577

556578
<br>

0 commit comments

Comments
 (0)