From 74374524ffa4a0061322eca7132cf8cd9481ba39 Mon Sep 17 00:00:00 2001 From: Juris Date: Sat, 2 Dec 2023 06:37:28 +0200 Subject: [PATCH] 2023, Day 01 - refactoring --- rust/ReadMe.md | 6 +++++ .../jurisk/adventofcode/y2023/Advent01.scala | 20 +++++----------- .../adventofcode/y2023/Advent01Spec.scala | 23 +++++++++++++++++++ .../adventofcode/y2023/AllSolutionSpec.scala | 6 +---- 4 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 scala2/src/test/scala/jurisk/adventofcode/y2023/Advent01Spec.scala diff --git a/rust/ReadMe.md b/rust/ReadMe.md index 4f6550e1..74c2c5c2 100644 --- a/rust/ReadMe.md +++ b/rust/ReadMe.md @@ -41,6 +41,12 @@ cargo fmt cargo build --release ``` +# Running + +```shell +cargo run --bin solution_ +``` + # Testing ```shell diff --git a/scala2/src/main/scala/jurisk/adventofcode/y2023/Advent01.scala b/scala2/src/main/scala/jurisk/adventofcode/y2023/Advent01.scala index 38d19f56..fbc0111d 100644 --- a/scala2/src/main/scala/jurisk/adventofcode/y2023/Advent01.scala +++ b/scala2/src/main/scala/jurisk/adventofcode/y2023/Advent01.scala @@ -1,8 +1,6 @@ package jurisk.adventofcode.y2023 import jurisk.utils.FileInput._ -import org.scalatest.matchers.should.Matchers._ - import scala.annotation.tailrec object Advent01 { @@ -61,19 +59,13 @@ object Advent01 { solve(data, stringToDigitList(mappings)) } - def main(args: Array[String]): Unit = { - val testData1 = readFileText("2023/01-test-1.txt") - val testData2 = readFileText("2023/01-test-2.txt") - val realData = readFileText("2023/01.txt") - - val test1 = parse(testData1) - val test2 = parse(testData2) - val real = parse(realData) + private[y2023] def parseFile(fileName: String): Parsed = + parse(readFileText(fileName)) - part1(test1) shouldEqual 142 - part1(real) shouldEqual 54081 + def main(args: Array[String]): Unit = { + val realData: Parsed = parseFile("2023/01.txt") - part2(test2) shouldEqual 281 - part2(real) shouldEqual 54649 + println(s"Part 1: ${part1(realData)}") + println(s"Part 2: ${part2(realData)}") } } diff --git a/scala2/src/test/scala/jurisk/adventofcode/y2023/Advent01Spec.scala b/scala2/src/test/scala/jurisk/adventofcode/y2023/Advent01Spec.scala new file mode 100644 index 00000000..5e2c925e --- /dev/null +++ b/scala2/src/test/scala/jurisk/adventofcode/y2023/Advent01Spec.scala @@ -0,0 +1,23 @@ +package jurisk.adventofcode.y2023 + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers._ +import Advent01._ + +class Advent01Spec extends AnyFlatSpec { + "Advent01" should "test part 1" in { + part1(parseFile("2023/01-test-1.txt")) shouldEqual 142 + } + + it should "test part 2" in { + part2(parseFile("2023/01-test-2.txt")) shouldEqual 281 + } + + it should "real part 1" in { + part1(parseFile("2023/01.txt")) shouldEqual 54081 + } + + it should "real part 2" in { + part2(parseFile("2023/01.txt")) shouldEqual 54649 + } +} diff --git a/scala2/src/test/scala/jurisk/adventofcode/y2023/AllSolutionSpec.scala b/scala2/src/test/scala/jurisk/adventofcode/y2023/AllSolutionSpec.scala index e6f3f37b..7bad23fe 100644 --- a/scala2/src/test/scala/jurisk/adventofcode/y2023/AllSolutionSpec.scala +++ b/scala2/src/test/scala/jurisk/adventofcode/y2023/AllSolutionSpec.scala @@ -2,8 +2,4 @@ package jurisk.adventofcode.y2023 import org.scalatest.flatspec.AnyFlatSpec -class AllSolutionSpec extends AnyFlatSpec { - "Advent01" should "work" in { - Advent01.main(Array.empty) - } -} +class AllSolutionSpec extends AnyFlatSpec {}