From f682ca1af2116e02fcbb61669e4863d7c38c847d Mon Sep 17 00:00:00 2001 From: Mark Bonicillo Date: Thu, 26 Oct 2023 12:41:59 -0700 Subject: [PATCH 1/2] HYP-177 Improve EntitySet.data test --- hypernetx/classes/tests/conftest.py | 26 +++++++------- .../classes/tests/test_entityset_on_dict.py | 36 +++++++++++++++++-- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/hypernetx/classes/tests/conftest.py b/hypernetx/classes/tests/conftest.py index dca99432..b37a0322 100644 --- a/hypernetx/classes/tests/conftest.py +++ b/hypernetx/classes/tests/conftest.py @@ -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], ] ) diff --git a/hypernetx/classes/tests/test_entityset_on_dict.py b/hypernetx/classes/tests/test_entityset_on_dict.py index 9b0e8982..ed589ae1 100644 --- a/hypernetx/classes/tests/test_entityset_on_dict.py +++ b/hypernetx/classes/tests/test_entityset_on_dict.py @@ -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")), @@ -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) From 74a99773d10995bf58e047ff18ea3f75354802a2 Mon Sep 17 00:00:00 2001 From: Mark Bonicillo Date: Wed, 1 Nov 2023 15:32:28 -0700 Subject: [PATCH 2/2] Update tests for soon to be deprecated translate methods --- hypernetx/classes/tests/test_entityset_on_np_array.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hypernetx/classes/tests/test_entityset_on_np_array.py b/hypernetx/classes/tests/test_entityset_on_np_array.py index f4fd04de..1cf02e9e 100644 --- a/hypernetx/classes/tests/test_entityset_on_np_array.py +++ b/hypernetx/classes/tests/test_entityset_on_np_array.py @@ -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)