From 8f6efc57934d520e5a12acd0a6aff04dd73892c1 Mon Sep 17 00:00:00 2001 From: "sergei.winitzki" Date: Wed, 22 Nov 2023 22:39:50 +0100 Subject: [PATCH] one more solution --- README.md | 1 + .../scala/sofp/unit/Exercises_2_1_7.scala | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 chapter02/src/test/scala/sofp/unit/Exercises_2_1_7.scala diff --git a/README.md b/README.md index f02b235..8c6d574 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,4 @@ To reformat code, run the script: `bash reformat_all_code.sh` +Run this command before pushing any code changes. If formatting is not applied, builds will fail. diff --git a/chapter02/src/test/scala/sofp/unit/Exercises_2_1_7.scala b/chapter02/src/test/scala/sofp/unit/Exercises_2_1_7.scala new file mode 100644 index 0000000..92d3adb --- /dev/null +++ b/chapter02/src/test/scala/sofp/unit/Exercises_2_1_7.scala @@ -0,0 +1,22 @@ +package sofp.unit + +import com.eed3si9n.expecty.Expecty.expect +import munit.FunSuite + +class Exercises_2_1_7 extends FunSuite { + + test("exercise 2.1.7.1") { + + val allPairs = + (0 to 9).flatMap { i => + (0 to 9).map { j => + (i, j) + } + } + val filteredPairs = allPairs.filter { case (i, j) => i + 4 * j > i * j } + + expect(filteredPairs.take(4) == Seq((0, 1), (0, 2), (0, 3), (0, 4))) + expect(filteredPairs.length == 64) + } + +}