Skip to content

Commit

Permalink
test parser on examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mdr committed Dec 2, 2024
1 parent c8dd6d5 commit db1ca9d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Aoc2024/Day01/Parser.lean
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Aoc2024.Utils
import Aoc2024.Day01.Examples
import Std
open Std.Internal.Parsec.String
open Std.Internal.Parsec
Expand All @@ -13,4 +14,11 @@ private def inputParser : Parser (List (Int × Int)) := sepBy lineParser (String

def parseLines : String -> Except String (List (Int × Int)) := inputParser.run

#guard parseLines "23 24\n14 13" == Except.ok [(23, 24), (14, 13)]
#guard parseLines exampleInput == Except.ok [
(3, 4),
(4, 3),
(2, 5),
(1, 3),
(3, 9),
(3, 3)
]
10 changes: 9 additions & 1 deletion Aoc2024/Day02/Parser.lean
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Aoc2024.Utils
import Aoc2024.Day02.Types
import Aoc2024.Day02.Examples
import Std
open Std.Internal.Parsec.String
open Std.Internal.Parsec
Expand All @@ -10,4 +11,11 @@ private def inputParser : Parser (List Report) := sepBy reportParser (String.ski

def parseReports : String -> Except String (List Report) := inputParser.run

#guard parseReports "7 6 4 2 1\n1 2 7 8 9" == Except.ok [[7, 6, 4, 2, 1], [1, 2, 7, 8, 9]]
#guard parseReports exampleInput == Except.ok [
[7, 6, 4, 2, 1],
[1, 2, 7, 8, 9],
[9, 7, 6, 2, 1],
[1, 3, 2, 4, 5],
[8, 6, 4, 4, 1],
[1, 3, 6, 7, 9]
]

0 comments on commit db1ca9d

Please sign in to comment.