diff --git a/NDTensors/src/lib/TypeParameterAccessors/test/test_basics.jl b/NDTensors/src/lib/TypeParameterAccessors/test/test_basics.jl index 744a79af6e..7df288f3dd 100644 --- a/NDTensors/src/lib/TypeParameterAccessors/test/test_basics.jl +++ b/NDTensors/src/lib/TypeParameterAccessors/test/test_basics.jl @@ -15,6 +15,11 @@ using NDTensors.TypeParameterAccessors: include("utils/test_inferred.jl") @testset "TypeParameterAccessors basics" begin @testset "Get parameters" begin + @test_inferred type_parameter(AbstractArray{Float64}, 1) == Float64 wrapped = true + @test_inferred type_parameter(AbstractArray{Float64}, Position(1)) == Float64 + @test_inferred type_parameter(AbstractArray{Float64}, eltype) == Float64 + @test_inferred type_parameter(AbstractMatrix{Float64}, ndims) == 2 + @test_inferred type_parameter(Array{Float64}, 1) == Float64 wrapped = true @test_inferred type_parameter(Array{Float64}, Position(1)) == Float64 @test_inferred type_parameter(Val{3}) == 3 diff --git a/NDTensors/test/ext/Project.toml b/NDTensors/test/ext/Project.toml new file mode 100644 index 0000000000..df085f1623 --- /dev/null +++ b/NDTensors/test/ext/Project.toml @@ -0,0 +1,4 @@ +[deps] +ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" +MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" +NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" diff --git a/NDTensors/test/ext/runtests.jl b/NDTensors/test/ext/runtests.jl new file mode 100644 index 0000000000..d9f34a4f70 --- /dev/null +++ b/NDTensors/test/ext/runtests.jl @@ -0,0 +1,12 @@ +@eval module $(gensym()) +using Test: @testset +@testset "$(@__DIR__)" begin + filenames = filter(readdir(@__DIR__)) do f + startswith("test_")(f) && endswith(".jl")(f) + end + @testset "Test $(@__DIR__)/$filename" for filename in filenames + println("Running $(@__DIR__)/$filename") + include(filename) + end +end +end diff --git a/NDTensors/test/ext/test_mappedarraysext.jl b/NDTensors/test/ext/test_mappedarraysext.jl new file mode 100644 index 0000000000..e322022f52 --- /dev/null +++ b/NDTensors/test/ext/test_mappedarraysext.jl @@ -0,0 +1,19 @@ +@eval module $(gensym()) +using ITensors: Index, itensor +using MappedArrays: mappedarray +using Test: @test, @testset +f(i::Int...) = float(sum(iⱼ -> iⱼ^2, i)) +f(i::CartesianIndex) = f(Tuple(i)...) +@testset "NDTensorsMappedArraysExt" begin + a = mappedarray(f, CartesianIndices((2, 2))) + b = copy(a) + i, j = Index.((2, 2)) + ta = itensor(a, i, j) + tb = itensor(b, i, j) + @test ta ≈ tb + @test ta[i => 1, j => 2] ≈ tb[i => 1, j => 2] + @test 2 * ta ≈ 2 * tb + @test ta + ta ≈ tb + tb + @test ta * ta ≈ tb * tb +end +end diff --git a/NDTensors/test/runtests.jl b/NDTensors/test/runtests.jl index 2a05921e40..5a43e4ee90 100644 --- a/NDTensors/test/runtests.jl +++ b/NDTensors/test/runtests.jl @@ -7,7 +7,7 @@ using SafeTestsets: @safetestset filenames = filter(readdir(@__DIR__)) do f startswith("test_")(f) && endswith(".jl")(f) end - for dir in ["lib", "ITensors"] + for dir in ["lib", "ext", "ITensors"] push!(filenames, joinpath(dir, "runtests.jl")) end @testset "Test $(@__DIR__)/$filename" for filename in filenames