Skip to content

Commit

Permalink
Default case updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Samy authored and Samy committed Nov 16, 2024
1 parent f0661ca commit a6b4f19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ data class StringPattern (
private val patternMinLength: Int =
when {
minLength != null && minLength > 0 -> minLength
else -> 1
maxLength != null && maxLength < 5 -> 1
else -> 5
}

override fun generate(resolver: Resolver): Value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,21 @@ internal class StringPatternTest {
fun `generate string value of appropriate length matching minLength and maxLength parameters`(min: Int?, max: Int?, length: Int) {
val result = StringPattern(minLength = min, maxLength = max).generate(Resolver()) as StringValue
val generatedLength = result.string.length
val minPatternLength = min ?: 1;
val patternMinLength: Int =
when {
min != null && min > 0 -> min
max != null && max < 5 -> 1
else -> 5
}

// If max is provided, ensure the generated length is within the range of min and max
if (max != null) {
// Ensure that the generated string length is between min (or 0 if min is null) and max
assertThat(generatedLength).isGreaterThanOrEqualTo(minPatternLength)
assertThat(generatedLength).isGreaterThanOrEqualTo(patternMinLength)
assertThat(generatedLength).isLessThanOrEqualTo(max)
} else {
// If max is not provided, ensure the generated length is at least the min (or randomStringDefaultLength if min is null)
assertThat(generatedLength).isGreaterThanOrEqualTo(minPatternLength)
assertThat(generatedLength).isGreaterThanOrEqualTo(patternMinLength)
}
}

Expand Down

0 comments on commit a6b4f19

Please sign in to comment.