Skip to content

Commit

Permalink
Add Gen.genIP4
Browse files Browse the repository at this point in the history
  • Loading branch information
japgolly committed Sep 6, 2022
1 parent e527afb commit 9103219
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/changelog/1.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
GenJson(4).sample()
```

* Added `Gen.ip4: Gen[java.net.InetAddress]` for generating random IP4 addresses

* Update Scala.js to 1.10
* Update Scala 3 to 3.1
8 changes: 8 additions & 0 deletions gen/shared/src/main/scala/nyaya/gen/Gen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nyaya.gen

import cats.data._
import cats.{Distributive, Eval, Functor, Monad, Traverse, ~>}
import java.net.InetAddress
import java.time.ZoneId
import java.util.UUID
import scala.annotation.{switch, tailrec}
Expand Down Expand Up @@ -879,6 +880,13 @@ object Gen {
def dateTime(implicit genNow: Gen[Now]): DateTimeBuilder =
DateTimeBuilder.default(genNow)

// ------------------
// Networking related
// ------------------

lazy val ip4: Gen[InetAddress] =
Gen.byte.arraySeq(4).map(a => InetAddress.getByAddress(a.toArray))

// --------------------------------------------------------------
// Traverse using plain Scala collections and CanBuildFrom (fast)
// --------------------------------------------------------------
Expand Down

0 comments on commit 9103219

Please sign in to comment.