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

Scala 2.12 support #16

Merged
merged 3 commits into from
Mar 21, 2017
Merged

Scala 2.12 support #16

merged 3 commits into from
Mar 21, 2017

Conversation

gkk-stripe
Copy link
Contributor

Check individual commits for details.

I tested it by running + test (that runs tests for all Scala versions).

Latest versions of scalacheck got stricter and would fail for
Gen.choose(0, SOME NEGATIVE NUMBER)

I found this problem while upgrading bonsai to Scala 2.12.
I bumped scalatest and scalacheck to versions that support Scala 2.12
(in addition to Scala 2.10 and 2.11).
@@ -18,7 +18,7 @@ class IndexedBitSetSpec extends WordSpec with Matchers with Checkers {

implicit val arbitraryBitSetWithIndex: Arbitrary[BitSetWithIndex] =
Arbitrary(for {
len <- arbitrary[Short].map(_.toInt)
len <- arbitrary[Short].map(_.toInt) if len > 0

Choose a reason for hiding this comment

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

should this not be >= 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. Fixed.

@thomas-stripe
Copy link
Contributor

LGTM!

@@ -18,7 +18,7 @@ class IndexedBitSetSpec extends WordSpec with Matchers with Checkers {

implicit val arbitraryBitSetWithIndex: Arbitrary[BitSetWithIndex] =
Arbitrary(for {
len <- arbitrary[Short].map(_.toInt)
len <- arbitrary[Short].map(_.toInt) if len >= 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we instead change this to something like the following?

arbitrary[Short].map(_ & 0xffff)

This way we get a non-negative value without any filtering (which I think is best to avoid when possible).

Choose a reason for hiding this comment

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

don't you mean _ & 0x7fff to make sure it is >=0?

Copy link
Contributor

Choose a reason for hiding this comment

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

0xffff is a positive Int (65535); that map changes the type as well as the value.

Choose a reason for hiding this comment

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

ahh, yeah. We are resulting in an Int.

So, in that case, I don't like _ & 0xffff because all negative numbers are mapped to 65535, so half the time we might see a really big list. I think we are better off with:
x => if(x < 0) -(x.toInt) else x

Copy link
Contributor

@erik-stripe erik-stripe Mar 15, 2017

Choose a reason for hiding this comment

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

@johnynek That's not quite true either.

scala> 0xffff
res0: Int = 65535

scala> Short.MinValue & 0xffff
res1: Int = 32768

scala> (Short.MinValue + 100) & 0xffff
res2: Int = 32868

scala> (Short.MinValue + 10000) & 0xffff
res3: Int = 42768

But I am fine with any of these approaches that remove the if.

Choose a reason for hiding this comment

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

yeah, I'm an idiot. Sorry for the goof up. It should be uniformly distributed if the input is uniform.

@gkk-stripe
Copy link
Contributor Author

Given this lgtmed, I'll go ahead and merge.

@gkk-stripe gkk-stripe merged commit 05cabb5 into master Mar 21, 2017
@gkk-stripe gkk-stripe deleted the gkk-scala-2.12-support branch March 21, 2017 00:05
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