Skip to content

Commit

Permalink
Merge f863af7 into bf9f5cd
Browse files Browse the repository at this point in the history
  • Loading branch information
mlopes committed May 18, 2019
2 parents bf9f5cd + f863af7 commit 45a5e4a
Show file tree
Hide file tree
Showing 62 changed files with 274 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ language: scala
scala:
- 2.12.8

script: "sbt clean coverage test coverageReport coveralls"
script: "sbt clean coverage test coverageReport && sbt coverageAggregate && sbt coveralls"
33 changes: 33 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,45 @@ ThisBuild / organizationName := "mlopes"

lazy val wen = project
.in(file("."))
.aggregate(core, cats, circe)
.settings(name := "Wen Root")

lazy val core = project
.in(file("modules/core"))
.settings(moduleName := "wen", name := "Wen")
.settings(
libraryDependencies ++= scalaTest,
libraryDependencies ++= wenDependencies,
scalacOptions := appScalacOptions,
compile in Compile := (compile in Compile).dependsOn(dependencyUpdates).value,
coverageMinimum := 100,
coverageFailOnMinimum := true,
publishTo := sonatypePublishTo.value
)

lazy val cats = project
.in(file("modules/cats"))
.dependsOn(core)
.settings(moduleName := "wen-cats", name := "Wen Cats")
.settings(
libraryDependencies ++= scalaTest,
libraryDependencies ++= wenDependencies,
scalacOptions := appScalacOptions,
compile in Compile := (compile in Compile).dependsOn(dependencyUpdates).value,
coverageMinimum := 100,
coverageFailOnMinimum := true,
publishTo := sonatypePublishTo.value
)

lazy val circe = project
.in(file("modules/circe"))
.dependsOn(core, cats)
.settings(moduleName := "wen-circe", name := "Wen Circe")
.settings(
libraryDependencies ++= scalaTest,
libraryDependencies ++= wenDependencies,
scalacOptions := appScalacOptions,
compile in Compile := (compile in Compile).dependsOn(dependencyUpdates).value,
coverageMinimum := 100,
coverageFailOnMinimum := true,
publishTo := sonatypePublishTo.value
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
160 changes: 160 additions & 0 deletions modules/core/src/test/scala/wen/test/Arbitraries.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package wen.test

import java.time.{Month => _, Year => _, _}

import org.scalacheck.{Arbitrary, Gen}
import wen.datetime.{Date, DateTime, Offset, Time, ZoneDateTime, ZoneTime}
import wen.types._
import eu.timepit.refined._

object Arbitraries {
implicit val optionYearArb: Arbitrary[Option[Year]] = Arbitrary {
for {
y <- Gen.posNum[Int]
e <- Gen.oneOf(BC, AD)
} yield Year.fromIntWithEpoch(y, e)
}

implicit val optionDayArb: Arbitrary[Option[Day]] = Arbitrary {
Gen.choose(Day.min, Day.max).map(Day.fromInt(_))
}

implicit val dayArb: Arbitrary[Day] = Arbitrary {
optionDayArb.arbitrary.map(_.get)
}

implicit val monthArb: Arbitrary[Month] = Arbitrary {
Gen.oneOf(January, February, March, April, May, June, July, August, September, October, November, December)
}

implicit val yearArb: Arbitrary[Year] = Arbitrary {
for {
y <- Gen.posNum[Int]
e <- Gen.oneOf[Epoch](BC, AD)
} yield Year(refineV.unsafeFrom(y), e)
}

implicit val weekDayArb: Arbitrary[WeekDay] = Arbitrary {
Gen.oneOf(Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday)
}

implicit val optionHourArb: Arbitrary[Option[Hour]] = Arbitrary {
Gen.choose(Hour.min, Hour.max).map(Hour.fromInt(_))
}

implicit val hourArb: Arbitrary[Hour] = Arbitrary {
optionHourArb.arbitrary.map(_.get)
}

implicit val optionMinuteArb: Arbitrary[Option[Minute]] = Arbitrary {
Gen.choose(Minute.min, Minute.max).map(Minute.fromInt(_))
}

implicit val minuteArb: Arbitrary[Minute] = Arbitrary {
optionMinuteArb.arbitrary.map(_.get)
}

implicit val optionSecondArb: Arbitrary[Option[Second]] = Arbitrary {
Gen.choose(Second.min, Second.max).map(Second.fromInt(_))
}

implicit val secondArb: Arbitrary[Second] = Arbitrary {
optionSecondArb.arbitrary.map(_.get)
}

implicit val optionMillisecondArb: Arbitrary[Option[Millisecond]] = Arbitrary {
Gen.choose(Millisecond.min, Millisecond.max).map(Millisecond.fromInt(_))
}

implicit val millisecondArb: Arbitrary[Millisecond] = Arbitrary {
optionMillisecondArb.arbitrary.map(_.get)
}

implicit val epochArb: Arbitrary[Epoch] = Arbitrary {
Gen.oneOf(BC, AD)
}

implicit val timeArb: Arbitrary[Time] = Arbitrary {
for {
h <- hourArb.arbitrary
m <- minuteArb.arbitrary
s <- secondArb.arbitrary
ms <- millisecondArb.arbitrary
} yield Time(h, m, s, ms)
}

implicit val localTimeArb: Arbitrary[LocalTime] = Arbitrary {
val rangeStart = LocalTime.MIN.toNanoOfDay
val rangeEnd = LocalTime.MAX.toNanoOfDay
Gen.choose(rangeStart, rangeEnd).map(i => LocalTime.ofNanoOfDay(i))
}

implicit val dateArb: Arbitrary[Date] = Arbitrary {
for {
d <- localDateArb.arbitrary
} yield Date(d)
}

implicit val dateTimeArb: Arbitrary[DateTime] = Arbitrary {
for {
d <- dateArb.arbitrary
t <- timeArb.arbitrary
} yield DateTime(d, t)
}

implicit val zoneTimeArb: Arbitrary[ZoneTime] = Arbitrary {
for {
t <- timeArb.arbitrary
o <- offsetArb.arbitrary
} yield ZoneTime(t, o)

}

implicit val zoneDateTimeArb: Arbitrary[ZoneDateTime] = Arbitrary {
for {
odt <- offsetDateTimeArb.arbitrary
} yield ZoneDateTime(odt)
}

implicit val offsetArb: Arbitrary[Offset] = Arbitrary {
for {
t <- Gen.oneOf(Offset.UTCMinus, Offset.UTCPlus)
h <- Gen.choose(0, 17).map(Hour.fromInt(_))
m <- minuteArb.arbitrary
} yield Offset(t, h.get, m)
}

implicit val localDateArb: Arbitrary[LocalDate] = Arbitrary {
val rangeStart = LocalDate.MIN.toEpochDay
val rangeEnd = LocalDate.MAX.toEpochDay
Gen.choose(rangeStart, rangeEnd).map(i => LocalDate.ofEpochDay(i))
}

implicit val localDateTimeArb: Arbitrary[LocalDateTime] = Arbitrary {
val rangeStart = LocalDateTime.MIN.toEpochSecond(ZoneOffset.UTC)
val rangeEnd = LocalDateTime.MAX.toEpochSecond(ZoneOffset.UTC)
Gen.choose(rangeStart, rangeEnd).map(i => LocalDateTime.ofEpochSecond(i, 0, ZoneOffset.UTC))
}

implicit val offsetTimeArb: Arbitrary[OffsetTime] = Arbitrary {
val rangeStart = OffsetTime.MIN.toLocalTime.toNanoOfDay
val rangeEnd = OffsetTime.MAX.toLocalTime.toNanoOfDay
Gen.choose(rangeStart, rangeEnd).map(i => OffsetTime.of(LocalTime.ofNanoOfDay(i), ZoneOffset.UTC))
}

implicit val zoneOffsetArb: Arbitrary[ZoneOffset] = Arbitrary {
val rangeStart = ZoneOffset.MIN.getTotalSeconds
val rangeEnd = ZoneOffset.MAX.getTotalSeconds
Gen.choose(rangeStart, rangeEnd).map(i => ZoneOffset.ofTotalSeconds(i))
}

implicit val instantArb: Arbitrary[Instant] = Arbitrary {
Gen.choose(Long.MinValue, Long.MaxValue).map(i => Instant.ofEpochMilli(i))
}

implicit val offsetDateTimeArb: Arbitrary[OffsetDateTime] = Arbitrary {
val rangeStart = OffsetDateTime.MIN.toEpochSecond
val rangeEnd = OffsetDateTime.MAX.toEpochSecond
Gen.choose(rangeStart, rangeEnd).map(i => OffsetDateTime.ofInstant(Instant.ofEpochSecond(i), ZoneOffset.UTC))
}
}
80 changes: 80 additions & 0 deletions modules/core/src/test/scala/wen/test/Generators.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package wen.test

import org.scalacheck.{Arbitrary, Gen}
import wen.types._
import eu.timepit.refined.refineV
import wen.refine.NumericYearConstraint

object Generators {
lazy val negativeLeapYears: List[Int] = (-2 to -100000 by -2).toList.filter(x => (x % 4 == 0 && x % 100 != 0) || x % 400 == 0)

val failedYearGen: Gen[Option[Year]] =
for {
y <- Gen.negNum[Int]
e <- Gen.oneOf(BC, AD)
} yield Year.fromIntWithEpoch(y, e)

val failedDayGen: Gen[Option[Day]] =
(Arbitrary.arbitrary[Int] suchThat (x => x < Day.min || x > Day.max)).map(Day.fromInt(_))

val failedHourGen: Gen[Option[Hour]] =
(Arbitrary.arbitrary[Int] suchThat (x => x < Hour.min || x > Hour.max)).map(Hour.fromInt(_))

val failedMinuteGen: Gen[Option[Minute]] =
(Arbitrary.arbitrary[Int] suchThat (x => x < Minute.min || x > Minute.max)).map(Minute.fromInt(_))

val failedSecondGen: Gen[Option[Second]] =
(Arbitrary.arbitrary[Int] suchThat (x => x < Second.min || x > Second.max)).map(Second.fromInt(_))

val failedMillisecondGen: Gen[Option[Millisecond]] =
(Arbitrary.arbitrary[Int] suchThat (x => x < Millisecond.min || x > Millisecond.max)).map(Millisecond.fromInt(_))

val yearAsIntGen: Gen[Int] =
Gen.posNum[Int]

val invalidYearAsIntGen: Gen[Int] =
Gen.negNum[Int]

val negativeLeapYearAsIntGen: Gen[Int] =
Gen.oneOf(negativeLeapYears)

val monthAsIntGen: Gen[Int] =
Gen.choose(January.asInt, December.asInt)

val invalidMonthAsIntGen: Gen[Int] =
Arbitrary.arbitrary[Int] suchThat (x => x < January.asInt || x > December.asInt)

val dayAsIntGen: Gen[Int] =
Gen.choose(Day.min, Day.max)

val invalidDayAsIntGen: Gen[Int] =
Arbitrary.arbitrary[Int] suchThat (x => x < Day.min || x > Day.max)

val hourAsIntGen: Gen[Int] =
Gen.choose(Hour.min, Hour.max)

val invalidHourAsIntGen: Gen[Int] =
Arbitrary.arbitrary[Int] suchThat (x => x < Hour.min || x > Hour.max)

val minuteAsIntGen: Gen[Int] =
Gen.choose(Minute.min, Minute.max)

val invalidMinuteAsIntGen: Gen[Int] =
Arbitrary.arbitrary[Int] suchThat (x => x < Minute.min || x > Minute.max)

val secondAsIntGen: Gen[Int] =
Gen.choose(Second.min, Second.max)

val invalidSecondAsIntGen: Gen[Int] =
Arbitrary.arbitrary[Int] suchThat (x => x < Second.min || x > Second.max)

val millisecondAsIntGen: Gen[Int] =
Gen.choose(Millisecond.min, Millisecond.max)

val invalidMillisecondAsIntGen: Gen[Int] =
Arbitrary.arbitrary[Int] suchThat (x => x < Millisecond.min || x > Millisecond.max)

val yearWithDefaultEpochGen: Gen[Year] =
Gen.posNum[Int].map(i => Year(refineV[NumericYearConstraint].unsafeFrom(i)))

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 45a5e4a

Please sign in to comment.