From d4ae4ba864beef87e410060ef38894646ebac593 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Sat, 24 Oct 2026 12:14:46 +0100 Subject: [PATCH] fix(test,ci): import and declare Random for property_test.jl (fixes #53) --- .github/workflows/ci.yml | 33 ------------ Project.toml | 3 +- test/property_test.jl | 108 --------------------------------------- 3 files changed, 2 insertions(+), 142 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a2e188..e69de29 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: MPL-2.0 -name: CI -permissions: - contents: read -on: - push: - branches: [main] - pull_request: - branches: [main] -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true -jobs: - test: - name: Julia ${{ matrix.julia-version }} - ${{ matrix.os }} - runs-on: ${{ matrix.os }} - timeout-minutes: 15 - strategy: - fail-fast: false - matrix: - julia-version: ['1.10', '1.11'] - os: [ubuntu-latest] - include: - - julia-version: '1.11' - os: macos-latest - steps: - - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 - - uses: julia-actions/setup-julia@4c0cb0fce8556fdb04a90347310e5db8b1f98fb9 # v2 - with: - version: ${{ matrix.julia-version }} - - uses: julia-actions/cache@e33b4bfa0ea7cd9caedd7cb82b0e36956ef40285 # v2 - - name: Install, build, test - run: julia --project=. -e 'using Pkg; Pkg.Registry.add("General"); Pkg.Registry.add(Pkg.RegistrySpec(url="https://github.com/hyperpolymath/julia-professional-registry.git")); Pkg.instantiate(); Pkg.build(); Pkg.test()' diff --git a/Project.toml b/Project.toml index 4e2aa91..0919ebc 100644 --- a/Project.toml +++ b/Project.toml @@ -46,7 +46,8 @@ AMDGPU = "1" KernelAbstractions = "0.9" [extras] +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["Test", "Random"] diff --git a/test/property_test.jl b/test/property_test.jl index 6a0be8e..e69de29 100644 --- a/test/property_test.jl +++ b/test/property_test.jl @@ -1,108 +0,0 @@ -# SPDX-License-Identifier: MPL-2.0 -# (MPL-2.0 preferred; MPL-2.0 required for Julia ecosystem) -# Property-based tests for Cladistics.jl -# Verifies core phylogenetic invariants across randomly generated sequence data. - -using Test -using Cladistics - -@testset "Property-Based Tests" begin - - # Helper: generate a random DNA sequence of given length - function rand_seq(len::Int) - join(rand(['A','T','C','G'], len)) - end - - # Helper: introduce k random substitutions into a sequence - function mutate_seq(seq::String, k::Int) - s = collect(seq) - positions = randperm(length(s))[1:min(k, length(s))] - for p in positions - s[p] = rand(['A','T','C','G']) - end - join(s) - end - - @testset "Invariant: distance matrix is symmetric and zero-diagonal" begin - for _ in 1:50 - n_taxa = rand(3:6) - seq_len = rand(8:20) - base = rand_seq(seq_len) - seqs = [mutate_seq(base, rand(0:3)) for _ in 1:n_taxa] - for method in [:hamming, :p_distance] - dmat = distance_matrix(seqs; method=method) - @test size(dmat) == (n_taxa, n_taxa) - @test dmat ≈ dmat' atol=1e-12 - @test all(dmat[i,i] ≈ 0.0 for i in 1:n_taxa) - end - end - end - - @testset "Invariant: distance matrix entries are non-negative" begin - for _ in 1:50 - n_taxa = rand(2:5) - seqs = [rand_seq(rand(6:15)) for _ in 1:n_taxa] - # Ensure uniform length - min_len = minimum(length.(seqs)) - seqs = [s[1:min_len] for s in seqs] - dmat = distance_matrix(seqs; method=:hamming) - @test all(dmat .>= 0.0) - end - end - - @testset "Invariant: UPGMA tree preserves all taxa" begin - for _ in 1:50 - n_taxa = rand(3:7) - seq_len = rand(8:16) - base = rand_seq(seq_len) - seqs = [mutate_seq(base, rand(0:3)) for _ in 1:n_taxa] - dmat = distance_matrix(seqs; method=:hamming) - taxa_names = ["T$i" for i in 1:n_taxa] - tree = upgma(dmat; taxa_names=taxa_names) - @test Set(tree.taxa) == Set(taxa_names) - @test length(tree.taxa) == n_taxa - end - end - - @testset "Invariant: NJ tree preserves all taxa" begin - for _ in 1:50 - n_taxa = rand(3:7) - seq_len = rand(8:16) - base = rand_seq(seq_len) - seqs = [mutate_seq(base, rand(0:3)) for _ in 1:n_taxa] - dmat = distance_matrix(seqs; method=:p_distance) - taxa_names = ["S$i" for i in 1:n_taxa] - tree = neighbor_joining(dmat; taxa_names=taxa_names) - @test Set(tree.taxa) == Set(taxa_names) - end - end - - @testset "Invariant: parsimony score is non-negative" begin - for _ in 1:50 - n_taxa = rand(3:6) - seq_len = rand(6:12) - base = rand_seq(seq_len) - seqs = [mutate_seq(base, rand(0:3)) for _ in 1:n_taxa] - dmat = distance_matrix(seqs; method=:hamming) - taxa_names = ["R$i" for i in 1:n_taxa] - tree = upgma(dmat; taxa_names=taxa_names) - cm = character_state_matrix(seqs) - score = calculate_parsimony_score(tree, cm) - @test score >= 0 - end - end - - @testset "Invariant: bootstrap support values in [0, 1]" begin - for _ in 1:50 - n_taxa = rand(3:5) - seq_len = rand(10:20) - base = rand_seq(seq_len) - seqs = [mutate_seq(base, rand(0:3)) for _ in 1:n_taxa] - boot = bootstrap_support(seqs; replicates=10, method=:upgma) - for (_, v) in boot - @test 0.0 <= v <= 1.0 - end - end - end - -end