From 623bf44da39b6d336ed360d13b54e3c8f7f68540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20R=C3=B8dland?= Date: Tue, 3 Dec 2024 12:53:39 +0100 Subject: [PATCH] Moved num tests check to the read/usage instead of write. --- src/test/kotlin/no/rodland/advent/TestMisc.kt | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/test/kotlin/no/rodland/advent/TestMisc.kt b/src/test/kotlin/no/rodland/advent/TestMisc.kt index 2cdcd352..8bbd8563 100644 --- a/src/test/kotlin/no/rodland/advent/TestMisc.kt +++ b/src/test/kotlin/no/rodland/advent/TestMisc.kt @@ -30,8 +30,9 @@ fun report(test: AOCTest) { println("=".repeat(this.length).joinToString("")) } var endValue: U? = null + val numTestsToRun = if (GHA) 1 else test.numTests val nanos = measureTimedValue { - repeat(test.numTests) { + repeat(numTestsToRun) { val value = test.function(test.data) to test.expected if (value.first != value.second) { println("Result: ${value.first}, Expected: ${test.expected}") @@ -40,9 +41,13 @@ fun report(test: AOCTest) { endValue = value.first } } - val avg = nanos.duration / test.numTests - println("Result: $endValue (OK)") - println("Ran ${test.numTests}, time_pr_test: $avg") + if (numTestsToRun == 1) { + println("Result: $endValue (OK), time: ${nanos.duration}") + } else { + val avg = nanos.duration / numTestsToRun + println("Result: $endValue (OK)") + println("Ran $numTestsToRun, time_pr_test: $avg") + } println() } @@ -125,8 +130,8 @@ fun defaultTestSuiteParseOnCall( numTestPart1: Int = 10, numTestPart2: Int = 10, ) = AOCTestSuite( - AOCTest(part1, liveData, livePart1, if (GHA) 1 else numTestPart1, day = day, part = Part.ONE, live = true), - AOCTest(part2, liveData, livePart2, if (GHA) 1 else numTestPart2, day = day, part = Part.TWO, live = true), + AOCTest(part1, liveData, livePart1, numTestPart1, day = day, part = Part.ONE, live = true), + AOCTest(part2, liveData, livePart2, numTestPart2, day = day, part = Part.TWO, live = true), AOCTest(part1, testData, testPart1, 1, day, part = Part.ONE, live = false), AOCTest(part2, testData, testPart2, 1, day, part = Part.TWO, live = false), AOCTest(part1, liveData, livePart1, 1, day = day, part = Part.ONE, live = true), @@ -148,12 +153,12 @@ fun defaultTestSuiteParseOnInit( numInitLive: Int = 100, numInitTest: Int = 100, ) = AOCTestSuite( - AOCTest({ liveDay.partOne() }, Unit, livePart1, if (GHA) 1 else numTestPart1, liveDay.day, Part.ONE, true), - AOCTest({ liveDay.partTwo() }, Unit, livePart2, if (GHA) 1 else numTestPart2, liveDay.day, Part.TWO, true), + AOCTest({ liveDay.partOne() }, Unit, livePart1, numTestPart1, liveDay.day, Part.ONE, true), + AOCTest({ liveDay.partTwo() }, Unit, livePart2, numTestPart2, liveDay.day, Part.TWO, true), AOCTest({ testDay.partOne() }, Unit, testPart1, 1, liveDay.day, Part.ONE, false), AOCTest({ testDay.partTwo() }, Unit, testPart2, 1, liveDay.day, Part.TWO, false), - AOCTest({ initLive() }, Unit, Unit, numInitLive, if (GHA) 1 else liveDay.day, Part.INIT, live = true), - AOCTest({ initTest() }, Unit, Unit, numInitTest, if (GHA) 1 else liveDay.day, Part.INIT, live = false), + AOCTest({ initLive() }, Unit, Unit, numInitLive, liveDay.day, Part.INIT, live = true), + AOCTest({ initTest() }, Unit, Unit, numInitTest, liveDay.day, Part.INIT, live = false), )