Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ authors = ["Samuel Belko <samuelbelko@protonmail.com> and contributors"]
version = "1.1.0"

[compat]
AllocCheck = "0.2"
Aqua = "0.8"
BenchmarkTools = "1"
JET = "0.9, 0.10, 0.11"
LinearAlgebra = "1.10"
SafeTestsets = "0.1"
Expand All @@ -13,12 +15,14 @@ Test = "1.10"
julia = "1.10"

[extras]
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "JET", "LinearAlgebra", "SafeTestsets", "Statistics", "Test"]
test = ["AllocCheck", "Aqua", "BenchmarkTools", "JET", "LinearAlgebra", "SafeTestsets", "Statistics", "Test"]
54 changes: 54 additions & 0 deletions test/alloc_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using SurrogatesBase
using AllocCheck
using BenchmarkTools
using Test

# This file tests that implementations of the SurrogatesBase interface
# can be made allocation-free when properly implemented.
# Since SurrogatesBase is an interface-only package, we test with
# simple concrete implementations.

# Simple deterministic surrogate that returns a constant value
struct ConstantSurrogate <: AbstractDeterministicSurrogate
value::Float64
end

# Allocation-free call operator
(s::ConstantSurrogate)(::Float64) = s.value

# Simple linear surrogate: f(x) = a*x + b
struct LinearSurrogate <: AbstractDeterministicSurrogate
a::Float64
b::Float64
end

# Allocation-free call operator
(s::LinearSurrogate)(x::Float64) = s.a * x + s.b

@testset "Allocation Tests" begin
@testset "ConstantSurrogate allocation-free" begin
s = ConstantSurrogate(42.0)
x = 1.0

# Warmup
s(x)

# Use BenchmarkTools for accurate allocation measurement
result = @benchmark $s($x)
@test result.memory == 0
@test result.allocs == 0
end

@testset "LinearSurrogate allocation-free" begin
s = LinearSurrogate(2.0, 1.0)
x = 3.0

# Warmup
s(x)

# Use BenchmarkTools for accurate allocation measurement
result = @benchmark $s($x)
@test result.memory == 0
@test result.allocs == 0
end
end
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,8 @@ end
@test length(m) == 3
@test m[1] ≈ parameters(ss)
end

# Allocation tests - run in nopre group to avoid precompilation interference
if get(ENV, "GROUP", "all") == "all" || get(ENV, "GROUP", "all") == "nopre"
@safetestset "Allocation Tests" include("alloc_tests.jl")
end
Loading