-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
274 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
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.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
File renamed without changes.