-
Notifications
You must be signed in to change notification settings - Fork 347
Restructure and document First/Last and Min/Max #578
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
Conversation
b2f31b0 to
eb33436
Compare
sritchie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments on what I've got so far.
| implicit def semigroup[T](implicit ord: Ordering[T]): Semigroup[Max[T]] = | ||
| Semigroup.from[Max[T]] { (l, r) => if (ord.gteq(l.get, r.get)) l else r } | ||
|
|
||
| implicit def ordering[T](implicit ord: Ordering[T]): Ordering[Max[T]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, these gets ordering instances as well.
| import org.scalacheck.Arbitrary.{ arbitrary => getArbitrary } | ||
| import Gen.oneOf | ||
|
|
||
| trait ExpHistGen { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think of this style, vs jamming everything into a single file?
| class CollectionSpecification extends CheckProperties { | ||
| import com.twitter.algebird.BaseProperties._ | ||
|
|
||
| implicit def arbMin[T: Arbitrary]: Arbitrary[Min[T]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to Arbitrary.scala`
| implicit def arbAndVal: Arbitrary[AndVal] = | ||
| Arbitrary { implicitly[Arbitrary[Boolean]].arbitrary.map{ b => AndVal(b) } } | ||
|
|
||
| property("MinSemigroup is a commutative semigroup") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved into Min and Max tests
| } | ||
| } | ||
|
|
||
| object ExpHistGenerators { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to ExpHistInstances.scala in the scalacheck package
|
|
||
| case class PosNum[T: Numeric](value: T) | ||
|
|
||
| object PosNum { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this is moved to Gen.scala and Arbitrary.scala
| object Generators { | ||
| // The new scalacheck oneOf results in diverging implicits here | ||
| // should follow up an investigation? | ||
| def oneOf[T](g1: Gen[T], g2: Gen[T], gs: Gen[T]*) = for { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I managed to get rid of this diverging implicit expansion by adding a [T] parameter onto the intervalArb sub-generators.
| } | ||
|
|
||
| property("Max[Long] is a commutative monoid") { | ||
| commutativeMonoidLaws[Max[Long]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bumped these up to commutative monoid tests from the old monoid-only tests.
| import com.twitter.algebird.scalacheck.NonEmptyVector | ||
| import org.scalacheck.Prop.forAll | ||
|
|
||
| class MinSpec extends CheckProperties { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests work great as long as you extend CheckProperties.
|
|
||
| `First` and `Last`. | ||
|
|
||
| ## Algebraic Properties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIP!
Current coverage is 65.21% (diff: 92.30%)@@ develop #578 diff @@
==========================================
Files 111 119 +8
Lines 4572 4651 +79
Methods 4154 4221 +67
Messages 0 0
Branches 379 391 +12
==========================================
+ Hits 2946 3033 +87
+ Misses 1626 1618 -8
Partials 0 0
|
| } | ||
| } | ||
|
|
||
| property("Last.aggregator returns the first item") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @sritchie,
I was just checking this pr. I think the above statement meant to be ".. last item".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thank you @morazow! I'll make the change tomorrow when I add the actual documentation updates.
| implicit def semigroup[T]: Semigroup[First[T]] = new Semigroup[First[T]] { | ||
| def plus(l: First[T], r: First[T]): First[T] = l | ||
|
|
||
| override def sumOption(iter: TraversableOnce[First[T]]): Option[First[T]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be more efficient.
| 0 | ||
| } | ||
|
|
||
| implicit def vectorMonoid[T: Ordering]: Monoid[Max[Vector[T]]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed cats here by only implementing this for Stream and Vector in addition to list.
|
Closed in favor of #529 |
This PR:
Gen.scalawith generators for Algebird data structuresArbitrary.scalawith arbitrary instances for Algebird data structuresInterval,First,Last,Min,MaxandExpHistinto these objectsOrderedSemigroup.scalainto their own files+operator to min, max, first, lastminoperator toMinandmaxoperator toMaxFirstAggregatorandLastAggregatorMonoid[Max[Vector[T]]]andMonoid[Max[Stream[T]]]tut-based documentation for first, last, min and max.This sets up the structure I need for upcoming documentation PRs. With each PR I'd like to spruce up each data structure, move its tests into its own file, get the documentation looking good and add arbitrary and gen instances to
GenandArbitrary.Following PRs should be smaller now that the structure for this is in place.