Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion test-tests/shared/src/test/scala/zio/test/GenSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object GenSpec extends ZIOBaseSpec {
val p = (as ++ bs).reverse == (as.reverse ++ bs.reverse)
if (p) assert(())(Assertion.anything) else assert((as, bs))(Assertion.nothing)
}

assertM(CheckN(100)(gen)(test).map { result =>
result.failures.fold(false) {
case BoolAlgebra.Value(FailureDetailsResult(failureDetails, _)) =>
Expand Down Expand Up @@ -255,6 +256,22 @@ object GenSpec extends ZIOBaseSpec {
val max = Instant.ofEpochSecond(74576982873324L, 345345345)
checkSample(Gen.instant(min, max))(forall(isGreaterThanEqualTo(min) && isLessThanEqualTo(max)))
},
testM("instant generates values in range when upper and lower bound share same second ") {
val min = Instant.ofEpochSecond(1, 2)
val max = Instant.ofEpochSecond(1, 3)
checkSample(Gen.instant(min, max))(forall(isGreaterThanEqualTo(min) && isLessThanEqualTo(max)))
},
testM("instant generates values in range when upper bound nano part is smaller than lower bound one") {
val min = Instant.ofEpochSecond(2, 1)
val max = Instant.ofEpochSecond(3, 9)
checkSample(Gen.instant(min, max))(forall(isGreaterThanEqualTo(min) && isLessThanEqualTo(max)))
},
testM("instant generates one value when upper and lower bound are equals") {
val anInstant = Instant.ofEpochSecond(1, 1)
checkSample(Gen.instant(anInstant, anInstant))(
forall(equalTo(anInstant))
)
},
testM("int generates values in range") {
checkSample(smallInt)(forall(isGreaterThanEqualTo(-10) && isLessThanEqualTo(10)))
},
Expand Down Expand Up @@ -750,7 +767,8 @@ object GenSpec extends ZIOBaseSpec {
case object Pop extends Command
final case class Push(value: Int) extends Command

val genPop: Gen[Any, Command] = Gen.const(Pop)
val genPop: Gen[Any, Command] = Gen.const(Pop)

def genPush: Gen[Random, Command] = Gen.anyInt.map(value => Push(value))

val genCommands: Gen[Random with Sized, List[Command]] =
Expand Down
2 changes: 1 addition & 1 deletion test/shared/src/main/scala/zio/test/TimeVariants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ trait TimeVariants {
*/
final def instant(min: Instant, max: Instant): Gen[Random, Instant] = {

def genSecond(min: Instant, max: Instant): Gen[Random, Long] = Gen.long(min.getEpochSecond, max.getEpochSecond - 1)
def genSecond(min: Instant, max: Instant): Gen[Random, Long] = Gen.long(min.getEpochSecond, max.getEpochSecond)

def genNano(min: Instant, max: Instant, second: Long): Gen[Random, Long] = {
val minNano = if (min.getEpochSecond == second) min.getNano.toLong else 0L
Expand Down