aoc/2024/01/part1.test.nix
2024-12-01 11:04:08 +00:00

101 lines
2.1 KiB
Nix

{describe, it, ...}:
let
pkgs = import <nixpkgs> {};
part1 = import ./part1.nix pkgs;
part1example = (part1 {file = ./example.txt;});
in [
(describe "part1" [
(it "gets file content" {
expected = ''
3 4
4 3
2 5
1 3
3 9
3 3'';
actual = part1example.content;
})
(it "splits lines" {
expected = [
"3 4"
"4 3"
"2 5"
"1 3"
"3 9"
"3 3"
];
actual = part1example.lines;
})
(it "splits left and right" {
expected = [
3 4
];
actual = part1example.getLeftAndRight "3 4";
})
(it "splits list into left and right" {
expected = {
left = [ 3 4 2 1 3 3 ];
right = [ 4 3 5 3 9 3 ];
};
actual = part1example.splitLists [
"3 4"
"4 3"
"2 5"
"1 3"
"3 9"
"3 3"
];
})
(it "splits list into left and right" {
expected = {
left = [ 1 2 3 3 3 4 ];
right = [ 3 3 3 4 5 9 ];
};
actual = part1example.sortLists {
left = [ 3 4 2 1 3 3 ];
right = [ 4 3 5 3 9 3 ];
};
})
(it "calculates the distance between each item" {
expected = [2 1 0 1 2 5];
actual = part1example.distance {
left = [ 3 4 2 1 3 3 ];
right = [ 4 3 5 3 9 3 ];
};
})
(it "calculates the total" {
expected = 11;
actual = part1example.total [2 1 0 1 2 5];
})
(it "gets diff of list of strings" {
expected = 11;
actual = part1example.getDiff [
"3 4"
"4 3"
"2 5"
"1 3"
"3 9"
"3 3"
];
})
(it "gets similarity" {
expected = [9 4 0 0 9 9];
actual = part1example.similarity {
left = [ 3 4 2 1 3 3 ];
right = [ 4 3 5 3 9 3 ];
};
})
(it "gets similarity of list of strings" {
expected = 31;
actual = part1example.getSimilarity [
"3 4"
"4 3"
"2 5"
"1 3"
"3 9"
"3 3"
];
})
])
]