From 7bc101ff27be09b06f7bff809343eec556991cfd Mon Sep 17 00:00:00 2001 From: Ummon Date: Tue, 12 Dec 2017 13:56:20 +0100 Subject: [PATCH] Add unit tests for day 12 --- AdventOfCode2017/Day12.fs | 8 ++++---- Tests/Day12 tests.fs | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/AdventOfCode2017/Day12.fs b/AdventOfCode2017/Day12.fs index bc636b7..10dae1f 100644 --- a/AdventOfCode2017/Day12.fs +++ b/AdventOfCode2017/Day12.fs @@ -4,11 +4,11 @@ open System let parseInput (lines : string[]) : Map> = lines - |> Array.fold ( - fun dic str -> + |> Array.map ( + fun str -> let l = str.Split ([| ' '; ',' |], StringSplitOptions.RemoveEmptyEntries) - dic.Add (int l.[0], l.[2 .. l.Length - 1] |> Array.map int |> Set.ofArray) - ) Map.empty + int l.[0], l.[2..] |> Array.map int |> Set.ofArray + ) |> Map.ofArray let graphCount (g : Map>) = let rec visit (current : int) (visited : Set) : Set = diff --git a/Tests/Day12 tests.fs b/Tests/Day12 tests.fs index 96d3438..3150149 100644 --- a/Tests/Day12 tests.fs +++ b/Tests/Day12 tests.fs @@ -10,8 +10,28 @@ type ``Day12 tests`` (output : ITestOutputHelper) = [] let ``(Part1) From web page`` () = - () + let input = + [| + "0 <-> 2" + "1 <-> 1" + "2 <-> 0, 3, 4" + "3 <-> 2, 4" + "4 <-> 2, 3, 6" + "5 <-> 6" + "6 <-> 4, 5" + |] + Day12.parseInput input |> Day12.graphCount |> fst =! 6 [] let ``(Part2) From web page`` () = - () \ No newline at end of file + let input = + [| + "0 <-> 2" + "1 <-> 1" + "2 <-> 0, 3, 4" + "3 <-> 2, 4" + "4 <-> 2, 3, 6" + "5 <-> 6" + "6 <-> 4, 5" + |] + Day12.parseInput input |> Day12.graphCount |> snd =! 2 \ No newline at end of file -- 2.45.2