Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ jobs:
strategy:
fail-fast: false
matrix:
group:
- Core
- nopre
version:
- '1'
- 'lts'
- 'nightly'
arch:
- x64
exclude:
- version: 'nightly'
group: 'nopre'
uses: "SciML/.github/.github/workflows/tests.yml@v1"
with:
group: "${{ matrix.group }}"
julia-version: "${{ matrix.version }}"
julia-arch: "${{ matrix.arch }}"
secrets: "inherit"
Expand Down
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ TruncatedStacktraces = "1"
julia = "1.6"

[extras]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Pkg", "Test"]
96 changes: 96 additions & 0 deletions test/basictests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using FunctionWrappersWrappers
using Test

@testset "FunctionWrappersWrappers.jl" begin
fwplus = FunctionWrappersWrapper(
+, (Tuple{Float64, Float64}, Tuple{Int, Int}), (
Float64, Int,
)
)
@test fwplus(4.0, 8.0) === 12.0
@test fwplus(4, 8) === 12

fwexp2 = FunctionWrappersWrapper(
exp2, (Tuple{Float64}, Tuple{Float32}, Tuple{Int}), (Float64, Float32, Float64)
)
@test fwexp2(4.0) === 16.0
@test fwexp2(4.0f0) === 16.0f0
@test fwexp2(4) === 16.0
end

@testset "Type inference" begin
# Test return type inference
fwplus = FunctionWrappersWrapper(
+, (Tuple{Float64, Float64}, Tuple{Int, Int}), (
Float64, Int,
)
)
@test @inferred(fwplus(4.0, 8.0)) === 12.0
@test @inferred(fwplus(4, 8)) === 12

fwexp2 = FunctionWrappersWrapper(
exp2, (Tuple{Float64}, Tuple{Float32}, Tuple{Int}), (Float64, Float32, Float64)
)
@test @inferred(fwexp2(4.0)) === 16.0
@test @inferred(fwexp2(4.0f0)) === 16.0f0
@test @inferred(fwexp2(4)) === 16.0
end

@testset "Introspection functions" begin
# Test with a simple function
fwsin = FunctionWrappersWrapper(sin, (Tuple{Float64},), (Float64,))

@testset "unwrap" begin
f = unwrap(fwsin)
@test f === sin
@test f(0.5) == sin(0.5)
end

@testset "wrapped_signatures" begin
sigs = wrapped_signatures(fwsin)
@test sigs == (Tuple{Float64},)
end

@testset "wrapped_return_types" begin
rets = wrapped_return_types(fwsin)
@test rets == (Float64,)
end

# Test with multiple signatures
fwplus = FunctionWrappersWrapper(
+, (Tuple{Float64, Float64}, Tuple{Int, Int}), (
Float64, Int,
)
)

@testset "unwrap with multiple signatures" begin
f = unwrap(fwplus)
@test f === +
@test f(1, 2) == 3
end

@testset "wrapped_signatures with multiple signatures" begin
sigs = wrapped_signatures(fwplus)
@test sigs == (Tuple{Float64, Float64}, Tuple{Int, Int})
end

@testset "wrapped_return_types with multiple signatures" begin
rets = wrapped_return_types(fwplus)
@test rets == (Float64, Int)
end

# Test with a custom function
my_func(x) = x^2
fwcustom = FunctionWrappersWrapper(
my_func, (Tuple{Float64}, Tuple{Int}), (
Float64, Int,
)
)

@testset "unwrap with custom function" begin
f = unwrap(fwcustom)
@test f === my_func
@test f(3) == 9
@test f(2.5) == 6.25
end
end
261 changes: 261 additions & 0 deletions test/nopre/Manifest.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/nopre/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[deps]
FunctionWrappersWrappers = "77dc65aa-8811-40c2-897b-53d922fa7daf"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Loading
Loading