Skip to content

Commit

Permalink
refactor(test): ensure index ordering isn't coincednt
Browse files Browse the repository at this point in the history
  • Loading branch information
hellkite500 committed Aug 28, 2024
1 parent 933b465 commit 223161b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions python/ngen_cal/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ def explicit_catchments(nexus, fabric, workdir) -> Generator[ List[ CalibrationC
@pytest.fixture
def multi_model_shared_params() -> Mapping[str, list[Parameter]]:
p1 = Parameter(name='a', min=0, max=1, init=0)
p2 = Parameter(name='a', min=0, max=1, init=0)
p2 = Parameter(name='d', min=2, max=3, init=0)
p3 = Parameter(name='c', min=0, max=1, init=0)
params = {'A':[p1], 'B':[p2], 'C':[p3]}
p4 = Parameter(name='a', min=0, max=1, init=0)
params = {'A':[p1], 'B':[p2, p4], 'C':[p3, p4]}

return params

Expand Down
15 changes: 9 additions & 6 deletions python/ngen_cal/tests/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ def test_multi_params(multi_model_shared_params: Mapping[str, list[Parameter]]):
# create new iteration from old
params['1'] = params['0']
#update the parameters by index
params.loc['a', '1'] = 0.5
pa = params[ params['model'] == 'A' ]
pb = params[ params['model'] == 'B' ]
pc = params[ params['model'] == 'C' ]
assert pa.drop('model', axis=1).equals( pb.drop('model', axis=1) )
idx1 = 'a'
idx2 = 'c'
params.loc[idx1, '1'] = 0.5
pa = params[ params['model'] == 'A' ].loc[idx1]
pb = params[ params['model'] == 'B' ].loc[idx1]
pc = params[ params['model'] == 'C' ].loc[idx2]

assert pa.drop('model').equals( pb.drop('model') )
# ensure unique params/alias are not modifed by selection
assert pa.loc['a', '1'] != pc.loc['c', '1']
assert pa.loc['1'] != pc.loc['1']

def test_multi_params2(multi_model_shared_params2: Mapping[str, list[Parameter]]):
# This is essentially the path the params go through from
Expand Down

0 comments on commit 223161b

Please sign in to comment.