Skip to content

Commit

Permalink
add runtests
Browse files Browse the repository at this point in the history
  • Loading branch information
Moelf committed Nov 30, 2023
1 parent 0c8cc65 commit 4d3a869
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
os: [ubuntu-latest]
arch: [x64]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Julia
uses: julia-actions/setup-julia@v1
with:
Expand All @@ -32,3 +32,5 @@ jobs:
with:
path: "~/.cache/bazel"
key: bazel
- name: Run tests
run: julia --color=yes ./runtests.jl
57 changes: 57 additions & 0 deletions runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Test

const ALL_LANGUAGES = readdir("src")
const INPUTS = readdir("./inputs")

"""
run_solution(day_num_str, input_path, ::Val{T}) -> Vector{String}
Given number of day in two-digit format (e.g. "00", "12") and an input file path `input_path`, run the algorithm
and return the output as a vector of strings.
`T` is the language type, for example `Val{:cpp}` or `Val{:julia}`.
For `Val{:cpp}`, you probably want to use `readlines(`cmd`)` to read the stdout of your executable into a vector of strings.
"""
function run_solution() end

function run_solution(day_num_str, input_path, ::Val{:cpp})
run(`g++ -std=c++17 ./src/cpp/$day_num_str.cpp -o $day_num_str.o`)
return readlines(`./$day_num_str.o $input_path`)
end

function run_solution(day_num_str, input_path, ::Val{:julia})
return readlines(`julia src/julia/$day_num_str.jl $input_path`)
end

function get_all_inputs_solutions(day_num_str)
paths = filter(startswith(day_num_str), INPUTS)
pairs = map(paths) do p
input = joinpath("./inputs", p)
solution = joinpath("./solutions", p)
if !isfile(solution)
error("Solution file $solution does not exist but input file $input does, make sure to upload both")
exit(1)
end
return (input, readlines(solution))
end

return pairs
end


for day_num in 0:0
day_num_str = lpad(day_num, 2, '0')
@testset verbose=true "Day $day_num_str" begin
inputs_solutions = get_all_inputs_solutions(day_num_str)
for lang in ALL_LANGUAGES, (input_path, reference_output) in inputs_solutions
our_output = run_solution(day_num_str, input_path, Val(Symbol(lang)))
reference_output
for (i, (our, ref)) in enumerate(zip(our_output, reference_output))
@testset "$lang $input_path Part $i" begin
@test our == ref
end
end
end
end
end
7 changes: 7 additions & 0 deletions src/cpp/00.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <iostream>

int main() {
std::cout << "hello world" << std::endl;
std::cout << "solution 2" << std::endl;
return 0;
}

0 comments on commit 4d3a869

Please sign in to comment.