Skip to content

Commit

Permalink
Part 2 and actual testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bertptrs committed Dec 1, 2024
1 parent 73f8863 commit f4a5ffe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 2024/bonus/day01/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
19 changes: 19 additions & 0 deletions 2024/bonus/day01/sample.tftest.hcl
Original file line number Diff line number Diff line change
@@ -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"
}

}
4 changes: 4 additions & 0 deletions 2024/bonus/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ module "day01" {
output "day01_1" {
value = module.day01.part1
}

output "day01_2" {
value = module.day01.part2
}

0 comments on commit f4a5ffe

Please sign in to comment.