Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapted to new package and some tests
- Loading branch information
Showing
12 changed files
with
124 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,2 +1,2 @@ | |||
addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.1.1", "0.13", "2.10") | addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.2.1-SNAPSHOT", "0.13", "2.10") | ||
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") | addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
package exercises | |||
|
|||
import cats.data.Xor | |||
|
|||
import shapeless._ | |||
import shapeless.ops.function._ | |||
|
|||
import org.scalacheck.{ Prop, Arbitrary } | |||
import org.scalacheck.Gen | |||
import Prop.forAll | |||
|
|||
import org.scalatest.Spec | |||
import org.scalatest.exceptions._ | |||
import org.scalatest.prop.Checkers | |||
|
|||
import org.scalacheck.Shapeless._ | |||
|
|||
object Test { | |||
|
|||
def testSuccess[F, R, L <: HList](method: F, answer: L)( | |||
implicit | |||
A: Arbitrary[L], | |||
fntop: FnToProduct.Aux[F, L ⇒ R] | |||
): Prop = { | |||
val rightGen = genRightAnswer(answer) | |||
val rightProp = forAll(rightGen)({ p ⇒ | |||
|
|||
val result = Xor.catchOnly[GeneratorDrivenPropertyCheckFailedException]({ fntop(method)(p) }) | |||
result match { | |||
case Xor.Left(exc) ⇒ exc.cause match { | |||
case Some(originalException) ⇒ throw originalException | |||
case _ ⇒ false | |||
} | |||
case _ ⇒ true | |||
} | |||
}) | |||
|
|||
val wrongGen = genWrongAnswer(answer) | |||
val wrongProp = forAll(wrongGen)({ p ⇒ | |||
Xor.catchNonFatal({ fntop(method)(p) }).isLeft | |||
}) | |||
|
|||
Prop.all(rightProp, wrongProp) | |||
} | |||
|
|||
def genRightAnswer[L <: HList](answer: L): Gen[L] = { | |||
Gen.const(answer) | |||
} | |||
|
|||
def genWrongAnswer[L <: HList](l: L)( | |||
implicit | |||
A: Arbitrary[L] | |||
): Gen[L] = { | |||
A.arbitrary.suchThat(_ != l) | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
package exercises | |||
|
|||
import fetchlib._ | |||
import shapeless.HNil | |||
|
|||
import org.scalatest.Spec | |||
import org.scalatest.prop.Checkers | |||
|
|||
import org.scalacheck.Shapeless._ | |||
|
|||
class QuickStartSpec extends Spec with Checkers { | |||
|
|||
import FetchTutorialHelper._ | |||
import UsageSection._ | |||
import Test._ | |||
|
|||
def `Creating And Running` = | |||
check(testSuccess(creatingAndRunning _, userDatabase(1) :: HNil)) | |||
|
|||
def `Sequencing Strategy` = | |||
check(testSuccess(sequencing _, (userDatabase(1), userDatabase(2)) :: 2 :: HNil)) | |||
|
|||
def `Batching Strategy` = | |||
check(testSuccess(batching _, (userDatabase(1), userDatabase(2)) :: 1 :: HNil)) | |||
|
|||
def `Deduplication Strategy` = | |||
check(testSuccess(deduplication _, (userDatabase(1), userDatabase(1)) :: 1 :: HNil)) | |||
|
|||
def `Caching Strategy` = | |||
check(testSuccess(caching _, (userDatabase(1), userDatabase(1)) :: 1 :: HNil)) | |||
|
|||
|
|||
} |