diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..53f53a8 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,35 @@ +name: CI +on: + push: + branches: + - master + tags: ['*'] + pull_request: +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + version: + - '1.8' + - 'nightly' + os: + - ubuntu-latest + arch: + - x64 + steps: + - uses: actions/checkout@v3 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/cache@v1 + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml new file mode 100644 index 0000000..cba9134 --- /dev/null +++ b/.github/workflows/CompatHelper.yml @@ -0,0 +1,16 @@ +name: CompatHelper +on: + schedule: + - cron: 0 0 * * * + workflow_dispatch: +jobs: + CompatHelper: + runs-on: ubuntu-latest + steps: + - name: Pkg.add("CompatHelper") + run: julia -e 'using Pkg; Pkg.add("CompatHelper")' + - name: CompatHelper.main() + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} + run: julia -e 'using CompatHelper; CompatHelper.main()' diff --git a/.github/workflows/TagBot.yml b/.github/workflows/TagBot.yml new file mode 100644 index 0000000..2bacdb8 --- /dev/null +++ b/.github/workflows/TagBot.yml @@ -0,0 +1,31 @@ +name: TagBot +on: + issue_comment: + types: + - created + workflow_dispatch: + inputs: + lookback: + default: 3 +permissions: + actions: read + checks: read + contents: write + deployments: read + issues: read + discussions: read + packages: read + pages: read + pull-requests: read + repository-projects: read + security-events: read + statuses: read +jobs: + TagBot: + if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' + runs-on: ubuntu-latest + steps: + - uses: JuliaRegistries/TagBot@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + ssh: ${{ secrets.DOCUMENTER_KEY }} diff --git a/Project.toml b/Project.toml index fef2742..0f07b21 100644 --- a/Project.toml +++ b/Project.toml @@ -1,10 +1,16 @@ name = "HerbData" uuid = "495a3ad3-8034-41b3-a087-aacf2fd71098" -authors = ["jaapjong "] -version = "0.1.0" +authors = ["Jaap de Jong ", "Tilman Hinnerichs ", "Sebastijan Dumancic "] +version = "0.1.1" + +[deps] +Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" [compat] julia = "1.8" -[deps] -Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/README.md b/README.md index 4aacee7..7b11f0d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # Data.jl +[![Build Status](https://github.com/Herb-AI/HerbData.jl/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/Herb-AI/HerbData.jl/actions/workflows/CI.yml?query=branch%3Amaster) + + This package contains functionality for specifying input data for the Herb Program Synthesis framework. It specifies the data structures that are used for examples and the functions to read and write examples from/to files. diff --git a/src/HerbData.jl b/src/HerbData.jl index 5190aa8..efd1fa3 100644 --- a/src/HerbData.jl +++ b/src/HerbData.jl @@ -6,6 +6,7 @@ export Problem, Example, IOExample, + IOPExample, readdata, readfile, @@ -39,6 +40,20 @@ struct IOExample <: Example out::Any end + +""" + struct IOPExample <: Example + +An input-output example with an associated program. +`ex` is an [`IOExample`](@ref). +`program` is a program of arbitrary form. Please note that this is a pure container, and thus does not guarantee any checks on the validity of the program. +""" +struct IOPExample <: Example + ex::IOExample + program::Any +end + + """ readdata(directory::AbstractString, lineparser::Function)::Vector{Problem} @@ -83,7 +98,7 @@ end Writes IO examples and the corresponding programs to disk by serializing them into a file using HDF5 checking for and appending the `.xiop`. """ -function write_IOPexamples(filepath::AbstractString, examples::Vector{Tuple{IOExample, Any}}) +function write_IOPexamples(filepath::AbstractString, examples::Vector{IOPExample}) serialize(filepath * (endswith(filepath, ".xiop") ? "" : ".xiop"), examples) end @@ -98,11 +113,11 @@ function read_IOexamples(filepath::AbstractString)::Vector{IOExample} end """ - read_IOPexamples(filepath::AbstractString)::Vector{Tuple{Data.IOExample, Any}} + read_IOPexamples(filepath::AbstractString)::Vector{Tuple{IOPExample} Reads serialized IO + program examples from disk after type checking. """ -function read_IOPexamples(filepath::AbstractString)::Vector{Tuple{Data.IOExample, Any}} +function read_IOPexamples(filepath::AbstractString)::Vector{IOPExample} @assert endswith(filepath, ".xiop") return deserialize(filepath) end diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 0000000..1fed689 --- /dev/null +++ b/test/runtests.jl @@ -0,0 +1,6 @@ +using HerbData +using Test + +@testset "HerbData.jl" verbose=true begin + include("test_io.jl") +end diff --git a/test/test_io.jl b/test/test_io.jl new file mode 100644 index 0000000..9a224fb --- /dev/null +++ b/test/test_io.jl @@ -0,0 +1,34 @@ +@testset verbose=true "Serialization tests" begin + # Define a sample directory for testing + test_directory = "test_data" + + # Create a directory for testing if it doesn't exist + if !isdir(test_directory) + mkdir(test_directory) + end + + # Sample data for testing + sample_ioexample = [IOExample(Dict(:x => x), 2x+1) for x ∈ 1:5] + sample_iopexample = [IOPExample(ex, :((x + 1) + x)) for ex in sample_ioexample] + + # Test write_IOexamples and read_IOexamples + @testset "IOExample Serialization Tests" begin + filename = joinpath(test_directory, "test_ioexample.xio") + HerbData.write_IOexamples(filename, sample_ioexample) + io_examples = HerbData.read_IOexamples(filename) + @test length(io_examples) == 5 + @test string(io_examples) == string(sample_ioexample) + end + + # Test write_IOPexamples and read_IOPexamples + @testset "IOPExample Serialization Tests" begin + filename = joinpath(test_directory, "test_iopexample.xiop") + HerbData.write_IOPexamples(filename, sample_iopexample) + iop_examples = HerbData.read_IOPexamples(filename) + @test length(iop_examples) == 5 + @test string(iop_examples) == string(sample_iopexample) + end + + # Remove the test data directory after testing + rm(test_directory; force=true, recursive=true) +end