Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Granularity #7

Merged
merged 6 commits into from
Jul 21, 2016
Merged

Granularity #7

merged 6 commits into from
Jul 21, 2016

Conversation

noelmarkham
Copy link
Collaborator

This PR allows importing of a Granularity type to restrict the precision of a generated date.

The import takes the form:

import com.fortysevendeg.scalacheck.datetime.<library>.granularity.<precision>

For instance:

scala> import com.fortysevendeg.scalacheck.datetime.jdk8.GenJdk8.genZonedDateTime
import com.fortysevendeg.scalacheck.datetime.jdk8.GenJdk8.genZonedDateTime

scala> import com.fortysevendeg.scalacheck.datetime.jdk8.granularity.hours
import com.fortysevendeg.scalacheck.datetime.jdk8.granularity.hours

scala> genZonedDateTime.sample.get
res0: java.time.ZonedDateTime = +37774885-05-18T08:00+10:00[Etc/GMT-10]

scala> genZonedDateTime.sample.get
res1: java.time.ZonedDateTime = -248542497-06-04T07:00+02:10:20[Africa/Lubumbashi]

////

scala> import com.fortysevendeg.scalacheck.datetime.joda.GenJoda.genDateTime
import com.fortysevendeg.scalacheck.datetime.joda.GenJoda.genDateTime

scala> import com.fortysevendeg.scalacheck.datetime.joda.granularity.years
import com.fortysevendeg.scalacheck.datetime.joda.granularity.years

scala> genDateTime.sample.get
res2: org.joda.time.DateTime = -284169544-01-01T00:00:00.000-00:01:15

scala> genDateTime.sample.get
res3: org.joda.time.DateTime = 45241122-01-01T00:00:00.000Z

These imports are optional, not including it gives maximum precision.

This works both for the genDateTime (Joda) and genZonedDateTime (Jdk8) generators, but also on the genDateTimeWithinRange method - allowing both generation with a specific range of time, to a certain precision, for both Joda and Jdk8 setups.

Resolves #3

@codecov-io
Copy link

codecov-io commented Jul 14, 2016

Current coverage is 100% (diff: 100%)

Merging #7 into master will not change coverage

@@           master    #7   diff @@
===================================
  Files           5     8     +3   
  Lines          35    76    +41   
  Methods        35    76    +41   
  Messages        0     0          
  Branches        0     0          
===================================
+ Hits           35    76    +41   
  Misses          0     0          
  Partials        0     0          

Powered by Codecov. Last update e274989...875fcbc


val granularitiesAndPredicatesWithDefault: List[(Granularity[ZonedDateTime], ZonedDateTime => Boolean)] = (Granularity.identity[ZonedDateTime], (_: ZonedDateTime) => true) :: granularitiesAndPredicates

property("genZonedDateTime with a granularity generated appropriate ZonedDateTimes") = forAll(Gen.oneOf(granularitiesAndPredicates)) { case (granularity, predicate) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a typo? generated -> generates

@franciscodr
Copy link
Member

Minor comment. LGTM

Great job @noelmarkham!

}
}

property("genDateTimeWithinRange for Java 8 should generate ZonedDateTimes between the given date and the end of the specified Duration") = forAll(genZonedDateTime, genDuration, Gen.oneOf(granularitiesAndPredicatesWithDefault)) { case (now, d, (granularity, predicate)) =>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a picky comment, could we split these long lines into shorter ones?

@FPerezP
Copy link

FPerezP commented Jul 21, 2016

Just a couple of minor comments about long lines :) Code looks great! Thanks @noelmarkham!!

@noelmarkham
Copy link
Collaborator Author

Addressed changes, thanks

@noelmarkham noelmarkham merged commit d92009b into master Jul 21, 2016
@noelmarkham noelmarkham deleted the issue-3-granularity branch July 21, 2016 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants