|
1 | 1 | using Test: @test, @testset |
2 | | -using ITensorNetworks: AbstractProblem, default_kwargs, current_kwargs, RegionIterator, problem |
| 2 | +using ITensorNetworks: AbstractProblem, default_kwargs, RegionIterator, problem, region_kwargs |
3 | 3 |
|
4 | 4 | module KwargsTestModule |
5 | 5 |
|
6 | 6 | using ITensorNetworks |
7 | | -using ITensorNetworks: AbstractProblem |
| 7 | +using ITensorNetworks: AbstractProblem, @default_kwargs |
8 | 8 |
|
9 | 9 | export TestProblem, NotOurTestProblem, test_function |
10 | 10 |
|
11 | 11 | struct TestProblem <: AbstractProblem end |
12 | 12 | struct NotOurTestProblem <: AbstractProblem end |
13 | 13 |
|
14 | | -test_function(; bool=false, int=0) = bool, int |
15 | | - |
16 | | -function ITensorNetworks.default_kwargs(::typeof(test_function), ::Type{<:AbstractProblem}) |
17 | | - return (; int=3) |
| 14 | +@default_kwargs astypes = true function test_function(::AbstractProblem; bool=false, int=3) |
| 15 | + return bool, int |
18 | 16 | end |
19 | | -function ITensorNetworks.default_kwargs(::typeof(test_function), ::Type{<:TestProblem}) |
20 | | - return (; bool=true) |
| 17 | +@default_kwargs astypes = true function test_function(::TestProblem; bool=true, int=0) |
| 18 | + return bool, int |
21 | 19 | end |
22 | 20 |
|
23 | 21 | end # KwargsTestModule |
24 | 22 |
|
25 | 23 | @testset "Default kwargs" begin |
26 | 24 | using .KwargsTestModule: TestProblem, NotOurTestProblem, test_function |
27 | 25 |
|
28 | | - our_iter = RegionIterator(TestProblem(), ["region" => (; int=1)], 1) |
29 | | - not_our_iter = RegionIterator(NotOurTestProblem(), ["region" => (; int=2)], 1) |
| 26 | + our_iter = RegionIterator(TestProblem(), ["region" => (; test_function_kwargs=(; int=1))], 1) |
| 27 | + not_our_iter = RegionIterator(NotOurTestProblem(), ["region" => (; test_function_kwargs=(; int=2))], 1) |
| 28 | + |
| 29 | + kw = region_kwargs(test_function, our_iter) |
| 30 | + @test kw == (; int=1) |
| 31 | + kw_not = region_kwargs(test_function, not_our_iter) |
| 32 | + @test kw_not == (; int=2) |
| 33 | + |
| 34 | + @info methods(default_kwargs) |
30 | 35 |
|
31 | 36 | # Test dispatch |
32 | | - @test default_kwargs(test_function, our_iter) == (; bool=true) |
33 | | - @test default_kwargs(test_function, problem(our_iter)) == (; bool=true) |
34 | | - @test default_kwargs(test_function, typeof(problem(our_iter))) == (; bool=true) |
| 37 | + @test default_kwargs(test_function, problem(our_iter)) == (; bool=true, int=0) |
| 38 | + @test default_kwargs(test_function, problem(our_iter) |> typeof) == (; bool=true, int=0) |
35 | 39 |
|
36 | | - @test default_kwargs(test_function, not_our_iter) == (; int=3) |
37 | | - @test default_kwargs(test_function, problem(not_our_iter)) == (; int=3) |
38 | | - @test default_kwargs(test_function, typeof(problem(not_our_iter))) == (; int=3) |
| 40 | + @test default_kwargs(test_function, problem(not_our_iter)) == (; bool=false, int=3) |
| 41 | + @test default_kwargs(test_function, problem(not_our_iter) |> typeof) == (; bool=false, int=3) |
39 | 42 |
|
40 | | - @test test_function(; current_kwargs(test_function, our_iter)...) == (true, 0) |
41 | | - @test test_function(; current_kwargs(test_function, not_our_iter)...) == (false, 3) |
| 43 | + @test test_function(problem(our_iter); default_kwargs(test_function, problem(our_iter); kw...)...) == (true, 1) |
| 44 | + @test test_function(problem(not_our_iter); default_kwargs(test_function, problem(not_our_iter); kw_not...)...) == (false, 2) |
42 | 45 |
|
43 | 46 | end |
0 commit comments