Part 2 and actual testing

This commit is contained in:
2024-12-01 17:05:41 +01:00
parent 73f886359b
commit f4a5ffe3ce
3 changed files with 29 additions and 0 deletions

View File

@@ -13,8 +13,14 @@ locals {
right_sorted = sort(local.right) right_sorted = sort(local.right)
diffs = [for i in range(length(local.left_sorted)): abs(local.left_sorted[i] - local.right_sorted[i])] diffs = [for i in range(length(local.left_sorted)): abs(local.left_sorted[i] - local.right_sorted[i])]
matching = [for left in local.left: sum([for right in local.right: left == right ? left : 0])]
} }
output "part1" { output "part1" {
value = sum(local.diffs) value = sum(local.diffs)
} }
output "part2" {
value = sum(local.matching)
}

View File

@@ -0,0 +1,19 @@
variables {
input = file("../../tests/samples/01.txt")
}
run "run" {
command = plan
assert {
condition = output.part1 == 11
error_message = "Part1 output is wrong"
}
assert {
condition = output.part2 == 31
error_message = "Part2 output is wrong"
}
}

View File

@@ -10,3 +10,7 @@ module "day01" {
output "day01_1" { output "day01_1" {
value = module.day01.part1 value = module.day01.part1
} }
output "day01_2" {
value = module.day01.part2
}