Skip to content

Commit 0a9f127

Browse files
author
Jack Dunham
committed
Update default_kwargs tests.
1 parent 112d55e commit 0a9f127

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
11
using Test: @test, @testset
2-
using ITensorNetworks: AbstractProblem, default_kwargs, current_kwargs, RegionIterator, problem
2+
using ITensorNetworks: AbstractProblem, default_kwargs, RegionIterator, problem, region_kwargs
33

44
module KwargsTestModule
55

66
using ITensorNetworks
7-
using ITensorNetworks: AbstractProblem
7+
using ITensorNetworks: AbstractProblem, @default_kwargs
88

99
export TestProblem, NotOurTestProblem, test_function
1010

1111
struct TestProblem <: AbstractProblem end
1212
struct NotOurTestProblem <: AbstractProblem end
1313

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
1816
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
2119
end
2220

2321
end # KwargsTestModule
2422

2523
@testset "Default kwargs" begin
2624
using .KwargsTestModule: TestProblem, NotOurTestProblem, test_function
2725

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)
3035

3136
# 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)
3539

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)
3942

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)
4245

4346
end

0 commit comments

Comments
 (0)