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

Make Chain Arbitraries recursively build concatenations #2430

Merged
merged 6 commits into from
Aug 21, 2018

Conversation

johnynek
Copy link
Contributor

forgive me @LukaJCB I wanted a direct Arbitrary that constructs in all the ways we can (empty, single, concat or fromList).

I think this current generator should create any possible chain with some probability.

@johnynek johnynek requested a review from LukaJCB August 20, 2018 15:37
LukaJCB
LukaJCB previously approved these changes Aug 20, 2018
Copy link
Member

@LukaJCB LukaJCB left a comment

Choose a reason for hiding this comment

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

Looks great, lot better than what I came up with 😁

@codecov-io
Copy link

codecov-io commented Aug 20, 2018

Codecov Report

Merging #2430 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2430      +/-   ##
==========================================
+ Coverage   95.21%   95.27%   +0.06%     
==========================================
  Files         351      351              
  Lines        6369     6350      -19     
  Branches      286      274      -12     
==========================================
- Hits         6064     6050      -14     
+ Misses        305      300       -5
Impacted Files Coverage Δ
core/src/main/scala/cats/data/Chain.scala 99.54% <100%> (+2.54%) ⬆️
...rc/main/scala/cats/laws/discipline/Arbitrary.scala 99.12% <100%> (-0.06%) ⬇️
core/src/main/scala/cats/data/NonEmptyChain.scala 97.97% <0%> (-1.02%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe409cf...27648d7. Read the comment docs.

rights.trimEnd(1)
}
// Empty is only top level, it is never internal to an Append
if (rights.nonEmpty) throw new IllegalStateException(s"found internal Empty in $this")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should we just remove this since 1. we believe this to be true, 2. we have laws to catch this. By removing entirely we improve code coverage and we possibly slightly improve performance.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah sounds good 👍

@@ -461,8 +455,8 @@ object Chain extends ChainInstances {
rights.clear()
currentIterator = seq.iterator
currentIterator.next
case Empty =>
go // This shouldn't happen
case null | Empty =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

without the null here we had a match error previously on empty.

Copy link
Member

Choose a reason for hiding this comment

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

Huh, I didn't even know you could pattern match on null 😬

@@ -505,8 +499,8 @@ object Chain extends ChainInstances {
lefts.clear()
currentIterator = seq.reverseIterator
currentIterator.next
case Empty =>
go // This shouldn't happen
case null | Empty =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

without the null here we had a match error previously on empty.

Copy link
Member

@LukaJCB LukaJCB left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@kailuowang kailuowang left a comment

Choose a reason for hiding this comment

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

Thanks!

@LukaJCB LukaJCB added this to the 1.3 milestone Aug 21, 2018
@LukaJCB
Copy link
Member

LukaJCB commented Aug 21, 2018

Ready to merge this @johnynek?

@johnynek johnynek merged commit 772bb1d into master Aug 21, 2018
catostrophe pushed a commit to catostrophe/cats that referenced this pull request Sep 15, 2018
* Make Chain Arbitraries recursively build concatenations

* check some emptyness invariants

* improve code coverage by leveraging invariants

* test next throws the right exception

* remove runtime check

* make Chain iterators private
@larsrh larsrh deleted the oscar/simplify_chain_arb branch October 5, 2019 12:53
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