-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Abhijit Sarkar
committed
Jan 11, 2025
1 parent
97de6b9
commit a503125
Showing
95 changed files
with
729 additions
and
633 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.12.4 | ||
0.12.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
bintree/test/src/P55Suite.scala → bintree/test/src/P55Spec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
bintree/test/src/P56Suite.scala → bintree/test/src/P56Spec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
12 changes: 7 additions & 5 deletions
12
bintree/test/src/P57Suite.scala → bintree/test/src/P57Spec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
7 changes: 4 additions & 3 deletions
7
bintree/test/src/P58Suite.scala → bintree/test/src/P58Spec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
bintree/test/src/P61ASuite.scala → bintree/test/src/P61ASpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
10 changes: 6 additions & 4 deletions
10
bintree/test/src/P61Suite.scala → bintree/test/src/P61Spec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.