Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from Herb-AI/dev
Browse files Browse the repository at this point in the history
Add tests, update Project.toml; add IOPExample struct
  • Loading branch information
THinnerichs authored Sep 4, 2023
2 parents 728c961 + 2d20ff3 commit 25966e7
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 7 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -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()'
31 changes: 31 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -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 }}
14 changes: 10 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
name = "HerbData"
uuid = "495a3ad3-8034-41b3-a087-aacf2fd71098"
authors = ["jaapjong <[email protected]>"]
version = "0.1.0"
authors = ["Jaap de Jong <[email protected]>", "Tilman Hinnerichs <[email protected]>", "Sebastijan Dumancic <[email protected]>"]
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"]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 18 additions & 3 deletions src/HerbData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export
Problem,
Example,
IOExample,
IOPExample,

readdata,
readfile,
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using HerbData
using Test

@testset "HerbData.jl" verbose=true begin
include("test_io.jl")
end
34 changes: 34 additions & 0 deletions test/test_io.jl
Original file line number Diff line number Diff line change
@@ -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

2 comments on commit 25966e7

@THinnerichs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/90777

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.1 -m "<description of version>" 25966e7edd82553739862ae7e3fc8088a991bdce
git push origin v0.1.1

Please sign in to comment.