Skip to content

Clarify expressions unit tests organisation #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/unittests/expressions/linear_expressions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ def test_addition(
assert e1 + e2 == expected


def test_addition_of_linear_expressions_with_different_number_of_instances_should_raise_value_error() -> (
None
):
pass


def test_operation_that_leads_to_term_with_zero_coefficient_should_be_removed_from_terms() -> (
None
):
Expand Down
276 changes: 0 additions & 276 deletions tests/unittests/expressions/test_expressions.py

This file was deleted.

11 changes: 11 additions & 0 deletions tests/unittests/expressions/visitor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
45 changes: 45 additions & 0 deletions tests/unittests/expressions/visitor/test_copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.


from andromede.expression import (
AdditionNode,
DivisionNode,
LiteralNode,
ParameterNode,
VariableNode,
)
from andromede.expression.copy import copy_expression
from andromede.expression.equality import expressions_equal
from andromede.expression.expression import (
AllTimeSumNode,
ComponentParameterNode,
MultiplicationNode,
TimeEvalNode,
TimeShiftNode,
)


def test_copy_ast() -> None:
ast = AllTimeSumNode(
DivisionNode(
TimeEvalNode(
AdditionNode([LiteralNode(1), VariableNode("x")]), ParameterNode("p")
),
TimeShiftNode(
MultiplicationNode(LiteralNode(1), VariableNode("x")),
ComponentParameterNode("comp1", "p"),
),
),
)
copy = copy_expression(ast)
assert expressions_equal(ast, copy)
36 changes: 36 additions & 0 deletions tests/unittests/expressions/visitor/test_degree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

import pytest

from andromede.expression import ExpressionDegreeVisitor, LiteralNode, param, var, visit


def test_degree() -> None:
x = var("x")
p = param("p")
expr = (5 * x + 3) / p

assert visit(expr, ExpressionDegreeVisitor()) == 1

expr = x * expr
assert visit(expr, ExpressionDegreeVisitor()) == 2


@pytest.mark.xfail(reason="Degree simplification not implemented")
def test_degree_computation_should_take_into_account_simplifications() -> None:
x = var("x")
expr = x - x
assert visit(expr, ExpressionDegreeVisitor()) == 0

expr = LiteralNode(0) * x
assert visit(expr, ExpressionDegreeVisitor()) == 0
Loading
Loading