Skip to content

Commit

Permalink
Merge pull request #57 from winitzki/feature/test-with-scala-3
Browse files Browse the repository at this point in the history
add scala 3.3.3 and 3.4.0 to tests
  • Loading branch information
winitzki authored Mar 18, 2024
2 parents 6bcde47 + 5271624 commit 5e1ae78
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ jobs:
java:
- '17.0.9'
scala:
- '2.13.11'
- '2.13.13'
- '3.3.3'
- '3.4.0'
checks:
name: Check formatting
runs-on: ubuntu-latest
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Files under `worksheets/` may be arbitrary Scala code, not made into a test.

Run the command `bash run_sbt.sh test` in order to verify all solutions. This will create temporary solution files in each chapter.

To compile the code with all supported Scala versions, run `bash run_sbt.sh +test:compile` (just to compile under all Scala versions) or `bash run_sbt.sh +test` for full testing.

# Code formatting

The GitHub job will verify that all code is properly formatted.
Expand All @@ -23,3 +25,8 @@ To reformat code, run the script:
`bash reformat_all_code.sh`

Run this command before pushing any code changes in the test code. If formatting is not applied, builds will fail.

# Configure the build

The GitHub build is configured via the Dhall file [github-scala-build-and-test.dhall](./github-scala-build-and-test.dhall).
After changing that file, run `bash ./update_github_actions.sh` and commit changes in the Yaml file [build-and-test.yml](./.github/workflows/build-and-test.yml).
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val scala2V = "2.13.11"
val scala3V = "3.3.1"
val scala2V = "2.13.13"
val scala3V = "3.3.3"
val scalaV = scala2V

val munitTest = "org.scalameta" %% "munit" % "0.7.29" % Test
Expand Down
2 changes: 1 addition & 1 deletion chapter01/worksheets/solution1.1.1.1_as_object_AR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object MyFactorial {
def myFactorial(a: Int): Int = {
(1 to a).foldRight(1)(_ * _)
}
def main(args: Array[String]) {
def main(args: Array[String]) = {
val expected = 3628800
val result = this.myFactorial(10)
println("result: %s".format(result))
Expand Down
2 changes: 1 addition & 1 deletion chapter01/worksheets/solution1.6.2.3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ that function.
def is3Factor(n: Int): Boolean = {
val q = (2 to n-1)
val r = q.filter(y => (n != y) && (n % y == 0))
(r.length == 3)
r.length == 3
}

def nestedIs3Factor(f: (Int => Boolean)): List[Int] = {
Expand Down
2 changes: 1 addition & 1 deletion chapter02/src/test/scala/sofp/unit/Exercises_2_1_7.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Exercises_2_1_7 extends FunSuite {
val names: List[String] = List("Joe", "Bob", "Mary")
val a: List[Boolean] = List(true, false, true)
val b: List[(String, Boolean)] = names.zip(a)
val c: List[Any] = b.map { case (x, y) => if (y == true) x }
val c: List[Any] = b.map { case (x, y) => if (y == true) x else () }
val d: List[Any] = c.filter(_ != (()))
expect(d == List("Joe", "Mary"))
}
Expand Down
2 changes: 1 addition & 1 deletion chapter02/worksheets/solution2.1.7.10_object_main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object LargestTree {
def largestTree(a: Seq[List[Int]]): Seq[List[Int]] = {
a.map{ k=>k.sortBy(k=>(-k))}.map{ k => k.take(3) }
}
def main(args: Array[String]) {
def main(args: Array[String]) = {
val expected = Seq(List(50, 30, 10), List(100), List(200, 20, 2))
val result = this.largestTree(Seq(List(50, 30, 10), List(100), List(200, 20, 2)))
assert(result == expected)
Expand Down
2 changes: 1 addition & 1 deletion chapter02/worksheets/solution2.1.7.3_AR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Given two sequences p: Seq[String] and q: Seq[Boolean] of equal length, compute
Seq[String] with those elements of p for which the corresponding element of q is true.
Hint: use zip, map, filter. */

val result = Seq("Joe", "Bob", "Mary").zip(Seq(true, false, true)).map { case (x, y) => if (y == true) x }.filter(_ != (())).map{ case x => x.toString }
val result = Seq("Joe", "Bob", "Mary").zip(Seq(true, false, true)).map { case (x, y) => if (y == true) x else () }.filter(_ != (())).map{ case x => x.toString }
assert(result == List("Joe", "Mary"))

// scala> :load solution2.1.7.3_AR.scala
Expand Down
2 changes: 1 addition & 1 deletion chapter02/worksheets/solution2.1.7.4_AR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ val a = Seq[Int](1, 3, 2, 4)
val b = a.last
val c: Seq[(Int, Boolean)] = Seq((b, false))
// val c = List(b, false)
val d: Seq[(Int, Boolean)] = Seq[Int](1, 3, 2, 4).sliding(2).toList.map{ case List(x, y) => if (x < y) (x, true) else (x, false)}
val d: Seq[(Int, Boolean)] = Seq[Int](1, 3, 2, 4).sliding(2).toList.map{ case Seq(x, y) => if (x < y) (x, true) else (x, false)}
val result = d ++ c

val expected: Seq[(Int, Boolean)] = List((1,true), (3,false), (2,true), (4,false))
Expand Down
2 changes: 1 addition & 1 deletion chapter02/worksheets/solution2.1.7.4_as_function_AR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def followedByGreater(a: Seq[Int]): Seq[(Int, Boolean)] = {
val b = a.last
val c: Seq[(Int, Boolean)] = Seq((b, false))
val d: Seq[(Int, Boolean)] = a.sliding(2).toList.map{ case List(x, y) => if (x < y) (x, true) else (x, false)}
val d: Seq[(Int, Boolean)] = a.sliding(2).toList.map{ case Seq(x, y) => if (x < y) (x, true) else (x, false)}
val e = d ++ c
e
}
Expand Down
2 changes: 1 addition & 1 deletion chapter02/worksheets/solution2.1.7.9_object_main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object TotalCount {
def totalCount(a: Seq[(String, Int)]): Map[String, Int] = {
a.groupBy(s => s._1).map { case (x, y) => (x, y.map(_._2).sum) }
}
def main(args: Array[String]) {
def main(args: Array[String]) = {
val expected = Map("apple" -> 10, "pear" -> 3, "lemon" -> 2)
val result = this.totalCount(Seq(("apple", 2), ("pear", 3), ("apple", 5), ("lemon", 2), ("apple", 3)))
assert(result == expected)
Expand Down
2 changes: 1 addition & 1 deletion github-scala-build-and-test.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let matrix =
-- "8.0.382",
-- "11.0.21",
"17.0.9",
], scala = [ "2.13.11" ] }
], scala = [ "2.13.13", "3.3.3", "3.4.0", ] }

let setup =
[ GithubActions.steps.actions/checkout // { `with` = Some (toMap { submodules = "true" }) }
Expand Down

0 comments on commit 5e1ae78

Please sign in to comment.