Skip to content

Commit 89c7260

Browse files
authored
Fixes tests (#3)
Fixes how to check identity of the outputs from functions.
1 parent 0a2c5f4 commit 89c7260

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

tests/test_ldl.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,30 +88,30 @@ def test_initialize_with_matrices ():
8888
assert all(pd.Series(ldl.__dict__.keys()) == pd.Series(['words', 'cmat',
8989
'smat', 'fmat', 'gmat', 'vmat', 'chat', 'shat']))
9090
assert all(pd.Series(ldl.words) == pd.Series(['ban', 'banban']))
91-
assert ldl.cmat.identical(cmat)
92-
assert ldl.smat.identical(smat)
93-
assert ldl.fmat.identical(fmat)
94-
assert ldl.gmat.identical(gmat)
95-
assert ldl.vmat.identical(vmat)
96-
assert ldl.shat.identical(shat)
97-
assert ldl.chat.identical(chat)
91+
xr.testing.assert_allclose(ldl.cmat, cmat)
92+
xr.testing.assert_allclose(ldl.smat, smat)
93+
xr.testing.assert_allclose(ldl.fmat, fmat)
94+
xr.testing.assert_allclose(ldl.gmat, gmat)
95+
xr.testing.assert_allclose(ldl.vmat, vmat)
96+
xr.testing.assert_allclose(ldl.shat, shat)
97+
xr.testing.assert_allclose(ldl.chat, chat)
9898

9999
def test_gen_cmat ():
100100
ldl = LDL()
101101
ldl.gen_cmat(words=words)
102-
assert ldl.cmat.identical(cmat)
102+
xr.testing.assert_allclose(ldl.cmat, cmat)
103103

104104
def test_gen_cmat_withfreq ():
105105
ldl = LDL()
106106
ldl.gen_cmat(words=words, freqs=freqs)
107-
assert ldl.cmat.identical(cmatfreq)
107+
xr.testing.assert_allclose(ldl.cmat, cmatfreq)
108108

109109
def test_gen_smat ():
110110
ldl = LDL()
111111
ldl.gen_smat(embed_or_df=semdf, words=words)
112-
assert ldl.smat.identical(smat)
112+
xr.testing.assert_allclose(ldl.smat, smat)
113113

114114
def test_gen_smat_withfreq ():
115115
ldl = LDL()
116116
ldl.gen_smat(embed_or_df=semdf, words=words, freqs=freqs)
117-
assert ldl.smat.identical(smatfreq)
117+
xr.testing.assert_allclose(ldl.smat, smatfreq)

tests/test_mapping.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ def test_gen_smat_sim (ind, form, sep, dim_size, mn, sd, incl, diff, seed):
9090
_smat = xr.open_dataarray(_smat)
9191
smat = pm.gen_smat_sim(infl, form, sep, dim_size, mn, sd, incl, diff, seed)
9292
if seed is None:
93-
assert not smat.identical(_smat)
93+
assert not smat.round(10).identical(_smat.round(10))
9494
else:
95-
assert smat.identical(_smat)
95+
xr.testing.assert_allclose(smat, _smat)
9696

9797

9898
def test_gen_fmat():
@@ -101,15 +101,15 @@ def test_gen_fmat():
101101
fmat = pm.gen_fmat(cmat, smat)
102102
_fmat = '{}/fmat.nc'.format(RESOURCES)
103103
_fmat = xr.open_dataarray(_fmat)
104-
assert fmat.identical(_fmat)
104+
xr.testing.assert_allclose(fmat, _fmat)
105105

106106
def test_gen_gmat():
107107
cmat = pm.gen_cmat(infl.word, gram=3, count=False, noise=0)
108108
smat = pm.gen_smat_sim(infl, form='word', sep='/', dim_size=5, seed=10)
109109
gmat = pm.gen_gmat(cmat, smat)
110110
_gmat = '{}/gmat.nc'.format(RESOURCES)
111111
_gmat = xr.open_dataarray(_gmat)
112-
assert gmat.identical(_gmat)
112+
xr.testing.assert_allclose(gmat, _gmat)
113113

114114
cmat = pm.gen_cmat(infl.word, gram=3, count=False, noise=0)
115115
smat = pm.gen_smat_sim(infl, form='word', sep='/', dim_size=5, seed=10)
@@ -133,7 +133,7 @@ def test_gen_shat (ind, cmat, fmat, smat, hmat):
133133
if ind==3: # Rounding due to rounding errors when producing hmat.
134134
shat = shat.round(10)
135135
_shat = _shat.round(10)
136-
assert shat.identical(_shat)
136+
xr.testing.assert_allclose(shat, _shat)
137137

138138

139139
gmat = pm.gen_gmat(cmat, smat)
@@ -156,7 +156,7 @@ def test_gen_chat (ind, smat, gmat, cmat, hmat):
156156
if ind==3: # Rounding due to rounding errors when producing hmat.
157157
chat = chat.round(10)
158158
_chat = _chat.round(10)
159-
assert chat.identical(_chat)
159+
xr.testing.assert_allclose(chat, _chat)
160160

161161
def test_update_weight_matrix ():
162162
w = np.zeros((4,2))
@@ -215,7 +215,7 @@ def test_incremental_learning_byind01 ():
215215
fmat0_cues_values = ['#a', 'a#', 'an', 'n#']
216216
fmat0_feature_values = ['Word:a', 'Word:an']
217217
fmat0 = xr.DataArray(np.array(fmat0_values).reshape(fmat0_shape), dims=fmat0_dims, coords={'cues':fmat0_cues_values, 'feature':fmat0_feature_values})
218-
assert fmat_test.identical(fmat0)
218+
xr.testing.assert_allclose(fmat_test, fmat0)
219219

220220
def test_incremental_learning_byind02 ():
221221
cmat = pm.gen_cmat(['a','an'], gram=2)

tests/test_measures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def test_semantic_support (ind, word, cue):
5050
assert e_info == 'xxx'
5151
else:
5252
sp = lmea.semantic_support(word, cue, chat)
53-
_sp = ["0.0000000000", "1.0000000000", "None", "1.0000000000", "1.0000000000", "None", "None", "None", "None"]
54-
assert '{:12.10f}'.format(sp) == _sp[ind]
53+
_sp = [0, 1, "None", 1, 1, "None", "None", "None", "None"]
54+
assert round(sp,10) == _sp[ind]
5555

5656
pars_semantic_support_word = [ (i,j) for i,j in enumerate(wrd) ]
5757
@pytest.mark.parametrize('ind, word', pars_semantic_support_word)

0 commit comments

Comments
 (0)