Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.10.3
81d252764a9ec8ad342504ba443ec1305f932f27
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "3.5.9"
version = "3.10.3"
runner.dialect = scala3
24 changes: 12 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
val Http4sVersion = "1.0.0-M38"
val Http4sScalaXmlVersion = Http4sVersion + ".1"
val Specs2Version = "5.0.7"
val Http4sVersion = "1.0.0-M38"
val Http4sScalaXmlVersion = Http4sVersion + ".1"
val Specs2Version = "5.0.7"
val CatsEffectTestingSpecs2Version = "1.7.0"
val LogbackVersion = "1.5.18"
val JAnsiVersion = "2.4.2"
val LogbackVersion = "1.5.18"
val JAnsiVersion = "2.4.2"

lazy val root = (project in file("."))
.settings(
Expand All @@ -12,13 +12,13 @@ lazy val root = (project in file("."))
version := "0.0.4-SNAPSHOT",
scalaVersion := "3.7.3",
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-blaze-server" % Http4sVersion,
"org.http4s" %% "http4s-blaze-client" % Http4sVersion,
"org.http4s" %% "http4s-dsl" % Http4sVersion,
"org.http4s" %% "http4s-scala-xml" % Http4sScalaXmlVersion,
"ch.qos.logback" % "logback-classic" % LogbackVersion,
"org.fusesource.jansi" % "jansi" % JAnsiVersion,
"org.typelevel" %% "cats-effect-testing-specs2" % CatsEffectTestingSpecs2Version % Test
"org.http4s" %% "http4s-blaze-server" % Http4sVersion,
"org.http4s" %% "http4s-blaze-client" % Http4sVersion,
"org.http4s" %% "http4s-dsl" % Http4sVersion,
"org.http4s" %% "http4s-scala-xml" % Http4sScalaXmlVersion,
"ch.qos.logback" % "logback-classic" % LogbackVersion,
"org.fusesource.jansi" % "jansi" % JAnsiVersion,
"org.typelevel" %% "cats-effect-testing-specs2" % CatsEffectTestingSpecs2Version % Test
),
scalacOptions ++= Seq(
"-deprecation",
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ val DEFAULT_PORT = "8080"

object Main extends IOApp:
def run(args: List[String]): IO[ExitCode] =
val port = sys.props.getOrElse("server.port", sys.env.getOrElse("PORT", DEFAULT_PORT)).toInt
val port = sys.props
.getOrElse("server.port", sys.env.getOrElse("PORT", DEFAULT_PORT))
.toInt
BlazeServerBuilder[IO]
.bindHttp(port, "0.0.0.0")
.withHttpApp(PrimeCheckerApp.app)
Expand Down
9 changes: 3 additions & 6 deletions src/main/scala/PrimeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package edu.luc.etl.cs433.laufer.primenumbers

object PrimeChecker:
def isPrime(i: BigInt): Boolean =
if i < 2 then
false
else if i == 2 then
true
else if i % 2 == 0 then
false
if i < 2 then false
else if i == 2 then true
else if i % 2 == 0 then false
else
val sqroot = BigInt(Math.sqrt(i.toDouble).toLong)
var k = BigInt(3)
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/PrimeCheckerApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ object PrimeCheckerApp:
case GET -> Root / LongVar(number) =>
if PrimeChecker.isPrime(BigInt(number)) then
Ok(s"Yay, $number happens to be a prime!")
else
NotFound(s"Bummer, $number is not a prime.")
else NotFound(s"Bummer, $number is not a prime.")

val app: HttpApp[IO] = routes.orNotFound
end PrimeCheckerApp
13 changes: 7 additions & 6 deletions src/test/scala/PrimeCheckerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import org.specs2.matcher.{DataTables, MatchResult}
class PrimeCheckerSpec extends Specification with DataTables with CatsEffect:

"PrimeChecker method works for values in table" >> (
primeTable |> (
(number, result) =>
PrimeChecker.isPrime(BigInt(number)) must_== result
primeTable |> ((number, result) =>
PrimeChecker.isPrime(BigInt(number)) must_== result
)
)

"PrimeChecker service works for values in table" >> (
primeTable |> (
(number, result) =>
serviceReturnsStatus(number, if result then Status.Ok else Status.NotFound)
primeTable |> ((number, result) =>
serviceReturnsStatus(
number,
if result then Status.Ok else Status.NotFound
)
)
)

Expand Down