From f4a5ffe3ce9276ff71335eb397c161fedaa3f3d0 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sun, 1 Dec 2024 17:05:41 +0100 Subject: [PATCH] Part 2 and actual testing --- 2024/bonus/day01/main.tf | 6 ++++++ 2024/bonus/day01/sample.tftest.hcl | 19 +++++++++++++++++++ 2024/bonus/main.tf | 4 ++++ 3 files changed, 29 insertions(+) create mode 100644 2024/bonus/day01/sample.tftest.hcl diff --git a/2024/bonus/day01/main.tf b/2024/bonus/day01/main.tf index add48b2..41fd6b1 100644 --- a/2024/bonus/day01/main.tf +++ b/2024/bonus/day01/main.tf @@ -13,8 +13,14 @@ locals { right_sorted = sort(local.right) 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" { value = sum(local.diffs) } + +output "part2" { + value = sum(local.matching) +} diff --git a/2024/bonus/day01/sample.tftest.hcl b/2024/bonus/day01/sample.tftest.hcl new file mode 100644 index 0000000..51fc196 --- /dev/null +++ b/2024/bonus/day01/sample.tftest.hcl @@ -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" + } + +} diff --git a/2024/bonus/main.tf b/2024/bonus/main.tf index c18ee14..d157bb3 100644 --- a/2024/bonus/main.tf +++ b/2024/bonus/main.tf @@ -10,3 +10,7 @@ module "day01" { output "day01_1" { value = module.day01.part1 } + +output "day01_2" { + value = module.day01.part2 +}