From 2bbc9805cb56d3c6030ad1ddfc2ae25636249bfd Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Thu, 20 Nov 2025 17:43:38 +0200 Subject: [PATCH] test: Improve reset! test to verify via matrix extraction Changed verification from counter-only to extracting and checking matrix: - Added SparseArrays import for nnz() - Verify nnz(K) > 0 after assembly (triplets exist) - Verify nnz(K) == 0 after reset (triplets cleared) - More robust test than checking counter alone Counter is implementation detail, matrix content is the guarantee. --- test/domains/continuum/test_reset_functions.jl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/domains/continuum/test_reset_functions.jl b/test/domains/continuum/test_reset_functions.jl index f5e3e68..99abceb 100644 --- a/test/domains/continuum/test_reset_functions.jl +++ b/test/domains/continuum/test_reset_functions.jl @@ -3,6 +3,7 @@ using JuliaFEM using Tensors using LinearAlgebra +using SparseArrays # For nnz() using Test include("test_helpers.jl") @@ -100,16 +101,21 @@ include("test_helpers.jl") # Populate with data by assembling assemble!(coo_cache, assembler, kernel, mesh) - # Verify data exists (counter should be > 0 after assembly) - @test coo_cache.counter[] > 0 + # Verify data exists by extracting system (matrix should have entries) + K, f = extract_system(coo_cache) + @test nnz(K) > 0 # Assembly produced triplets # Note: force vector f is zero for zero displacement with no body forces # Reset and verify zeros JuliaFEM.reset!(coo_cache) - @test coo_cache.counter[] == 0 + @test coo_cache.counter[] == 0 # Counter is reset @test all(x -> x == 0.0, coo_cache.f) + # After reset, extraction should give empty/zero matrix + K2, f2 = extract_system(coo_cache) + @test nnz(K2) == 0 # No triplets after reset + # Test zero allocations (warm-up first) JuliaFEM.reset!(coo_cache) allocs = @allocated JuliaFEM.reset!(coo_cache)