aoc2025 test script
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -3,6 +3,7 @@ build/
|
|||||||
*~
|
*~
|
||||||
*.swp
|
*.swp
|
||||||
*.log
|
*.log
|
||||||
|
*.bak
|
||||||
*.agda
|
*.agda
|
||||||
*.agdai
|
*.agdai
|
||||||
/*.js
|
/*.js
|
||||||
@@ -12,3 +13,8 @@ mkday.py
|
|||||||
tmp
|
tmp
|
||||||
min.js.gz
|
min.js.gz
|
||||||
src/Revision.newt
|
src/Revision.newt
|
||||||
|
.calva
|
||||||
|
.clj-kondo
|
||||||
|
.joyride
|
||||||
|
.lsp
|
||||||
|
.vscode
|
||||||
|
|||||||
1
Makefile
1
Makefile
@@ -36,6 +36,7 @@ test: newt.js
|
|||||||
|
|
||||||
aoctest: newt.js
|
aoctest: newt.js
|
||||||
scripts/aoc
|
scripts/aoc
|
||||||
|
scripts/aoc25
|
||||||
|
|
||||||
# Misc
|
# Misc
|
||||||
|
|
||||||
|
|||||||
6
aoc2025/Day1.newt.golden
Normal file
6
aoc2025/Day1.newt.golden
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
aoc2025/day1/eg.txt
|
||||||
|
part1 3
|
||||||
|
part2 6
|
||||||
|
aoc2025/day1/input.txt
|
||||||
|
part1 1100
|
||||||
|
part2 6358
|
||||||
11
aoc2025/Day11.newt.golden
Normal file
11
aoc2025/Day11.newt.golden
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
aoc2025/day11/eg.txt
|
||||||
|
part1 5
|
||||||
|
svr missing {"tag":0}
|
||||||
|
part2 0
|
||||||
|
aoc2025/day11/eg2.txt
|
||||||
|
you missing {"tag":0}
|
||||||
|
part1 0
|
||||||
|
part2 2
|
||||||
|
aoc2025/day11/input.txt
|
||||||
|
part1 636
|
||||||
|
part2 509312913844956
|
||||||
6
aoc2025/Day12.newt.golden
Normal file
6
aoc2025/Day12.newt.golden
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
aoc2025/day12/eg.txt
|
||||||
|
[7, 7, 7, 7, 7, 7]
|
||||||
|
3 rows, 0 easy, 3 maybe, 0 impossible
|
||||||
|
aoc2025/day12/input.txt
|
||||||
|
[7, 5, 7, 6, 7, 7]
|
||||||
|
1000 rows, 479 easy, 0 maybe, 521 impossible
|
||||||
6
aoc2025/Day2.newt.golden
Normal file
6
aoc2025/Day2.newt.golden
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
aoc2025/day2/eg.txt
|
||||||
|
part1 1227775554
|
||||||
|
part2 4174379265
|
||||||
|
aoc2025/day2/input.txt
|
||||||
|
part1 18893502033
|
||||||
|
part2 26202168557
|
||||||
6
aoc2025/Day3.newt.golden
Normal file
6
aoc2025/Day3.newt.golden
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
aoc2025/day3/eg.txt
|
||||||
|
part1 357
|
||||||
|
part2 3121910778619
|
||||||
|
aoc2025/day3/input.txt
|
||||||
|
part1 17452
|
||||||
|
part2 173300819005913
|
||||||
6
aoc2025/Day4.newt.golden
Normal file
6
aoc2025/Day4.newt.golden
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
aoc2025/day4/eg.txt
|
||||||
|
part1 13
|
||||||
|
part2 43
|
||||||
|
aoc2025/day4/input.txt
|
||||||
|
part1 1569
|
||||||
|
part2 9280
|
||||||
6
aoc2025/Day5.newt.golden
Normal file
6
aoc2025/Day5.newt.golden
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
aoc2025/day5/eg.txt
|
||||||
|
part1 3
|
||||||
|
part2 14
|
||||||
|
aoc2025/day5/input.txt
|
||||||
|
part1 862
|
||||||
|
part2 357907198933892
|
||||||
6
aoc2025/Day6.newt.golden
Normal file
6
aoc2025/Day6.newt.golden
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
aoc2025/day6/eg.txt
|
||||||
|
part1 4277556
|
||||||
|
part2 3263827
|
||||||
|
aoc2025/day6/input.txt
|
||||||
|
part1 5346286649122
|
||||||
|
part2 10389131401929
|
||||||
10
aoc2025/Day7.newt.golden
Normal file
10
aoc2025/Day7.newt.golden
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
aoc2025/day7/eg.txt
|
||||||
|
rows 15
|
||||||
|
cols 14
|
||||||
|
part1 21
|
||||||
|
part2 40
|
||||||
|
aoc2025/day7/input.txt
|
||||||
|
rows 141
|
||||||
|
cols 140
|
||||||
|
part1 1587
|
||||||
|
part2 5748679033029
|
||||||
6
aoc2025/Day8.newt.golden
Normal file
6
aoc2025/Day8.newt.golden
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
aoc2025/day8/eg.txt
|
||||||
|
part1 40
|
||||||
|
part2 25272
|
||||||
|
aoc2025/day8/input.txt
|
||||||
|
part1 123234
|
||||||
|
part2 9259958565
|
||||||
6
aoc2025/Day9.newt.golden
Normal file
6
aoc2025/Day9.newt.golden
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
aoc2025/day9/eg.txt
|
||||||
|
part1 6 50
|
||||||
|
part2 24
|
||||||
|
aoc2025/day9/input.txt
|
||||||
|
part1 1222 4777816465
|
||||||
|
part2 1410501884
|
||||||
75
aoc2025/Parser.newt
Normal file
75
aoc2025/Parser.newt
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
module Parser
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
import Aoc
|
||||||
|
|
||||||
|
Parser : U → U
|
||||||
|
Parser a = List Char → Either String (a × List Char)
|
||||||
|
|
||||||
|
instance Monad Parser where
|
||||||
|
pure a = \ cs => Right (a, cs)
|
||||||
|
bind ma mab = \ cs => ma cs >>= uncurry mab
|
||||||
|
|
||||||
|
instance Alternative Parser where
|
||||||
|
pa <|> pb = \ cs => case pa cs of
|
||||||
|
Left msg => pb cs
|
||||||
|
res => res
|
||||||
|
|
||||||
|
instance Functor Parser where
|
||||||
|
map f pa = \ cs => case pa cs of
|
||||||
|
Left msg => Left msg
|
||||||
|
Right (a, cs) => Right (f a, cs)
|
||||||
|
|
||||||
|
instance Applicative Parser where
|
||||||
|
return a = pure a
|
||||||
|
pa <*> pb = pa >>= (\ f => map f pb)
|
||||||
|
|
||||||
|
|
||||||
|
fail : ∀ a. String -> Parser a
|
||||||
|
fail msg = \ cs => Left msg
|
||||||
|
|
||||||
|
-- TODO, case builder isn't expanding Parser Unit to count lambdas
|
||||||
|
eof : Parser Unit
|
||||||
|
eof = \case
|
||||||
|
Nil => Right (MkUnit, Nil)
|
||||||
|
_ => Left "expected eof"
|
||||||
|
|
||||||
|
satisfy : (Char → Bool) → Parser Char
|
||||||
|
satisfy pred = \case
|
||||||
|
Nil => Left "unexpected EOF"
|
||||||
|
(c :: cs) => if pred c then Right (c, cs) else Left ("did not expect " ++ show c ++ " - " ++ pack cs)
|
||||||
|
|
||||||
|
match : Char → Parser Char
|
||||||
|
match d = satisfy (_==_ d)
|
||||||
|
|
||||||
|
any : Parser Char
|
||||||
|
any = satisfy (λ _ => True)
|
||||||
|
|
||||||
|
some many : ∀ a. Parser a → Parser (List a)
|
||||||
|
many p = some p <|> pure Nil
|
||||||
|
some p = do
|
||||||
|
v <- p
|
||||||
|
vs <- many p
|
||||||
|
pure (v :: vs)
|
||||||
|
|
||||||
|
string : String → Parser Unit
|
||||||
|
string str = go (unpack str)
|
||||||
|
where
|
||||||
|
go : List Char → Parser Unit
|
||||||
|
go Nil = pure MkUnit
|
||||||
|
go (c :: cs) = match c >> go cs
|
||||||
|
|
||||||
|
number : Parser Int
|
||||||
|
number = stringToInt ∘ pack <$> some (satisfy isDigit)
|
||||||
|
-- do
|
||||||
|
-- digs <- some (satisfy isDigit)
|
||||||
|
-- pure $ stringToInt $ pack digs
|
||||||
|
|
||||||
|
optional : ∀ a. Parser a → Parser (Maybe a)
|
||||||
|
optional pa = Just <$> pa <|> pure Nothing
|
||||||
|
|
||||||
|
ws : Parser Unit
|
||||||
|
ws = many (match ' ') >> pure MkUnit
|
||||||
|
|
||||||
|
token : String → Parser Unit
|
||||||
|
token str = string str >> ws
|
||||||
36
scripts/aoc25
Executable file
36
scripts/aoc25
Executable file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
mkdir -p tmp
|
||||||
|
echo "Test AoC 2025 solutions"
|
||||||
|
NCC="node newt.js"
|
||||||
|
total=0
|
||||||
|
failed=0
|
||||||
|
for fn in aoc2025/Day*.newt; do
|
||||||
|
total=$((total + 1))
|
||||||
|
echo Test $fn
|
||||||
|
bn=$(basename $fn)
|
||||||
|
$NCC $fn -o out.js > tmp/${bn}.compile
|
||||||
|
if [ $? != "0" ]; then
|
||||||
|
echo Compile failed for $fn
|
||||||
|
failed=$((failed + 1))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
# if there is a golden file, run the code and compare output
|
||||||
|
if [ -f ${fn}.golden ]; then
|
||||||
|
node out.js > tmp/${bn}.out
|
||||||
|
if [ $? != "0" ]; then
|
||||||
|
echo Run failed for $fn
|
||||||
|
failed=$((failed + 1))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if ! diff -q tmp/${bn}.out ${fn}.golden; then
|
||||||
|
echo "Output mismatch for $fn"
|
||||||
|
failed=$((failed + 1))
|
||||||
|
if [ $1 = "--fix" ]; then
|
||||||
|
cp tmp/${bn}.out ${fn}.golden
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Total tests: $total"
|
||||||
|
echo "Failed tests: $failed"
|
||||||
Reference in New Issue
Block a user