Skip to content

Commit

Permalink
Black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrada committed Sep 11, 2024
1 parent f7d0882 commit b11d780
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 55 deletions.
10 changes: 5 additions & 5 deletions tests/assert_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def __init__(self, test: unittest.TestCase, actual: T) -> None:
self.test.maxDiff = None # show all differences

def repr_is(
self,
representation: str,
/,
with_alias: str | None = None,
validate: bool = True,
self,
representation: str,
/,
with_alias: str | None = None,
validate: bool = True,
) -> Self:
"""Asserts that the obtained object's representation is equal to the expected representation."""

Expand Down
21 changes: 11 additions & 10 deletions tests/test_defuzzifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def has_attribute(self, **kwargs: Any) -> Self:
return self

def defuzzifies(
self,
minimum: float,
maximum: float,
terms: dict[fl.Term, float],
vectorized: bool = True,
self,
minimum: float,
maximum: float,
terms: dict[fl.Term, float],
vectorized: bool = True,
) -> Self:
"""Assert that the defuzzification of the given terms result in the expected values."""
for term, expected in terms.items():
Expand All @@ -60,6 +60,7 @@ def defuzzifies(
err_msg=f"{fl.Op.class_name(self.actual)}({term}) = {obtained}, but expected {expected}",
)
if vectorized:

class StackTerm(fl.Term):
def __init__(self, terms: list[fl.Term]) -> None:
super().__init__("_")
Expand Down Expand Up @@ -415,7 +416,7 @@ def test_weighted_defuzzifier(self) -> None:

class BaseWeightedDefuzzifier(fl.WeightedDefuzzifier):
def defuzzify(
self, term: fl.Term, minimum: float = fl.nan, maximum: float = fl.nan
self, term: fl.Term, minimum: float = fl.nan, maximum: float = fl.nan
) -> Scalar:
return fl.nan

Expand Down Expand Up @@ -526,8 +527,8 @@ def test_weighted_average(self) -> None:

defuzzifier = fl.WeightedAverage()
with self.assertRaisesRegex(
ValueError,
re.escape("expected an Aggregated term, but found <class 'fuzzylite.term.Triangle'>"),
ValueError,
re.escape("expected an Aggregated term, but found <class 'fuzzylite.term.Triangle'>"),
):
defuzzifier.defuzzify(fl.Triangle())

Expand Down Expand Up @@ -628,8 +629,8 @@ def test_weighted_sum(self) -> None:
defuzzifier = fl.WeightedSum()

with self.assertRaisesRegex(
ValueError,
re.escape("expected an Aggregated term, but found <class 'fuzzylite.term.Triangle'>"),
ValueError,
re.escape("expected an Aggregated term, but found <class 'fuzzylite.term.Triangle'>"),
):
defuzzifier.defuzzify(fl.Triangle())

Expand Down
8 changes: 4 additions & 4 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class EngineAssert(BaseAssert[fl.Engine]):
"""Engine assert."""

def has_type(
self,
expected: fl.Engine.Type | set[fl.Engine.Type],
/,
reasons: list[str] | None = None,
self,
expected: fl.Engine.Type | set[fl.Engine.Type],
/,
reasons: list[str] | None = None,
) -> Self:
"""Asserts the engine has the expected type."""
obtained_reasons: list[str] = []
Expand Down
8 changes: 4 additions & 4 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class FunctionFactoryAssert(BaseAssert[fl.FunctionFactory]):
"""Function Factory assert."""

def contains_exactly(
self,
elements: set[str],
element_type: fl.Function.Element.Type | None = None,
self,
elements: set[str],
element_type: fl.Function.Element.Type | None = None,
) -> Self:
"""Assert the factory contains only the expected elements."""
if element_type == fl.Function.Element.Type.Operator:
Expand Down Expand Up @@ -129,7 +129,7 @@ def precedence_is_higher(self, a: str, b: str) -> Self:
elements[a].precedence,
elements[b].precedence,
msg=f"expected precedence of {a} ({elements[a].precedence}) > {b} ({elements[b].precedence}), "
f"but got {elements[a].precedence} <= {elements[b].precedence}",
f"but got {elements[a].precedence} <= {elements[b].precedence}",
)
return self

Expand Down
2 changes: 1 addition & 1 deletion tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_library_exports_dir(self) -> None:
GaussianProduct Linear PiShape Ramp Rectangle SShape SemiEllipse Sigmoid SigmoidDifference
SigmoidProduct Spike Term Trapezoid Triangle ZShape
types Array Scalar ScalarArray
types Array Scalar ScalarArray Self
variable InputVariable OutputVariable Variable
"""
Expand Down
46 changes: 23 additions & 23 deletions tests/test_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def configured_as(self, parameters: str) -> Self:
return self

def has_memberships(
self, x_mf: dict[float, float], heights: Sequence[float] | None = None
self, x_mf: dict[float, float], heights: Sequence[float] | None = None
) -> Self:
"""Assert the term's membership function produces $f(x{_keys}) = mf_{values}$."""
inputs = fl.scalar(list(x_mf.keys()))
Expand Down Expand Up @@ -132,10 +132,10 @@ def has_tsukamotos(self, x_mf: dict[float, float]) -> Self:
return self

def apply(
self,
func: Callable[..., None],
args: Sequence[str] = (),
**keywords: dict[str, object],
self,
func: Callable[..., None],
args: Sequence[str] = (),
**keywords: dict[str, object],
) -> Self:
"""Applies function on the term with the arguments and keywords as parameters."""
func(self.actual, *args, **keywords)
Expand Down Expand Up @@ -800,19 +800,19 @@ def test_discrete(self) -> None:

term = fl.Discrete()
with self.assertRaisesRegex(
ValueError,
re.escape("expected xy to contain coordinate pairs, but it is empty"),
ValueError,
re.escape("expected xy to contain coordinate pairs, but it is empty"),
):
term.membership(0.0)
with self.assertRaisesRegex(
ValueError,
re.escape("expected xy to contain coordinate pairs, but it is empty"),
ValueError,
re.escape("expected xy to contain coordinate pairs, but it is empty"),
):
term.values = fl.Discrete.to_xy([], [])
term.membership(0.0)
with self.assertRaisesRegex(
ValueError,
re.escape("expected xy to have with 2 columns, but got 1 in shape (1,): [1.]"),
ValueError,
re.escape("expected xy to have with 2 columns, but got 1 in shape (1,): [1.]"),
):
term.values = fl.array([1.0])
term.membership(0.0)
Expand Down Expand Up @@ -1922,7 +1922,7 @@ def value_is(self, expected: str) -> FunctionNodeAssert:
return self

def evaluates_to(
self, expected: float, variables: dict[str, fl.Scalar] | None = None
self, expected: float, variables: dict[str, fl.Scalar] | None = None
) -> FunctionNodeAssert:
"""Assert the node evaluates to the expected value (optionally) given variables."""
obtained = self.actual.evaluate(variables)
Expand Down Expand Up @@ -1979,11 +1979,11 @@ def test_function(self) -> None:
output_a = fl.OutputVariable("o_A")
engine_a = fl.Engine("A", "Engine A", [input_a], [output_a])
with self.assertRaisesRegex(
ValueError,
re.escape(
"expected a map of variables containing the value for 'i_A', "
"but the map contains: {'x': 0.0}"
),
ValueError,
re.escape(
"expected a map of variables containing the value for 'i_A', "
"but the map contains: {'x': 0.0}"
),
):
fl.Function.create("engine_a", "2*i_A + o_A + x").membership(0.0)

Expand All @@ -2010,11 +2010,11 @@ def test_function(self) -> None:

function_a.variables = {"x": nan}
with self.assertRaisesRegex(
ValueError,
re.escape(
"variable 'x' is reserved for internal use of Function term, "
"please remove it from the map of variables: {'x': nan}"
),
ValueError,
re.escape(
"variable 'x' is reserved for internal use of Function term, "
"please remove it from the map of variables: {'x': nan}"
),
):
function_a.membership(0.0)
del function_a.variables["x"]
Expand Down Expand Up @@ -2290,7 +2290,7 @@ def test_function_parse(self) -> None:
"a+~b": "a b ~ +",
"~a*~b": "a ~ b ~ *",
"(sin(pi()/4) + cos(pi/4)) / (~sin(pi()/4) - ~cos(pi/4))": "pi 4.000 / sin pi 4.000 / cos + "
"pi 4.000 / sin ~ pi 4.000 / cos ~ - /",
"pi 4.000 / sin ~ pi 4.000 / cos ~ - /",
}
for infix, postfix in infix_postfix.items():
self.assertEqual(postfix, fl.Function.parse(infix).postfix())
Expand Down
16 changes: 8 additions & 8 deletions tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,14 @@ class TestOutputVariable(unittest.TestCase):
"""Test the output variable."""

def output_variable(
self,
enabled: bool = True,
name: str = "name",
description: str = "description",
minimum: float = -1.0,
maximum: float = 1.0,
default_value: float = fl.nan,
terms: list[fl.Term] | None = None,
self,
enabled: bool = True,
name: str = "name",
description: str = "description",
minimum: float = -1.0,
maximum: float = 1.0,
default_value: float = fl.nan,
terms: list[fl.Term] | None = None,
) -> fl.OutputVariable:
"""Create an output variable."""
return fl.OutputVariable(
Expand Down

0 comments on commit b11d780

Please sign in to comment.