From 793a6ce1a493d9209fa4f3b56a6e9b32a1295f9f Mon Sep 17 00:00:00 2001 From: Nicholas Date: Sun, 10 Nov 2024 14:15:05 -0500 Subject: [PATCH] Added equals test --- tests/test_relational.py | 62 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/tests/test_relational.py b/tests/test_relational.py index 16632548..a906e9bc 100644 --- a/tests/test_relational.py +++ b/tests/test_relational.py @@ -2322,8 +2322,66 @@ def test_root_to_string(root: RelationalRoot, output: str): assert root.to_string() == output -# def test_root_equals(first_root: RelationalRoot, second_root: Relational, output: bool): -# assert first_root.equals(second_root) == output +@pytest.mark.parametrize( + "first_root, second_root, output", + [ + pytest.param( + RelationalRoot(build_simple_scan(), [make_column("a"), make_column("b")]), + RelationalRoot(build_simple_scan(), [make_column("a"), make_column("b")]), + True, + id="matching_columns_no_orderings", + ), + pytest.param( + RelationalRoot(build_simple_scan(), [make_column("a"), make_column("b")]), + RelationalRoot(build_simple_scan(), [make_column("b"), make_column("c")]), + False, + id="different_columns_no_orderings", + ), + pytest.param( + RelationalRoot( + build_simple_scan(), + [make_column("a"), make_column("b")], + [make_simple_column_reference("a")], + ), + RelationalRoot( + build_simple_scan(), + [make_column("a"), make_column("b")], + [make_simple_column_reference("a")], + ), + True, + id="matching_columns_with_orderings", + ), + pytest.param( + RelationalRoot( + build_simple_scan(), + [make_column("a"), make_column("b")], + [make_simple_column_reference("a")], + ), + RelationalRoot( + build_simple_scan(), + [make_column("a"), make_column("b")], + [make_simple_column_reference("b")], + ), + False, + id="different_orderings", + ), + pytest.param( + RelationalRoot(build_simple_scan(), [make_column("a"), make_column("b")]), + RelationalRoot(Scan("table2", []), [make_column("a"), make_column("b")]), + False, + id="different_inputs", + ), + pytest.param( + RelationalRoot(build_simple_scan(), [make_column("a"), make_column("b")]), + Scan("table2", [make_column("a"), make_column("b")]), + False, + id="different_nodes", + ), + ], +) +def test_root_equals(first_root: RelationalRoot, second_root: Relational, output: bool): + assert first_root.equals(second_root) == output + # def test_root_can_merge(first_root: RelationalRoot, second_root: RelationalRoot): # assert not first_root.can_merge(second_root)