Skip to content

Commit

Permalink
Merge pull request #13 from KamchatkaLtd/scala-2.12
Browse files Browse the repository at this point in the history
Move to Scala 2.12
  • Loading branch information
alf239 authored May 4, 2019
2 parents 434de67 + 95ac1ba commit 9d4a5bf
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: scala
scala:
- 2.11.7
- 2.11.8
- 2.12.8

script:
- sbt clean coverage test
Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name := "prio_queues"

version := "1.0"

scalaVersion := "2.11.7"
scalaVersion := "2.12.8"

libraryDependencies ++= Seq(
"org.specs2" %% "specs2-core" % "3.5" % "test",
"org.specs2" %% "specs2-scalacheck" % "3.5" % "test"
"org.specs2" %% "specs2-core" % "4.3.4" % "test",
"org.specs2" %% "specs2-scalacheck" % "4.3.4" % "test"
)

resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
Expand Down
4 changes: 3 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.1.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")

addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.2")
4 changes: 2 additions & 2 deletions src/main/scala/okasaki/misc/Exercises.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package okasaki.misc

/**
* Copyright (C) 2015 Kamchatka Ltd
* Copyright (C) 2015-2019 Kamchatka Ltd
*/
object Exercises {

Expand All @@ -21,7 +21,7 @@ object Exercises {
}

// ex 2.5b
def almostComplete[E](x: E, n: Int) = {
def almostComplete[E](x: E, n: Int): BinaryTree[E] = {
def create2(x: E, m: Int): (BinaryTree[E], BinaryTree[E]) = m match {
case 0 => (Empty, SubBinaryTree(Empty, x, Empty))
case mm if mm > 0 =>
Expand Down
27 changes: 17 additions & 10 deletions src/test/scala/okasaki/RandomAccessListSpec.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package okasaki

import org.scalacheck.Arbitrary
import org.scalacheck.{Arbitrary, Gen}
import org.scalacheck.Arbitrary._
import org.scalacheck.Gen.choose
import org.specs2.ScalaCheck
import org.specs2.mutable.Specification

/**
* Copyright (C) 2015 Kamchatka Ltd
* Copyright (C) 2015-2019 Kamchatka Ltd
*/
abstract class RandomAccessListSpec[E, RL, RAL <: RandomAccessList[E, RL]](val list: RAL)
extends Specification with ScalaCheck {
Expand Down Expand Up @@ -51,13 +51,14 @@ abstract class RandomAccessListSpec[E, RL, RAL <: RandomAccessList[E, RL]](val l
}

"Random update is non-breaking" ! prop {
(xs: ListWithTwoIndices, e: E) => xs.distinct ==> {
val ListWithTwoIndices(l, i, j) = xs
(xs: ListWithTwoIndices, e: E) =>
xs.distinct ==> {
val ListWithTwoIndices(l, i, j) = xs

val xs1 = list.update(i, e, fromList(l))
val xs1 = list.update(i, e, fromList(l))

list.lookup(j, xs1) === l(j)
}
list.lookup(j, xs1) === l(j)
}
}
}

Expand All @@ -71,13 +72,19 @@ abstract class RandomAccessListSpec[E, RL, RAL <: RandomAccessList[E, RL]](val l
lazy implicit val listWithIndex: Arbitrary[ListWithIndex] =
Arbitrary(for {
xs <- arbitrary[List[E]]
i <- choose(0, xs.size - 1)
if xs.nonEmpty
i <- indexOf(xs)
} yield ListWithIndex(xs, i))

lazy implicit val listWithTwoDistinctIndexes: Arbitrary[ListWithTwoIndices] =
Arbitrary(for {
xs <- arbitrary[List[E]]
i <- choose(0, xs.size - 1)
j <- choose(0, xs.size - 1)
if xs.length >= 2
i <- indexOf(xs)
j <- indexOf(xs)
if i != j
} yield ListWithTwoIndices(xs, i, j))

private def indexOf(xs: List[E]): Gen[Int] =
choose(0, Math.max(0, xs.size - 1))
}
12 changes: 8 additions & 4 deletions src/test/scala/okasaki/heaps/HeapWithDeletionSpec.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package okasaki.heaps

import okasaki.{HeapSpec, HeapWithDeletion, IntElements}
import org.scalacheck.Arbitrary
import org.scalacheck.{Arbitrary, Gen}
import org.scalacheck.Arbitrary._
import org.scalacheck.Gen._

/**
* Copyright (C) 2015 Kamchatka Ltd
* Copyright (C) 2015-2019 Kamchatka Ltd
*/
class HeapWithDeletionSpec
extends HeapSpec[Int, HeapWithDeletion[Int, SkewBinomialHeap[Int]]]
with IntElements {
with IntElements {

def empty = new HeapWithDeletion(new SkewBinomialHeap[Int]())

Expand Down Expand Up @@ -38,6 +38,10 @@ class HeapWithDeletionSpec
lazy implicit val listWithElement: Arbitrary[ListWithElement] =
Arbitrary(for {
xs <- arbitrary[List[Int]]
i <- choose(0, xs.size - 1)
if xs.nonEmpty
i <- indexIn(xs)
} yield ListWithElement(xs, xs(i)))

private def indexIn(xs: List[Int]): Gen[Int] =
choose(0, Math.max(0, xs.size - 1))
}
4 changes: 2 additions & 2 deletions src/test/scala/okasaki/misc/ExerciseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.specs2.ScalaCheck
import org.specs2.mutable.Specification

/**
* Copyright (C) 2015 Kamchatka Ltd
* Copyright (C) 2015-2019 Kamchatka Ltd
*/
class ExerciseSpec extends Specification with ScalaCheck {
"Complete set" should {
Expand All @@ -22,5 +22,5 @@ class ExerciseSpec extends Specification with ScalaCheck {
}
}

implicit val sizes = Arbitrary(Gen.chooseNum(0, 30))
implicit val sizes: Arbitrary[Int] = Arbitrary(Gen.chooseNum(0, 30))
}

0 comments on commit 9d4a5bf

Please sign in to comment.