From: Ummon Date: Tue, 12 Dec 2017 12:56:20 +0000 (+0100) Subject: Add unit tests for day 12 X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=7bc101ff27be09b06f7bff809343eec556991cfd;p=advent_of_code_2017.git Add unit tests for day 12 --- 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