Skip to content

Add examples to CI workflow, register missing example metadata, and add comprehensive test suite#146

Merged
HyperCodec merged 4 commits intodevfrom
copilot/rewrite-tests-code
Mar 10, 2026
Merged

Add examples to CI workflow, register missing example metadata, and add comprehensive test suite#146
HyperCodec merged 4 commits intodevfrom
copilot/rewrite-tests-code

Conversation

Copy link
Contributor

Copilot AI commented Mar 10, 2026

Tests had largely been replaced by manual verification via examples; this wires all examples into CI and introduces a new integration test suite to enforce invariants across the crate.

genetic-rs/Cargo.toml

  • Added missing [[example]] entries for readme_ex and knockout (previously unregistered, so cargo wouldn't enforce their feature requirements)
  • Added genrand to required-features for crossover and speciation — both call Vec::gen_random which is gated behind that feature
  • Registered four new [[test]] targets with their respective required-features

.github/workflows/ci-cd.yml

  • New examples job runs all five examples (readme_ex, crossover, knockout, derive, speciation) with their declared minimal feature sets
  • Job scoped to permissions: contents: read

New integration tests

  • tests/simulation.rs (builtin, genrand) — GeneticSim population-size preservation over single and many generations; FitnessEliminator sorting, threshold, highest/lowest-fitness invariants, custom threshold, builder pattern; observer called exactly once per generation; GenerateRandom collection size
  • tests/knockout.rs (knockout, genrand) — KnockoutEliminator output-size invariant for even input; all three ActionIfOdd variants; KnockoutWinner Not/From<Ordering>/Into<usize> conversions; correct genome survives each pair; FitnessKnockoutFn delegation behaviour
  • tests/repopulator.rs (crossover, genrand) — MitosisRepopulator and CrossoverRepopulator fill-to-target and no-op invariants; zero-mutation-rate cloning; deterministic crossover averaging; FromParent count and first-element invariants; population stability over many generations
  • tests/speciation.rs (speciation, genrand) — identical/different-class species grouping; high-threshold merging; every-genome-index-once invariant; insert_genome new-species and join-existing paths; round_robin full-cycle coverage; round_robin_enumerate pair validity; SpeciatedFitnessEliminator population-size stability; rare-species fitness-protection invariant
Original prompt

This section details on the original issue you should resolve

<issue_title>Rewrite Tests</issue_title>
<issue_description>The test code is really spaghetti because of the features, should be rewritten.</issue_description>

Comments on the Issue (you are @copilot in this section)

@HyperCodec after rewriting most of the crate, the tests don't really even exist anymore. i've been using the examples to check my work. maybe we should turn this issue into one about adding examples to workflow?

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…Cargo.toml

Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
@HyperCodec HyperCodec marked this pull request as ready for review March 10, 2026 12:12
Copilot AI changed the title [WIP] Rewrite and improve test code structure Add examples to CI workflow and register missing example metadata Mar 10, 2026
Copy link
Owner

@HyperCodec HyperCodec left a comment

Choose a reason for hiding this comment

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

When rewriting the genetic-rs crate, I had removed a lot of the old tests and had not put them back. Make a new test suite to help enforce invariants and such (which is particularly important with rng-based crates like this where buggy behaviors might not be immediately apparent).

Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 10, 2026

When rewriting the genetic-rs crate, I had removed a lot of the old tests and had not put them back. Make a new test suite to help enforce invariants and such (which is particularly important with rng...

Added four new integration-test files in commit 2641263, covering the main structural invariants across the crate:

  • tests/simulation.rs (builtin,genrand) — GeneticSim population-size preservation, FitnessEliminator sorting/threshold/custom-threshold, always-survives/always-eliminated assertions, builder pattern, observer called-once-per-generation
  • tests/knockout.rs (knockout,genrand) — KnockoutEliminator output-size for even/odd inputs, all three ActionIfOdd variants (including should_panic), KnockoutWinner Not/From<Ordering> conversions, FitnessKnockoutFn delegation behaviour
  • tests/repopulator.rs (crossover,genrand) — MitosisRepopulator and CrossoverRepopulator fill-to-target and no-op invariants, zero-rate cloning, deterministic crossover averaging, FromParent count/first-element, GeneticSim size stability over many generations
  • tests/speciation.rs (speciation,genrand) — identical/different-class species grouping, threshold effect, every-genome-index-once invariant, insert_genome new-species/join-existing paths, round_robin full-coverage, round_robin_enumerate pair validity, population-size stability, rare-species fitness-protection

All 63 tests pass and clippy is clean.

Copilot AI changed the title Add examples to CI workflow and register missing example metadata Add examples to CI workflow, register missing example metadata, and add comprehensive test suite Mar 10, 2026
Copy link
Owner

@HyperCodec HyperCodec left a comment

Choose a reason for hiding this comment

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

kind of excessive amount of comments imo, but LGTM

@HyperCodec HyperCodec merged commit 2fc5ab1 into dev Mar 10, 2026
4 checks passed
@HyperCodec HyperCodec deleted the copilot/rewrite-tests-code branch March 10, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants