Skip to content

Commit e89044e

Browse files
committed
Add justfile and additional checks
1 parent d3972f3 commit e89044e

File tree

5 files changed

+199
-113
lines changed

5 files changed

+199
-113
lines changed

.github/workflows/CI.yml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,48 @@ jobs:
5858
- uses: julia-actions/setup-julia@v1
5959
with:
6060
version: '1'
61+
- uses: extractions/setup-just@v1 # or taiki-e/install-action@just
6162
- run: |
6263
git config --global user.name name
6364
git config --global user.email email
6465
git config --global github.user username
6566
- run: |
66-
julia --project=docs -e '
67-
using Pkg;
68-
Pkg.develop(PackageSpec(path=pwd()));
69-
Pkg.instantiate();'
70-
- run: julia --project=docs docs/make.jl
67+
just docs
7168
env:
72-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
71+
format:
72+
name: Format
73+
runs-on: ubuntu-latest
74+
steps:
75+
- uses: actions/checkout@v2
76+
- uses: julia-actions/setup-julia@v1
77+
with:
78+
version: '1'
79+
- uses: extractions/setup-just@v1 # or taiki-e/install-action@just
80+
- run: |
81+
git config --global user.name name
82+
git config --global user.email email
83+
git config --global github.user username
84+
- run: |
85+
just fmt
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
89+
perf:
90+
name: Performance
91+
runs-on: ubuntu-latest
92+
steps:
93+
- uses: actions/checkout@v2
94+
- uses: julia-actions/setup-julia@v1
95+
with:
96+
version: '1'
97+
- uses: extractions/setup-just@v1 # or taiki-e/install-action@just
98+
- run: |
99+
git config --global user.name name
100+
git config --global user.email email
101+
git config --global github.user username
102+
- run: |
103+
just perf
104+
env:
105+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

dev/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[deps]
22
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
3+
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"

justfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# -*- mode: just -*-
2+
3+
# FILE="file.jl"
4+
# https://stackoverflow.com/a/246128/12069968
5+
# PDIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
6+
7+
# julia --project="$PDIR" "$FILE"
8+
9+
# Define project directory
10+
#
11+
# {Project, Manifest}.toml should exist in the root directory, as per
12+
# the justfile, so we should be able to use the justfile directory [1]
13+
# as the root project directory that Julia uses.
14+
#
15+
# [1]: https://just.systems/man/en/functions.html#justfile-and-justfile-directory
16+
project_dir := justfile_dir() + "/"
17+
test_dir := project_dir + "test/"
18+
test_file := test_dir + "runtests.jl"
19+
docs_dir := project_dir + "docs/"
20+
docs_mk_file := docs_dir + "make.jl"
21+
dev_dir := project_dir + "dev/"
22+
bench_file := dev_dir + "runbenchmarks.jl"
23+
standard_instantiate_code := """
24+
import Pkg
25+
Pkg.instantiate()
26+
"""
27+
dev_instantiate_code := """
28+
import Pkg
29+
Pkg.develop(PathSpec(path=pwd()))
30+
Pkg.instantiate()
31+
"""
32+
33+
# Test project
34+
test:
35+
julia --project={{project_dir}} {{test_file}}
36+
37+
# Run specified file
38+
run run_file:
39+
julia --project={{project_dir}} {{run_file}}
40+
41+
# Generate documentation
42+
[group: 'ci']
43+
docs: (instantiate-dev docs_dir)
44+
julia --project={{docs_dir}} {{docs_mk_file}}
45+
46+
# Benchmark performance
47+
[group: 'ci']
48+
perf:
49+
julia --project={{dev_dir}} {{bench_file}}
50+
51+
# check formatting
52+
[group: 'ci']
53+
fmt: (instantiate-dev dev_dir)
54+
julia --project={{dev_dir}} -e 'using JuliaFormatter; format(".")'
55+
56+
# Instantiate main project
57+
instantiate:
58+
julia --project={{project_dir}} -e '{{standard_instantiate_code}}'
59+
60+
# Instantiate sub-project
61+
[private]
62+
instantiate-dev dev_project_dir:
63+
julia --project={{dev_project_dir}} -e '{{dev_instantiate_code}}'

perf/runbenchmarks.jl

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using CodingTheory, BenchmarkTools, Polynomials
2+
import CodingTheory.deepsym, CodingTheory.displaymatrix
3+
4+
function BM()
5+
hamming_distance("ABC", "DBC") == 1
6+
hamming_distance("ABC", "DEF") == 3
7+
8+
hamming_ball([[1, 0, 1], [0, 1, 1], [1, 0, 0]], [1, 0, 0], 2) == deepsym([[1, 0, 1], [1, 0, 0]])
9+
hamming_ball(list_span([2, 2, 2], [1, 2, 0], [0, 2, 1], 3), [1, 0, 0], 3) == deepsym([[0, 0, 0], [0, 2, 1], [0, 1, 2], [1, 2, 0], [1, 1, 1], [1, 0, 2], [2, 1, 0], [2, 0, 1], [2, 2, 2]])
10+
11+
rate(3, 5, 4) 0.3662433802
12+
13+
t_error_correcting([[0, 0, 0, 0], [2, 2, 2, 2]], 1) == true
14+
t_error_correcting([[1, 0, 1], [0, 1, 1], [1, 0, 0], [1, 1, 1]], 3) == false
15+
t_error_detecting([[1, 0, 1], [0, 1, 1], [1, 0, 0], [1, 1, 1]], 3) == false
16+
17+
find_error_detection_max([[0, 0, 0, 0], [0, 1, 1, 1], [1, 0, 1, 0], [1, 1, 0, 1]], 2) == 1
18+
find_error_correction_max([[0, 0, 0, 0], [0, 1, 1, 1], [1, 0, 1, 0], [1, 1, 0, 1]], 2) == 0
19+
find_error_correction_max(list_span([1, 0, 1, 0], [0, 1, 1, 1], 2), 2) == 0
20+
find_error_detection_max(list_span([1, 0, 1, 0], [0, 1, 1, 1], 2), 2) == 1
21+
22+
Polynomial([1, 2, 3, 4, 5, 6, 7, 8, 9], 3) == Polynomial([1, 2, 0, 1, 2, 0, 1, 2])
23+
24+
isirreducible(Polynomial([1, 1, 0, 0, 1]), 2) == true
25+
isirreducible(Polynomial([1, 1, 1, 0, 1, 1]), 2) == true
26+
isirreducible(Polynomial([4, 4, 1]), 2) == false
27+
isirreducible(Polynomial([1, 0, 1]), 2) == false
28+
isirreducible(Polynomial([-2, 0, 1]), 2) == false
29+
isirreducible(Polynomial([1, 1]), 2) == false
30+
31+
p = Polynomial([1, 1, 2, 0, 1, 2, 1])
32+
q = Polynomial([2, 1, 1])
33+
a = Polynomial([0, 1, 0, 1, 0, 0, 1])
34+
b = Polynomial([1, 0, 1])
35+
36+
mod(rem(p, q), 3) == Polynomial([1, 1])
37+
mod(rem(a, b), 2) == Polynomial([1])
38+
39+
rref([1 0 1 1 1; 1 1 1 0 1; 0 1 1 1 1], 2) == [1 0 0 1 0; 0 1 0 1 0; 0 0 1 0 1]
40+
rref([1 0 1 0 1 0; 0 1 0 0 1 0; 1 1 1 1 1 1], 2) == [1 0 1 0 1 0; 0 1 0 0 1 0; 0 0 0 1 1 1]
41+
rref([1 1 0 2 3 1; 2 0 1 3 4 1; 1 2 2 1 4 3], 5, colswap=false) == [1 0 3 0 2 2; 0 1 2 0 1 1; 0 0 0 1 0 4]
42+
rref([1 1 0 2 3 1; 2 0 1 3 4 1; 1 2 2 1 4 3], 5, colswap=true) == [1 0 0 3 2 2; 0 1 0 2 1 1; 0 0 1 0 0 4]
43+
rref([1 2 0 1 2 1 2; 2 2 2 0 1 1 1; 1 0 1 1 2 1 2; 0 1 0 1 1 2 2], 3) == [1 0 0 0 2 2 2; 0 1 0 0 2 0 1; 0 0 1 0 1 0 2; 0 0 0 1 2 2 1]
44+
rref([0 0 0 0 0; 1 0 1 0 1; 0 1 0 1 1; 1 1 1 1 0], 2) == [1 0 1 0 1; 0 1 0 1 1; 0 0 0 0 0; 0 0 0 0 0]
45+
rref([1 1 1 0; 1 1 0 1; 0 0 1 1], 2) == [1 1 0 1; 0 0 1 1; 0 0 0 0]
46+
47+
multiplication_table(2, 3) == Polynomial[Polynomial([0]) Polynomial([0]) Polynomial([0]) Polynomial([0]) Polynomial([0]) Polynomial([0]) Polynomial([0]) Polynomial([0]) Polynomial([0]); Polynomial([0]) Polynomial([1]) Polynomial([2]) Polynomial([0, 1]) Polynomial([1, 1]) Polynomial([2, 1]) Polynomial([0, 2]) Polynomial([1, 2]) Polynomial([2, 2]); Polynomial([0]) Polynomial([2]) Polynomial([1]) Polynomial([0, 2]) Polynomial([2, 2]) Polynomial([1, 2]) Polynomial([0, 1]) Polynomial([2, 1]) Polynomial([1, 1]); Polynomial([0]) Polynomial([0, 1]) Polynomial([0, 2]) Polynomial([0, 0, 1]) Polynomial([0, 1, 1]) Polynomial([0, 2, 1]) Polynomial([0, 0, 2]) Polynomial([0, 1, 2]) Polynomial([0, 2, 2]); Polynomial([0]) Polynomial([1, 1]) Polynomial([2, 2]) Polynomial([0, 1, 1]) Polynomial([1, 2, 1]) Polynomial([2, 0, 1]) Polynomial([0, 2, 2]) Polynomial([1, 0, 2]) Polynomial([2, 1, 2]); Polynomial([0]) Polynomial([2, 1]) Polynomial([1, 2]) Polynomial([0, 2, 1]) Polynomial([2, 0, 1]) Polynomial([1, 1, 1]) Polynomial([0, 1, 2]) Polynomial([2, 2, 2]) Polynomial([1, 0, 2]); Polynomial([0]) Polynomial([0, 2]) Polynomial([0, 1]) Polynomial([0, 0, 2]) Polynomial([0, 2, 2]) Polynomial([0, 1, 2]) Polynomial([0, 0, 1]) Polynomial([0, 2, 1]) Polynomial([0, 1, 1]); Polynomial([0]) Polynomial([1, 2]) Polynomial([2, 1]) Polynomial([0, 1, 2]) Polynomial([1, 0, 2]) Polynomial([2, 2, 2]) Polynomial([0, 2, 1]) Polynomial([1, 1, 1]) Polynomial([2, 0, 1]); Polynomial([0]) Polynomial([2, 2]) Polynomial([1, 1]) Polynomial([0, 2, 2]) Polynomial([2, 1, 2]) Polynomial([1, 0, 2]) Polynomial([0, 1, 1]) Polynomial([2, 0, 1]) Polynomial([1, 2, 1])]
48+
49+
list_span([2, 1, 1], [1, 1, 1], 3) == [[0, 0, 0], [1, 1, 1], [2, 2, 2], [2, 1, 1], [0, 2, 2], [1, 0, 0], [1, 2, 2], [2, 0, 0], [0, 1, 1]]
50+
51+
islinear([[0,0,0],[1,1,1],[1,0,1],[1,1,0]], 2) == false
52+
islinear([[0,0,0],[1,1,1],[1,0,1],[0,1,0]], 2) == true
53+
54+
code_distance([[0,0,0,0,0],[1,0,1,0,1],[0,1,0,1,0],[1,1,1,1,1]]) == 2
55+
code_distance([[0,0,0,0,0],[1,1,1,0,0],[0,0,0,1,1],[1,1,1,1,1],[1,0,0,1,1],[0,1,1,0,0]]) == 1
56+
57+
Alphabet("123") == deepsym([1, 2, 3])
58+
Alphabet([1, 2, 3]) == deepsym([1, 2, 3])
59+
Alphabet(["1", "2", "3"]) == deepsym([1, 2, 3])
60+
# TODO: write test for CodeUniverse struct
61+
[i for i in CodeUniverseIterator(["a", "b", "c"], 3)] == get_all_words(["a", "b", "c"], 3) # implicitly tests CodeUniverseIterator
62+
collect(CodeUniverseIterator(["a", "b", "c"], 4)) == Tuple[(:a, :a, :a, :a), (:b, :a, :a, :a), (:c, :a, :a, :a), (:a, :b, :a, :a), (:b, :b, :a, :a), (:c, :b, :a, :a), (:a, :c, :a, :a), (:b, :c, :a, :a), (:c, :c, :a, :a), (:a, :a, :b, :a), (:b, :a, :b, :a), (:c, :a, :b, :a), (:a, :b, :b, :a), (:b, :b, :b, :a), (:c, :b, :b, :a), (:a, :c, :b, :a), (:b, :c, :b, :a), (:c, :c, :b, :a), (:a, :a, :c, :a), (:b, :a, :c, :a), (:c, :a, :c, :a), (:a, :b, :c, :a), (:b, :b, :c, :a), (:c, :b, :c, :a), (:a, :c, :c, :a), (:b, :c, :c, :a), (:c, :c, :c, :a), (:a, :a, :a, :b), (:b, :a, :a, :b), (:c, :a, :a, :b), (:a, :b, :a, :b), (:b, :b, :a, :b), (:c, :b, :a, :b), (:a, :c, :a, :b), (:b, :c, :a, :b), (:c, :c, :a, :b), (:a, :a, :b, :b), (:b, :a, :b, :b), (:c, :a, :b, :b), (:a, :b, :b, :b), (:b, :b, :b, :b), (:c, :b, :b, :b), (:a, :c, :b, :b), (:b, :c, :b, :b), (:c, :c, :b, :b), (:a, :a, :c, :b), (:b, :a, :c, :b), (:c, :a, :c, :b), (:a, :b, :c, :b), (:b, :b, :c, :b), (:c, :b, :c, :b), (:a, :c, :c, :b), (:b, :c, :c, :b), (:c, :c, :c, :b), (:a, :a, :a, :c), (:b, :a, :a, :c), (:c, :a, :a, :c), (:a, :b, :a, :c), (:b, :b, :a, :c), (:c, :b, :a, :c), (:a, :c, :a, :c), (:b, :c, :a, :c), (:c, :c, :a, :c), (:a, :a, :b, :c), (:b, :a, :b, :c), (:c, :a, :b, :c), (:a, :b, :b, :c), (:b, :b, :b, :c), (:c, :b, :b, :c), (:a, :c, :b, :c), (:b, :c, :b, :c), (:c, :c, :b, :c), (:a, :a, :c, :c), (:b, :a, :c, :c), (:c, :a, :c, :c), (:a, :b, :c, :c), (:b, :b, :c, :c), (:c, :b, :c, :c), (:a, :c, :c, :c), (:b, :c, :c, :c), (:c, :c, :c, :c)]
63+
64+
sphere_covering_bound(5,7,3) == 215
65+
sphere_packing_bound(5,7,3) == 2693
66+
67+
construct_ham_matrix(3,2) == [0 0 0 1 1 1 1; 0 1 1 0 0 1 1; 1 0 1 0 1 0 1]
68+
construct_ham_matrix(3,3) == [0 0 0 0 0 0 0 0 1 1 1 1 1; 0 0 1 1 1 2 2 2 0 0 0 1 1; 1 2 0 1 2 0 1 2 0 1 2 0 1]
69+
70+
isperfect(11, 6, 5, 3) == true
71+
isperfect(23, 12, 7, 2) == true
72+
isperfect(23, 12, 7, 3) == false
73+
isperfect(11, 6, 5, 4) == false
74+
isgolayperfect(11, 6, 5, 3) == true
75+
isgolayperfect(23, 12, 7, 2) == true
76+
isgolayperfect(23, 12, 7, 3) == false
77+
isgolayperfect(11, 6, 5, 4) == false
78+
79+
length(get_codewords(5, 5, 3)) [74:74...]
80+
length(get_codewords(4, 7, 3; m = 1)) [256:308...]
81+
length(get_codewords_greedy(5, 5, 3)) == 74
82+
randq, randn = rand(1:8, 2)
83+
length(get_all_words(randq, randn)) == big(randq)^randn
84+
get_codewords([1 0 1 0; 0 1 1 1], 2) == [[0, 0, 0, 0], [1, 0, 1, 0], [0, 1, 1, 1], [1, 1, 0, 1]]
85+
get_codewords([1 0 0 1 1 0; 0 1 0 1 0 1; 0 0 1 0 1 1], 2) == [[0, 0, 0, 0, 0, 0], [1, 0, 0, 1, 1, 0], [0, 1, 0, 1, 0, 1], [1, 1, 0, 0, 1, 1], [0, 0, 1, 0, 1, 1], [1, 0, 1, 1, 0, 1], [0, 1, 1, 1, 1, 0], [1, 1, 1, 0, 0, 0]]
86+
87+
syndrome([0, 2, 1, 2, 0, 1, 0], transpose(parity_check([1 0 0 0 2 2 2; 0 1 0 0 2 0 1; 0 0 1 0 1 0 2; 0 0 0 1 2 2 1], 3)), 3) == [0 0 0]
88+
parity_check([1 0 0 0 2 2 2; 0 1 0 0 2 0 1; 0 0 1 0 1 0 2; 0 0 0 1 2 2 1], 3) == [1 1 2 1 1 0 0; 1 0 0 1 0 1 0; 1 2 1 2 0 0 1]
89+
normal_form([1 2 0 1 2 1 2; 2 2 2 0 1 1 1; 1 0 1 1 2 1 2; 0 1 0 1 1 2 2], 3) == [1 0 0 0 2 2 2; 0 1 0 0 2 0 1; 0 0 1 0 1 0 2; 0 0 0 1 2 2 1]
90+
equivalent_code([1 2 0 1 2 1 2; 2 2 2 0 1 1 1; 1 0 1 1 2 1 2; 0 1 0 1 1 2 2], 3) == [1 0 0 0 2 2 2; 0 1 0 0 2 0 1; 0 0 1 0 1 0 2; 0 0 0 1 2 2 1]
91+
parity_check(normal_form([1 2 0 1 2 1 2; 2 2 2 0 1 1 1; 1 0 1 1 2 1 2; 0 1 0 1 1 2 2], 3), 3) == [1 1 2 1 1 0 0; 1 0 0 1 0 1 0; 1 2 1 2 0 0 1]
92+
isincode([0, 2, 1, 2, 0, 1, 0], transpose(parity_check([1 0 0 0 2 2 2; 0 1 0 0 2 0 1; 0 0 1 0 1 0 2; 0 0 0 1 2 2 1], 3)), 3) == true
93+
isincode([1, 0, 2, 2, 1, 2, 1], transpose(parity_check([1 0 0 0 2 2 2; 0 1 0 0 2 0 1; 0 0 1 0 1 0 2; 0 0 0 1 2 2 1], 3)), 3) == false
94+
end # end runtests
95+
96+
@btime BM()

0 commit comments

Comments
 (0)