Skip to content

Commit

Permalink
Replace munit with scalatest
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijit Sarkar committed Jan 11, 2025
1 parent 97de6b9 commit a503125
Show file tree
Hide file tree
Showing 95 changed files with 729 additions and 633 deletions.
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.4
0.12.5
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version = "3.8.4-RC4"
align.preset = more
maxColumn = 120
maxColumn = 100
runner.dialect = scala3
assumeStandardLibraryStripMargin = true
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package arithmetic

import munit.FunSuite
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P31Suite extends FunSuite:
class P31Spec extends AnyFunSpec:

test("determine whether a given integer is prime"):
it("determine whether a given integer is prime"):
val data = List(
(1, false),
(2, true),
Expand All @@ -16,5 +17,5 @@ class P31Suite extends FunSuite:
(11, true)
)
data.foreach { (n, prime) =>
assertEquals(P31.isPrime(n), prime, s"n=${n}")
P31.isPrime(n) shouldBe prime
}
12 changes: 12 additions & 0 deletions arithmetic/test/src/P32Spec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package arithmetic

import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P32Spec extends AnyFunSpec:

it("determine the greatest common divisor of two positive integers"):
P32.gcd(36, 63) shouldBe 9
P32.gcd(63, 36) shouldBe 9
P32.gcd(125, 81) shouldBe 1
P32.gcd(221, 559) shouldBe 13
11 changes: 0 additions & 11 deletions arithmetic/test/src/P32Suite.scala

This file was deleted.

10 changes: 10 additions & 0 deletions arithmetic/test/src/P33Spec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package arithmetic

import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P33Spec extends AnyFunSpec:

it("determine whether two positive integer numbers are coprime"):
P33.isCoprime(35, 64) shouldBe true
P33.isCoprime(1173, 1547) shouldBe false
9 changes: 0 additions & 9 deletions arithmetic/test/src/P33Suite.scala

This file was deleted.

9 changes: 9 additions & 0 deletions arithmetic/test/src/P34Spec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package arithmetic

import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P34Spec extends AnyFunSpec:

it("calculate Euler's totient function phi"):
P34.totient(10) shouldBe 4
8 changes: 0 additions & 8 deletions arithmetic/test/src/P34Suite.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package arithmetic

import munit.FunSuite
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P35Suite extends FunSuite:
class P35Spec extends AnyFunSpec:

test("determine the prime factors of a given positive integer"):
it("determine the prime factors of a given positive integer"):
val data = List(
(1, Nil),
(2, List(2)),
Expand All @@ -15,5 +16,5 @@ class P35Suite extends FunSuite:
(901255, List(5, 17, 23, 461))
)
data.foreach { (n, pf) =>
assertEquals(P35.primeFactors(n), pf)
P35.primeFactors(n) shouldBe pf
}
9 changes: 9 additions & 0 deletions arithmetic/test/src/P36Spec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package arithmetic

import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P36Spec extends AnyFunSpec:

it("construct a list containing the prime factors and their multiplicity for a given integer"):
P36.primeFactorMultiplicity(315) shouldBe Map(3 -> 2, 5 -> 1, 7 -> 1)
8 changes: 0 additions & 8 deletions arithmetic/test/src/P36Suite.scala

This file was deleted.

15 changes: 15 additions & 0 deletions arithmetic/test/src/P39Spec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package arithmetic

import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P39Spec extends AnyFunSpec:

it("construct a list of all prime numbers within a given range"):
val obtained = P39.primesInRng(7, 31)
val expected = List(7, 11, 13, 17, 19, 23, 29, 31)
obtained shouldBe expected

val obtained1 = P39.primesInRng(10, 20)
val expected1 = List(11, 13, 17, 19)
obtained1 shouldBe expected1
14 changes: 0 additions & 14 deletions arithmetic/test/src/P39Suite.scala

This file was deleted.

11 changes: 11 additions & 0 deletions arithmetic/test/src/P40Spec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package arithmetic

import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P40Spec extends AnyFunSpec:

it("find the two prime numbers that sum up to a given even integer"):
val obtained = P40.goldbach(28)
val expected = (5, 23)
obtained shouldBe expected
10 changes: 0 additions & 10 deletions arithmetic/test/src/P40Suite.scala

This file was deleted.

18 changes: 18 additions & 0 deletions arithmetic/test/src/P41Spec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package arithmetic

import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P41Spec extends AnyFunSpec:

it("find the Goldbach compositions of all even numbers within a given range"):
val obtained = P41.goldbachList(9, 20)
val expected = Map(
10 -> (3, 7),
12 -> (5, 7),
14 -> (3, 11),
16 -> (3, 13),
18 -> (5, 13),
20 -> (3, 17)
)
obtained shouldBe expected
17 changes: 0 additions & 17 deletions arithmetic/test/src/P41Suite.scala

This file was deleted.

4 changes: 2 additions & 2 deletions bintree/src/P62B.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object P62B:
def loop(tree: Tree[A], currLevel: Int, acc: List[A]): List[A] =
tree match
case Node(value, _, _) if currLevel == level => value :: acc
case Node(_, left, right) => loop(left, currLevel + 1, loop(right, currLevel + 1, acc))
case Empty => acc
case Node(_, left, right) => loop(left, currLevel + 1, loop(right, currLevel + 1, acc))
case Empty => acc

loop(t, 1, Nil)
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bintree

import munit.FunSuite
import scala.language.implicitConversions

class P55Suite extends FunSuite:
test("construct completely balanced binary trees"):
import org.scalatest.funspec.AnyFunSpec

class P55Spec extends AnyFunSpec:
it("construct completely balanced binary trees"):
val data: List[(Int, List[Array[Option[Char]]])] = List(
(0, List()),
(1, List(Tuple('x'))),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package bintree

import munit.FunSuite
import scala.language.implicitConversions
import bintree.P56.isSymmetric

class P56Suite extends FunSuite:
test("check whether a given binary tree is symmetric"):
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P56Spec extends AnyFunSpec:
it("check whether a given binary tree is symmetric"):
val data: List[(Boolean, Array[Option[Char]])] = List(
(false, ('a', 'b')),
(true, ('a', 'b', 'c'))
)

data.foreach { (symmetric, xs) =>
val tree = Tree.fromArray(xs)
assertEquals(tree.isSymmetric, symmetric)
tree.isSymmetric shouldBe symmetric
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package bintree

import munit.FunSuite
import bintree.P56.isSymmetric
import P57.addValue

class P57Suite extends FunSuite:
test("add an element to a BST"):
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P57Spec extends AnyFunSpec:
it("add an element to a BST"):
val xs = List(3, 2, 5, 7, 1)
val obtained = xs.foldLeft(Tree.empty[Int])((t, x) => t.addValue(x))
assertEquals(obtained.isSymmetric, true)
obtained.isSymmetric shouldBe true

val ys = List(3, 2, 5, 7, 4)
val obtained2 = ys.foldLeft(Tree.empty[Int])((t, x) => t.addValue(x))
assertEquals(obtained2.isSymmetric, false)
obtained2.isSymmetric shouldBe false
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bintree

import munit.FunSuite
import scala.language.implicitConversions

class P58Suite extends FunSuite:
test("construct all symmetric, completely balanced binary trees with a given number of nodes"):
import org.scalatest.funspec.AnyFunSpec

class P58Spec extends AnyFunSpec:
it("construct all symmetric, completely balanced binary trees with a given number of nodes"):
val obtained = P58.symmetricBalancedTrees(5, 'x')
val expected: List[Array[Option[Char]]] =
List(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package bintree

import munit.FunSuite
import scala.language.implicitConversions

class P59Suite extends FunSuite:
test("construct height-balanced binary trees"):
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P59Spec extends AnyFunSpec:
it("construct height-balanced binary trees"):
val obtained = P59.hbalTrees(3, 'x')
val expected: List[Array[Option[Char]]] = List(
('x', 'x', 'x', None, None, None, 'x'),
Expand All @@ -13,5 +15,5 @@ class P59Suite extends FunSuite:
('x', 'x', 'x', None, 'x')
)
expected.foreach { xs =>
assert(obtained.contains(Tree.fromArray(xs)))
obtained.contains(Tree.fromArray(xs)) shouldBe true
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package bintree

import munit.FunSuite
import scala.language.implicitConversions
import P61A.leafList

class P61ASuite extends FunSuite:
test("collect the leaves of a binary tree in a list"):
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P61ASpec extends AnyFunSpec:
it("collect the leaves of a binary tree in a list"):
val data: List[(Array[Option[Char]], List[Char])] = List(
(('x', 'x'), List('x')),
(('a', 'b', 'c', None, None, 'd', 'e'), List('b', 'd', 'e'))
)
data.foreach { (xs, expected) =>
val obtained = Tree.fromArray(xs).leafList
assertEquals(obtained, expected)
obtained shouldBe expected
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package bintree

import munit.FunSuite
import scala.language.implicitConversions
import P61.leafCount

class P61Suite extends FunSuite:
test("count the leaves of a binary tree"):
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.shouldBe

class P61Spec extends AnyFunSpec:
it("count the leaves of a binary tree"):
val data: List[(Array[Option[Char]], Int)] = List(
(('x', 'x'), 1),
(('a', 'b', 'c', None, None, 'd', 'e'), 3)
)

data.foreach { (xs, expected) =>
val obtained = Tree.fromArray(xs).leafCount
assertEquals(obtained, expected)
obtained shouldBe expected
}
Loading

0 comments on commit a503125

Please sign in to comment.