diff --git a/src/main/scala/main/Main.scala b/src/main/scala/main/Main.scala index d03eeb9..743084f 100644 --- a/src/main/scala/main/Main.scala +++ b/src/main/scala/main/Main.scala @@ -2,21 +2,42 @@ package main import Ops.* import Tests.* -import tools.* + import java.time.Instant +import zio._ -object Torque { - @main - def main(args: String*): Unit = { println("\u001b[2J\u001b[H") - println("--- TORQUE STRESS TESTING UTILITY ---") +/* + * *> = "Then" (think arrow pointing to what matters) + * <&> = "Both" (symbol looks like things going in both directions) + * <* = "Keep left" (pointing to what you keep) + * &> = "Keep right" (pointing to what you keep) + * */ - var cdt: CholeskyDecompositionTest = new CholeskyDecompositionTest - // returns an out of bounds error - // println(cdt.test()) - var p: Prime = new Prime - p.run(1000000000, true) +object Torque extends ZIOAppDefault { - } + def runCholeskyTest: ZIO[Any, Throwable, Unit] = + ZIO.attempt { + val matrix: Vector[Vector[Int]] = Vector(Vector(1,2,3), Vector(1,2,3), Vector(1,2,3)) + val cd = new CholeskyDecomposition + cd.run(matrix) + }.catchAll { error => Console.printError(s"failed: $error")} + + def runPrimeTest: ZIO[Any, Throwable, Unit] = + ZIO.attempt { + val p = new Prime + p.run(390483094, true) + }.catchAll { error => Console.printError(s"failed: $error")} + + def runSequential: ZIO[Any, Throwable, Unit] = + Console.printLine("sequential test") *> + runCholeskyTest *> + runPrimeTest + + def runParallel: ZIO[Any, Throwable, Unit] = + Console.printLine("CholeskyTest") *> + (runCholeskyTest <&> runPrimeTest).unit + + override def run: ZIO[ZIOAppArgs & Scope, Any, Any] = runParallel } diff --git a/src/main/scala/main/Ops/Ops.scala b/src/main/scala/main/Ops/Ops.scala index 6db51a9..821f39b 100644 --- a/src/main/scala/main/Ops/Ops.scala +++ b/src/main/scala/main/Ops/Ops.scala @@ -31,18 +31,15 @@ class Prime() { * We want the function to be less optimized so that the CPU has more work == more stress */ - - def isPrime(n: Int): Boolean = { - if n <= 1 then false - else !(2 to math.sqrt(n).toInt).exists(i => n % i == 0) - - - } - def run(n: Int, result: Boolean): Unit = { - for i <- 0 to n do if isPrime(i) == result then println("true") else println("false") } + + private def isPrime(n: Int): Boolean = { + if n <= 1 then false + else !(2 to math.sqrt(n).toInt).exists(i => n % i == 0) + } + } class Hash { diff --git a/src/main/scala/main/Tests/Tests.scala b/src/main/scala/main/Tests/Tests.scala index 851ac4d..494a5db 100644 --- a/src/main/scala/main/Tests/Tests.scala +++ b/src/main/scala/main/Tests/Tests.scala @@ -5,7 +5,7 @@ import zio._ import main.Ops.CholeskyDecomposition -class CholeskyDecompositionTest { +class CholeskyDecompositionRunner { def test(): Unit = {