diff --git a/test/Project.toml b/test/Project.toml index 1d54f1b..75aeabb 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -6,3 +6,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138" + +[sources] +TypeParameterAccessors = {url = "https://github.com/ITensor/TypeParameterAccessors.jl"} diff --git a/test/test_basics.jl b/test/test_basics.jl index 7f625ed..c0063f8 100644 --- a/test/test_basics.jl +++ b/test/test_basics.jl @@ -249,79 +249,4 @@ using .NDTensorsTestUtils: devices_list end end -## TODO: These are broken, fix them. Also, split off into a -## seperate test file, and maybe make a package extension? -## using FillArrays: Fill, Zeros -## using UnallocatedArrays: UnallocatedFill, UnallocatedZeros -## using TypeParameterAccessors: -## Position, default_type_parameter, nparameters, set_type_parameter, type_parameter -## using Test: @test, @testset -## -## @testset "SetParameters" begin -## @testset "Testing $typ" for typ in (:Fill, :Zeros) -## t1 = default_type_parameter(typ, Position{1}()) -## t2 = default_type_parameter(typ, Position{2}()) -## t3 = default_type_parameter(typ, Position{3}()) -## t4 = Any -## ft1 = typ{t1} -## ft2 = typ{t1,t2} -## ft3 = typ{t1,t2,t3} -## -## ## check 1 parameter specified -## ftn1 = set_type_parameter(ft1, Position{1}(), t4) -## ftn2 = set_type_parameter(ft1, Position{2}(), t4) -## ftn3 = set_type_parameter(ft1, Position{3}(), t4) -## @test ftn1 == typ{t4} -## @test ftn2 == typ{t1,t4} -## @test ftn3 == typ{t1,<:Any,t4} -## -## ## check 2 parameters specified -## ftn1 = set_type_parameter(ft2, Position{1}(), t4) -## ftn2 = set_type_parameter(ft2, Position{2}(), t4) -## ftn3 = set_type_parameter(ft2, Position{3}(), t4) -## @test ftn1 == typ{t4,t2} -## @test ftn2 == typ{t1,t4} -## @test ftn3 == typ{t1,t2,t4} -## -## ## check 3 parameters specified -## ftn1 = set_type_parameter(ft3, Position{1}(), t4) -## ftn2 = set_type_parameter(ft3, Position{2}(), t4) -## ftn3 = set_type_parameter(ft3, Position{3}(), t4) -## @test ftn1 == typ{t4,t2,t3} -## @test ftn2 == typ{t1,t4,t3} -## @test ftn3 == typ{t1,t2,t4} -## -## @test type_parameter(ft3, Position{1}()) == t1 -## @test type_parameter(ft3, Position{2}()) == t2 -## @test type_parameter(ft3, Position{3}()) == t3 -## -## @test nparameters(ft3) == 3 -## end -## -## @testset "Testing $typ" for typ in (:UnallocatedFill, :UnallocatedZeros) -## t1 = default_type_parameter(typ, Position{1}()) -## t2 = default_type_parameter(typ, Position{2}()) -## t3 = default_type_parameter(typ, Position{3}()) -## t4 = default_type_parameter(typ, Position{4}()) -## t5 = Any -## ft = typ{t1,t2,t3,t4} -## -## ## check 4 parameters specified -## ftn1 = set_type_parameter(ft, Position{1}(), t5) -## ftn2 = set_type_parameter(ft, Position{2}(), t5) -## ftn3 = set_type_parameter(ft, Position{3}(), t5) -## ftn4 = set_type_parameter(ft, Position{4}(), t5) -## @test ftn1 == typ{t5,t2,t3,t4} -## @test ftn2 == typ{t1,t5,t3,t4} -## @test ftn3 == typ{t1,t2,t5,t4} -## @test ftn4 == typ{t1,t2,t3,t5} -## -## @test type_parameter(ft, Position{1}()) == t1 -## @test type_parameter(ft, Position{2}()) == t2 -## @test type_parameter(ft, Position{3}()) == t3 -## @test type_parameter(ft, Position{4}()) == t4 -## -## @test nparameters(ft) == 4 -## end -## end end diff --git a/test/test_defaults.jl b/test/test_defaults.jl new file mode 100644 index 0000000..9adc3f5 --- /dev/null +++ b/test/test_defaults.jl @@ -0,0 +1,77 @@ + +## TODO: These are broken, fix them. Also, split off into a +## seperate test file, and maybe make a package extension? +@eval module $(gensym()) +using FillArrays: Fill, Zeros +using UnallocatedArrays: UnallocatedFill, UnallocatedZeros +using TypeParameterAccessors: + Position, default_type_parameter, nparameters, set_type_parameter, type_parameter +using Test: @test, @testset + +#@testset "SetParameters" begin +@testset "Testing $typ" for typ in (Fill, Zeros) + t1 = default_type_parameter(typ, Position{1}()) + t2 = default_type_parameter(typ, Position{2}()) + t3 = default_type_parameter(typ, Position{3}()) + t4 = Any + ft1 = typ{t1} + ft2 = typ{t1,t2} + ft3 = typ{t1,t2,t3} + + ## check 1 parameter specified + ftn1 = set_type_parameter(ft1, Position{1}(), t4) + ftn2 = set_type_parameter(ft1, Position{2}(), t4) + ftn3 = set_type_parameter(ft1, Position{3}(), t4) + @test ftn1 == typ{t4} + @test ftn2 == typ{t1,t4} + @test ftn3 == typ{t1,<:Any,t4} + + ## check 2 parameters specified + ftn1 = set_type_parameter(ft2, Position{1}(), t4) + ftn2 = set_type_parameter(ft2, Position{2}(), t4) + ftn3 = set_type_parameter(ft2, Position{3}(), t4) + @test ftn1 == typ{t4,t2} + @test ftn2 == typ{t1,t4} + @test ftn3 == typ{t1,t2,t4} + + ## check 3 parameters specified + ftn1 = set_type_parameter(ft3, Position{1}(), t4) + ftn2 = set_type_parameter(ft3, Position{2}(), t4) + ftn3 = set_type_parameter(ft3, Position{3}(), t4) + @test ftn1 == typ{t4,t2,t3} + @test ftn2 == typ{t1,t4,t3} + @test ftn3 == typ{t1,t2,t4} + + @test type_parameter(ft3, Position{1}()) == t1 + @test type_parameter(ft3, Position{2}()) == t2 + @test type_parameter(ft3, Position{3}()) == t3 + + @test nparameters(ft3) == 3 +end + +@testset "Testing $typ" for typ in (UnallocatedFill, UnallocatedZeros) + t1 = default_type_parameter(typ, Position{1}()) + t2 = default_type_parameter(typ, Position{2}()) + t3 = default_type_parameter(typ, Position{3}()) + t4 = default_type_parameter(typ, Position{4}()) + t5 = Any + ft = typ{t1,t2,t3,t4} + + ## check 4 parameters specified + ftn1 = set_type_parameter(ft, Position{1}(), t5) + ftn2 = set_type_parameter(ft, Position{2}(), t5) + ftn3 = set_type_parameter(ft, Position{3}(), t5) + ftn4 = set_type_parameter(ft, Position{4}(), t5) + @test ftn1 == typ{t5,t2,t3,t4} + @test ftn2 == typ{t1,t5,t3,t4} + @test ftn3 == typ{t1,t2,t5,t4} + @test ftn4 == typ{t1,t2,t3,t5} + + @test type_parameter(ft, Position{1}()) == t1 + @test type_parameter(ft, Position{2}()) == t2 + @test type_parameter(ft, Position{3}()) == t3 + @test type_parameter(ft, Position{4}()) == t4 + + @test nparameters(ft) == 4 +end +end