2
J'essaie de générer une liste d'UUID arbitraires en utilisant scalacheck (version 1.12.2). Pour une raison quelconque, chaque UUID de la liste générée est identique. Ce n'est pas le cas pour d'autres types tels que List [String] ou List [Int]. Voici le code que j'ai écrit:Scalacheck génère toujours le même UUID pour un arbitraire de List [UUID]
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.Arbitrary
import java.util.UUID
case class SomeUUIDClass(field: List[UUID])
case class SomeOtherClass(field: List[Int])
object Arb {
implicit def arbUUID: Arbitrary[UUID] = Arbitrary {
UUID.randomUUID()
}
implicit def arbUUIDClass = Arbitrary {
for {
field <- arbitrary[List[UUID]]
} yield SomeUUIDClass(field)
}
implicit def arbOtherClass = Arbitrary {
for {
field <- arbitrary[List[Int]]
} yield SomeOtherClass(field)
}
def main(args: Array[String]) {
println("without uuids:")
arbitrary[SomeOtherClass].sample.get.field.foreach(println(_))
println("")
println("with uuids:")
arbitrary[SomeUUIDClass].sample.get.field.foreach(println(_))
}
}
Et une course exemple:
without uuids:
-1
0
2147483647
-1
-2147483648
527079214
-698179980
1192016877
-1001957700
0
682853458
-1
-2147483648
109314552
1130736291
1080418
1771214863
1164874892
-1306566270
2147483647
-2009106057
2147483647
-2147483648
-1
-1
-1
945958506
777623735
-490377345
-272177229
0
-2147483648
-1753697474
-1
736327057
415072340
0
with uuids:
a49540b4-29ce-464f-946d-3649f38fb8a6
a49540b4-29ce-464f-946d-3649f38fb8a6
a49540b4-29ce-464f-946d-3649f38fb8a6
a49540b4-29ce-464f-946d-3649f38fb8a6
a49540b4-29ce-464f-946d-3649f38fb8a6
a49540b4-29ce-464f-946d-3649f38fb8a6
a49540b4-29ce-464f-946d-3649f38fb8a6
a49540b4-29ce-464f-946d-3649f38fb8a6
a49540b4-29ce-464f-946d-3649f38fb8a6
Merci! Cela l'a réparé. – emccorson