diff --git a/src/test/scala/algebra/MonoidsSpec.scala b/src/test/scala/algebra/MonoidsSpec.scala index 9c5646ddee758f1a79a96cb35d2d8a52c0303ebc..06264a9994630e75551d0f571ccd09bc013ce0ae 100644 --- a/src/test/scala/algebra/MonoidsSpec.scala +++ b/src/test/scala/algebra/MonoidsSpec.scala @@ -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) } -} diff --git a/src/test/scala/applicative/ApplicativeSpec.scala b/src/test/scala/applicative/ApplicativeSpec.scala index 35fb1656c749a7b73632baeec694a3ca3f70d49e..99368624b469c40b87b038fdfa114f9344d00fd5 100644 --- a/src/test/scala/applicative/ApplicativeSpec.scala +++ b/src/test/scala/applicative/ApplicativeSpec.scala @@ -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)) } -} diff --git a/src/test/scala/applicative/ValidatedSpec.scala b/src/test/scala/applicative/ValidatedSpec.scala index ba850f5d38c1bc55ba34c7ea70005de2b136a160..a9188c0006156feb96edb5d07f8ca98c0e8a2fd8 100644 --- a/src/test/scala/applicative/ValidatedSpec.scala +++ b/src/test/scala/applicative/ValidatedSpec.scala @@ -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 } -} diff --git a/src/test/scala/datastructures/ListSpec.scala b/src/test/scala/datastructures/ListSpec.scala index f067becc0ff6373c7da0bf756a0d78030883dd4f..e472122f9d47f2e2cbfa2f00fd2484a16040e66e 100644 --- a/src/test/scala/datastructures/ListSpec.scala +++ b/src/test/scala/datastructures/ListSpec.scala @@ -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" } -} diff --git a/src/test/scala/errors/EitherSpec.scala b/src/test/scala/errors/EitherSpec.scala index 3b263a29dc2bcefc08325115e43de9f571035d6d..85c9055a21d69c16d7d684e90154d51f3d722582 100644 --- a/src/test/scala/errors/EitherSpec.scala +++ b/src/test/scala/errors/EitherSpec.scala @@ -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 } -} diff --git a/src/test/scala/errors/OptionSpec.scala b/src/test/scala/errors/OptionSpec.scala index c079f62c5147dd8c340e11d3902cc184b94e5261..02c1ace6c6a79cf773234a91d64ac5d09a2f3ab1 100644 --- a/src/test/scala/errors/OptionSpec.scala +++ b/src/test/scala/errors/OptionSpec.scala @@ -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 } -} diff --git a/src/test/scala/errors/TeamSpec.scala b/src/test/scala/errors/TeamSpec.scala index da5536d3ce13f2039ffc8a4c2b4bcb95ff927611..e2910442103849a64fd396b5b2057294cdacda65 100644 --- a/src/test/scala/errors/TeamSpec.scala +++ b/src/test/scala/errors/TeamSpec.scala @@ -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))) } -} diff --git a/src/test/scala/laziness/LazyListSpec.scala b/src/test/scala/laziness/LazyListSpec.scala index 77eb647e7ab9f0cebde286f29edbf31976ff027c..b1264e7c8fa3a352a83703f815eb33b46e764edd 100644 --- a/src/test/scala/laziness/LazyListSpec.scala +++ b/src/test/scala/laziness/LazyListSpec.scala @@ -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 } -} diff --git a/src/test/scala/monads/MonadFunctorSpec.scala b/src/test/scala/monads/MonadFunctorSpec.scala index e3be0ff0fa73c51d8d286b370efeb8c39c2da960..03d05a3f83f53df80723dc1c2fe77ff0e56a67dd 100644 --- a/src/test/scala/monads/MonadFunctorSpec.scala +++ b/src/test/scala/monads/MonadFunctorSpec.scala @@ -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") } -} diff --git a/src/test/scala/monads/MonadSpec.scala b/src/test/scala/monads/MonadSpec.scala index 15fd1d6f7dedb534daf33bbb6898bf3984ab63e3..e806cba79290494db45042e2787c153f3b81f515 100644 --- a/src/test/scala/monads/MonadSpec.scala +++ b/src/test/scala/monads/MonadSpec.scala @@ -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) } -} diff --git a/src/test/scala/parsers/AddressParserSpec.scala b/src/test/scala/parsers/AddressParserSpec.scala index 0d236553fcfc844290664dff4fd723d877994d03..7a5f4f330df0016ec5959e0c971a5baba3d43981 100644 --- a/src/test/scala/parsers/AddressParserSpec.scala +++ b/src/test/scala/parsers/AddressParserSpec.scala @@ -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 diff --git a/src/test/scala/readerwriter/RandomSpec.scala b/src/test/scala/readerwriter/RandomSpec.scala index 0f062a9e31c6cfb3d35ed9208ecfa19b45248e76..9e81d54f1f7ab9195ee566fd57e65f19a8159313 100644 --- a/src/test/scala/readerwriter/RandomSpec.scala +++ b/src/test/scala/readerwriter/RandomSpec.scala @@ -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 } -} diff --git a/src/test/scala/readerwriter/ReaderSpec.scala b/src/test/scala/readerwriter/ReaderSpec.scala index 2e791094d3af9f376e17d15448d007183e4674f9..bf036ac6b2d0291476e605bd7dbb2c33db4d39ab 100644 --- a/src/test/scala/readerwriter/ReaderSpec.scala +++ b/src/test/scala/readerwriter/ReaderSpec.scala @@ -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" } -} diff --git a/src/test/scala/readerwriter/WriterSpec.scala b/src/test/scala/readerwriter/WriterSpec.scala index a9e90f9dce2c5db1b56886a5994ab6742af992ef..4c37908c3788c30d6840c2bdb64ee413ee84356a 100644 --- a/src/test/scala/readerwriter/WriterSpec.scala +++ b/src/test/scala/readerwriter/WriterSpec.scala @@ -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 } -} diff --git a/src/test/scala/testutil/PendingIfUnimplemented.scala b/src/test/scala/testutil/PendingIfUnimplemented.scala index 63f28a2b164a1d64f1ac26fddbd2b10ef3774945..e733d29f65af384e579a334deff488ecc0d86e6a 100644 --- a/src/test/scala/testutil/PendingIfUnimplemented.scala +++ b/src/test/scala/testutil/PendingIfUnimplemented.scala @@ -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 - } - } } diff --git a/src/test/scala/typeclasses/FunctorSpec.scala b/src/test/scala/typeclasses/FunctorSpec.scala index e35abbaca12a43bad847a7bdadf31dbbd018c372..7f1eee6f676117880825eb3ec4ca035875cd25b0 100644 --- a/src/test/scala/typeclasses/FunctorSpec.scala +++ b/src/test/scala/typeclasses/FunctorSpec.scala @@ -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 } -} diff --git a/src/test/scala/typeclasses/ShowSpec.scala b/src/test/scala/typeclasses/ShowSpec.scala index 760fc19f7d480beb15b5c0e20cedab6d1a0665b6..0f54756a0c81c5bf7db241aae80f2621e2fd8763 100644 --- a/src/test/scala/typeclasses/ShowSpec.scala +++ b/src/test/scala/typeclasses/ShowSpec.scala @@ -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" } -}