Skip to content

[LiquidCortex.jl] GH#22 — Add unit tests for reference LSM (reference_lsm.jl) #22

Description

@rmems

Source

Synced / linked to GitHub for 1:1 mirror (2026-07-26).


Context

src/reference_lsm.jl has zero test coverage. The lazy initialization, dimension validation, and run_lsm_step function are completely untested.

Untested code paths

  1. _init_ref_lsm!() — GPU initialization with custom dims
  2. _ref_is_initialized() — boolean flag check
  3. run_lsm_step() — lazy init, dimension validation, reservoir dynamics
  4. run_lsm_step_str() — string output format
  5. DimensionMismatch guard for wrong input length

Tests to add (test/runtests.jl)

@testset "Reference LSM" begin
    if LiquidCortex._cuda_available[]
        @testset "Lazy initialization" begin
            # Reset state
            LiquidCortex._ref_initialized[] = false
            LiquidCortex._ref_W[] = nothing
            @test !LiquidCortex._ref_is_initialized()
            
            # First call triggers init
            input = zeros(Float32, 16)
            output = LiquidCortex.run_lsm_step(input, 0.5f0)
            @test LiquidCortex._ref_is_initialized()
            @test length(output) == 16
        end

        @testset "Custom dimensions" begin
            LiquidCortex._ref_initialized[] = false
            LiquidCortex._ref_W[] = nothing
            input = zeros(Float32, 8)
            output = LiquidCortex.run_lsm_step(input, 0.0f0; n_out=4)
            @test length(output) == 4
            @test LiquidCortex._ref_n_in[] == 8
            @test LiquidCortex._ref_n_out[] == 4
        end

        @testset "Dimension validation" begin
            LiquidCortex._ref_initialized[] = false
            LiquidCortex._ref_W[] = nothing
            # Init with 16 inputs
            LiquidCortex.run_lsm_step(zeros(Float32, 16), 0.0f0)
            # Try with wrong size
            @test_throws DimensionMismatch LiquidCortex.run_lsm_step(zeros(Float32, 8), 0.0f0)
        end

        @testset "run_lsm_step_str" begin
            output = LiquidCortex.run_lsm_step_str(zeros(Float32, 16), 0.0f0)
            @test output isa String
            @test occursin(",", output)
        end
    else
        @info "Skipping reference LSM tests — no CUDA device"
        @test_skip "Reference LSM GPU tests skipped"
    end
end

Acceptance criteria

  • Tests cover lazy init, custom dims, dimension validation, string output
  • Tests pass on GPU CI
  • No regression in existing tests

Labels

testing, good first issue

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions