Skip to content
Snippets Groups Projects
Commit 4994e125 authored by Alexander Gehrke's avatar Alexander Gehrke
Browse files

Run migrations on tests

parent eb447bbe
No related branches found
No related tags found
No related merge requests found
Showing
with 49 additions and 68 deletions
......@@ -5,72 +5,71 @@ import testutil.PendingIfUnimplemented
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class MonoidsSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class MonoidsSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
"The addditive Int monoid" should "have the right zero element" in {
Monoids.intAddition.zero shouldBe 0
intAddition.zero shouldBe 0
}
it should "combine multiple values correctly" in {
Monoids.intAddition.op(1, 2) shouldBe 3
intAddition.combine(1, 2) shouldBe 3
}
"The multiplicative Int monoid" should "have the right zero element" in {
Monoids.intMultiplication.zero shouldBe 1
intMultiplication.zero shouldBe 1
}
it should "combine multiple values correctly" in {
Monoids.intMultiplication.op(1, 2) shouldBe 2
intMultiplication.combine(1, 2) shouldBe 2
}
"The boolean or monoid" should "have the right zero element" in {
Monoids.booleanOr.zero shouldBe false
booleanOr.zero shouldBe false
}
it should "combine multiple values correctly" in {
Monoids.booleanOr.op(false, true) shouldBe true
Monoids.booleanOr.op(false, false) shouldBe false
booleanOr.combine(false, true) shouldBe true
booleanOr.combine(false, false) shouldBe false
}
"The boolean and monoid" should "have the right zero element" in {
Monoids.booleanAnd.zero shouldBe true
booleanAnd.zero shouldBe true
}
it should "combine multiple values correctly" in {
Monoids.booleanAnd.op(false, true) shouldBe false
Monoids.booleanAnd.op(false, false) shouldBe false
Monoids.booleanAnd.op(true, true) shouldBe true
booleanAnd.combine(false, true) shouldBe false
booleanAnd.combine(false, false) shouldBe false
booleanAnd.combine(true, true) shouldBe true
}
"The option monoid" should "always return the non-empty option" in {
Monoids.optionMonoid[Int].op(Some(3), None) shouldBe Some(3)
Monoids.optionMonoid[Int].op(None, Some(3)) shouldBe Some(3)
optionMonoid[Int].combine(Some(3), None) shouldBe Some(3)
optionMonoid[Int].combine(None, Some(3)) shouldBe Some(3)
}
"The endofunction monoid" should "always give the right zero element" in {
Monoids.endoMonoid[Int].zero(3) shouldBe 3
endoMonoid[Int].zero(3) shouldBe 3
}
it should "combine the functions one way or the other" in {
Monoids.endoMonoid[Int].op(_ / 4, _ * 2)(4) shouldBe 2
endoMonoid[Int].combine(_ / 4, _ * 2)(4) shouldBe 2
}
"the foldMap implementation" should "give the right result" in {
val l = List("1", "2", "3")
Monoids.foldMap(l, new Monoid[Int] {
foldMap(l, new Monoid[Int] {
def zero = 10
def op(a: Int, b: Int) = a + b
def combine(a: Int, b: Int) = a + b
})(_.toInt) shouldBe 16
}
"the balanced foldMap implementation" should "give the right result" in {
val l = Vector("1", "2", "3")
Monoids.foldMapBalanced(l, new Monoid[Int] {
foldMapBalanced(l, new Monoid[Int] {
def zero = 0
def op(a: Int, b: Int) = a + b
def combine(a: Int, b: Int) = a + b
})(_.toInt) shouldBe 6
}
"the bag function" should "count correctly" in {
val words = "a rose is a rose".split(" ")
val words = "a rose is a rose".split(" ").toIndexedSeq
Monoids.bag(words) shouldBe Map("a" -> 2, "rose" -> 2, "is" -> 1)
bag(words) shouldBe Map("a" -> 2, "rose" -> 2, "is" -> 1)
}
}
......@@ -5,15 +5,14 @@ import testutil.PendingIfUnimplemented
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class ApplicativeSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
implicit val optionApplicative = new Applicative[Option] {
class ApplicativeSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
given optionApplicative: Applicative[Option] with
override def pure[A](a: A): Option[A] = Some(a)
override def ap[A, B](ff: Option[A => B])(fa: Option[A]): Option[B] = ff.flatMap(f => fa.map(f))
}
implicit val listApplicative = new Applicative[List] {
given listApplicative: Applicative[List] with
override def pure[A](a: A): List[A] = List(a)
override def ap[A, B](ff: List[A => B])(fa: List[A]): List[B] = ff.flatMap(f => fa.map(f))
}
"map" should "work the same when implemented via ap" in {
val f: Int => Int = i => i * 3
......@@ -36,16 +35,15 @@ class ApplicativeSpec extends AnyFlatSpec with Matchers with AppendedClues with
}
"compose" should "create nested element with pure" in {
val ola: Applicative[Lambda[a => Option[List[a]]]] = optionApplicative.compose(listApplicative)
val ola: Applicative[[a] =>> Option[List[a]]] = optionApplicative.compose(listApplicative)
ola.pure(5) shouldBe Some(List(5))
}
it should "implement map2 or ap correctly" in {
val ola: Applicative[Lambda[a => Option[List[a]]]] = optionApplicative.compose(listApplicative)
val ola: Applicative[[a] =>> Option[List[a]]] = optionApplicative.compose(listApplicative)
val optList = Some(List(1, 2, 3, 4))
ola.map(optList)(_ + 10) shouldBe Some(List(11, 12, 13, 14))
}
}
......@@ -5,7 +5,7 @@ import testutil.PendingIfUnimplemented
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class ValidatedSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class ValidatedSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
"map2" should "accumulate errors" in {
type VSI = Validated[String, Int]
val valid1: VSI = Valid(1)
......@@ -15,7 +15,7 @@ class ValidatedSpec extends AnyFlatSpec with Matchers with AppendedClues with Pe
val invalidAB: VSI = Invalid("A", List("B"))
val invalidABAB: VSI = Invalid("A", List("B", "A", "B"))
val strErrorApplicative = implicitly[Applicative[Validated[String, +?]]]
val strErrorApplicative = implicitly[Applicative[[a] =>> Validated[String, a]]]
??? //remove, when you have overridden map2 or ap
......@@ -25,4 +25,3 @@ class ValidatedSpec extends AnyFlatSpec with Matchers with AppendedClues with Pe
strErrorApplicative.map2(invalidA, invalidB)((a, b) => a + b) shouldBe invalidAB
strErrorApplicative.map2(invalidAB, invalidAB)((a, b) => a + b) shouldBe invalidABAB
}
}
......@@ -5,7 +5,7 @@ import testutil.PendingIfUnimplemented
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class ListSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class ListSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
val numbers = List(1 to 5: _*)
val single = List(1)
val strings = List("a", "b", "c")
......@@ -31,4 +31,3 @@ class ListSpec extends AnyFlatSpec with Matchers with AppendedClues with Pending
strings.foldLeft("X")(_ + _) should not be "Xcba" withClue ", this looks like a right fold with flipped args"
strings.foldLeft("X")(_ + _) shouldBe "Xabc"
}
}
......@@ -5,7 +5,7 @@ import testutil.PendingIfUnimplemented
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class EitherSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class EitherSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
val l1: Either[Int, Int] = Either.Left(1)
val l2: Either[Int, Int] = Either.Left(2)
val r1: Either[Int, Int] = Either.Right(1)
......@@ -17,5 +17,4 @@ class EitherSpec extends AnyFlatSpec with Matchers with AppendedClues with Pendi
r1.map2(r1)((a, b) => a+b) shouldBe r2
l1.map2(l2)((a, b) => a+b) shouldBe l1
}
}
......@@ -7,7 +7,7 @@ import org.scalatest.matchers.should.Matchers
import Option.{Some, None}
class OptionSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class OptionSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
"An option" should "have a map function which transforms it's content" in {
Some(3).map(_ + 1) shouldBe Some(4)
}
......@@ -33,5 +33,4 @@ class OptionSpec extends AnyFlatSpec with Matchers with AppendedClues with Pendi
Option.sequence(List(Some(1), Some(2))) shouldBe Some(List(1,2))
Option.sequence(List(Some(1), None)) shouldBe None
}
}
......@@ -5,9 +5,8 @@ import testutil.PendingIfUnimplemented
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class TeamSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class TeamSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
"getTeam" should "return both persons ore none" in {
getTeam("blar", "Dagobert") shouldBe None
getTeam("Daniel", "Dagobert") shouldBe Some((persons(2), persons(0)))
getTeam("blar", "Dagobert") shouldBe Option.None
getTeam("Daniel", "Dagobert") shouldBe Option.Some((persons(2), persons(0)))
}
}
......@@ -5,7 +5,7 @@ import testutil.PendingIfUnimplemented
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class LazyListSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class LazyListSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
import LazyList._
......@@ -36,11 +36,10 @@ class LazyListSpec extends AnyFlatSpec with Matchers with AppendedClues with Pen
}
"unfold" should "should generate lazy lists from a function while stopping on None" in {
val alphabet = unfold('a')(s => if(s <= 'z') Some((s, (s+1).toChar)) else None)
val alphabet = unfold('a')(s => if s <= 'z' then Some((s, (s+1).toChar)) else None)
alphabet.toList shouldBe ('a' to 'z').toList
}
"fibsViaUnfold" should "result in the same values as fibs without unfold" in {
fibsViaUnfold.take(10).toList shouldBe fibs.take(10).toList
}
}
......@@ -5,7 +5,7 @@ import testutil.PendingIfUnimplemented
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class MonadFunctorSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class MonadFunctorSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
"functorFromMonad" should "return a working functor" in {
Functor.functorFromMonad[Option](new Monad[Option] {
def pure[A](a: A): Option[A] = Some(a)
......@@ -13,4 +13,3 @@ class MonadFunctorSpec extends AnyFlatSpec with Matchers with AppendedClues with
fa.flatMap(f)
}).map[Int, String](Some(3))(_.toString) shouldBe Some("3")
}
}
......@@ -5,7 +5,7 @@ import testutil.PendingIfUnimplemented
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class MonadSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class MonadSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
"map2" should "combine two monadic values" in {
tupleMonad.map2(Tuple1(1), Tuple1(2))((a, b) => a + b) shouldBe Tuple1(3)
}
......@@ -30,4 +30,3 @@ class MonadSpec extends AnyFlatSpec with Matchers with AppendedClues with Pendin
def flatMap[A, B](fa: Tuple1[A])(f: A => Tuple1[B]): Tuple1[B] =
f(fa._1)
}
}
......@@ -14,7 +14,7 @@ class AddressParserSpec extends AnyFlatSpec with Matchers with AppendedClues wit
}
it should "not accept other formats" in {
for {
for
wrong <- List(
"Hublandstraße 123 97074 Würzburg",
"Hublandstraße Abc, 97074 Würzburg",
......@@ -22,8 +22,7 @@ class AddressParserSpec extends AnyFlatSpec with Matchers with AppendedClues wit
"Hublandstraße123,97074Würzburg",
"",
)
} {
do
address.parse(wrong) should matchPattern { case Fail(_,_) => }
}
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ import testutil.PendingIfUnimplemented
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class RandomSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class RandomSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
val initial = Simple(192837465L)
val (r1, i1) = initial.nextInt
val (r2, i2) = r1.nextInt
......@@ -17,4 +17,3 @@ class RandomSpec extends AnyFlatSpec with Matchers with AppendedClues with Pendi
it should "result in the same rng state as passing state manually" in {
Randoms.threeInts.run(initial)._1 shouldBe r3
}
}
......@@ -6,7 +6,7 @@ import java.time.LocalDate
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class ReaderSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class ReaderSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
val exampleRequest = Request(
Some("Mister X"),
"de-DE",
......@@ -29,5 +29,4 @@ class ReaderSpec extends AnyFlatSpec with Matchers with AppendedClues with Pendi
"sayBye" should "contain the correct user name and date" in {
Readers.sayBye.run(exampleRequest) shouldBe "Goodbye Mister X, today is 2019-06-26"
}
}
......@@ -7,7 +7,7 @@ import testutil.PendingIfUnimplemented
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class WriterSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class WriterSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
"collatzDepth" should "keep a log of the search" in {
val (log, _) = Writers.collatzDepth(3).v
log shouldBe List(
......@@ -55,5 +55,4 @@ class WriterSpec extends AnyFlatSpec with Matchers with AppendedClues with Pendi
val (_, res) = Writers.collatzSearch(1, 5).v
res shouldBe 3
}
}
......@@ -6,10 +6,8 @@ import org.scalatest._
* Mix into a test suite to mark tests for ??? methods as "pending" instead of "failed"
*/
trait PendingIfUnimplemented extends TestSuiteMixin { this: TestSuite =>
abstract override def withFixture(test: NoArgTest): Outcome = {
super.withFixture(test) match {
abstract override def withFixture(test: NoArgTest): Outcome =
super.withFixture(test) match
case Failed(_: NotImplementedError) => Pending
case other => other
}
}
}
......@@ -6,8 +6,7 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
@SuppressWarnings(Array("org.wartremover.warts.All"))
class FunctorSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class FunctorSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
"The Functor instance for Option" should "be available in implicit scope" in {
"implicitly[Functor[Option]]" should compile
}
}
......@@ -6,7 +6,7 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
@SuppressWarnings(Array("org.wartremover.warts.All"))
class ShowSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
class ShowSpec extends AnyFlatSpec with Matchers with AppendedClues with PendingIfUnimplemented:
"The Show instance for Person" should "be available in implicit scope" in {
"implicitly[Show[Person]]" should compile
}
......@@ -15,4 +15,3 @@ class ShowSpec extends AnyFlatSpec with Matchers with AppendedClues with Pending
// uncomment as soon as you pass the above test
//implicitly[Show[Person]].show(People.odersky) shouldBe "Martin Odersky is 60 years old"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment