Skip to content

Commit

Permalink
Pull request #118: HYP-177 Improve EntitySet.data test
Browse files Browse the repository at this point in the history
Merge in HYP/hypernetx from HYP-177-improve-entityset-data-test to develop

* commit '74a99773d10995bf58e047ff18ea3f75354802a2':
  Update tests for soon to be deprecated translate methods
  HYP-177 Improve EntitySet.data test
  • Loading branch information
bonicim committed Nov 3, 2023
2 parents 0fd55db + 74a9977 commit 091bd7b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
26 changes: 13 additions & 13 deletions hypernetx/classes/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,28 @@ def __init__(self, static=False):
)
self.labels = OrderedDict(
[
("edges", [p, r, s, l, o, i]),
("edges", [i, l, o, p, r, s]),
("nodes", [a, c, e, k, t1, t2, v]),
]
)

self.data = np.array(
[
[0, 0],
[0, 1],
[0, 3],
[1, 0],
[1, 2],
[2, 0],
[2, 3],
[2, 5],
[2, 6],
[3, 0],
[3, 1],
[3, 2],
[4, 4],
[4, 5],
[3, 3],
[4, 0],
[4, 2],
[5, 0],
[5, 3],
[5, 5],
[5, 6],
[1, 1],
[1, 2],
[2, 4],
[2, 5],
[0, 3],
[0, 5],
]
)

Expand Down
36 changes: 33 additions & 3 deletions hypernetx/classes/tests/test_entityset_on_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
"entity, data, data_cols, labels",
[
(lazy_fixture("sbs_dict"), None, (0, 1), None),
(lazy_fixture("sbs_dict"), None, (0, 1), lazy_fixture("sbs_labels")),
(
lazy_fixture("sbs_dict"),
None,
(0, 1),
lazy_fixture("sbs_labels"),
), # labels are ignored if entity is provided
(lazy_fixture("sbs_dict"), None, ["edges", "nodes"], None),
(lazy_fixture("sbs_dict"), lazy_fixture("sbs_data"), (0, 1), None),
(None, lazy_fixture("sbs_data"), (0, 1), lazy_fixture("sbs_labels")),
Expand Down Expand Up @@ -154,10 +159,35 @@ def test_dataframe(self, entity, data, data_cols, labels, sbs):
assert actual_node_row0 in ["A", "C", "K"]
assert actual_cell_weight_row0 == 1

# TODO: validate state of 'data'
def test_data(self, entity, data, data_cols, labels, sbs):
es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels)
assert len(es.data) == 15

actual_data = es.data

assert len(actual_data) == 15

expected_data = np.array(
[
[3, 0],
[3, 1],
[3, 3],
[4, 0],
[4, 2],
[5, 0],
[5, 3],
[5, 5],
[5, 6],
[1, 1],
[1, 2],
[2, 4],
[2, 5],
[0, 5],
[0, 3],
]
)
assert np.array_equal(
np.sort(actual_data, axis=0), np.sort(expected_data, axis=0)
)

def test_properties(self, entity, data, data_cols, labels, sbs):
es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels)
Expand Down
4 changes: 2 additions & 2 deletions hypernetx/classes/tests/test_entityset_on_np_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def test_dimensions_equal_dimsize(self, sbs_data, sbs_labels):

def test_translate(self, sbs_data, sbs_labels):
ent_sbs = EntitySet(data=np.asarray(sbs_data), labels=sbs_labels)
assert ent_sbs.translate(0, 0) == "P"
assert ent_sbs.translate(0, 0) == "I"
assert ent_sbs.translate(1, [3, 4]) == ["K", "T1"]

def test_translate_arr(self, sbs_data, sbs_labels):
ent_sbs = EntitySet(data=np.asarray(sbs_data), labels=sbs_labels)
assert ent_sbs.translate_arr((0, 0)) == ["P", "A"]
assert ent_sbs.translate_arr((0, 0)) == ["I", "A"]

def test_uidset_by_level(self, sbs_data, sbs_labels):
ent_sbs = EntitySet(data=np.asarray(sbs_data), labels=sbs_labels)
Expand Down

0 comments on commit 091bd7b

Please sign in to comment.