def test_can_add_condition_to_engine():
    engine = RuleEngine()

    @engine.condition()
    def is_equal(a: int, b: int) -> bool:
        return a == b

    assert len(engine.conditions) == 1
    assert engine.conditions["is_equal"]["function"](1, 1)
    assert not engine.conditions["is_equal"]["function"](1, 2)
def test_can_add_action_to_engine():
    engine = RuleEngine()

    @engine.action()
    def is_equal(a: int, b: int) -> bool:
        return a == b

    assert len(engine.actions) == 1
    assert hasattr(engine.actions["is_equal"]["function"], "__call__")
    assert engine.actions["is_equal"]["function"](1, 1)
    assert not engine.actions["is_equal"]["function"](1, 2)
def test_can_run_rules(json_rule_can_increment):
    engine = RuleEngine()
    number_to_be_incremented = 1

    @engine.condition()
    def is_smaller_than(compared_to: int) -> bool:
        return number_to_be_incremented < compared_to

    @engine.action()
    def increment_number() -> None:
        nonlocal number_to_be_incremented
        number_to_be_incremented += 1

    engine.run(json_rule_can_increment)
    assert number_to_be_incremented == 2
import pytest
from sauron_rule_engine.rule_engine import RuleEngine
from enum import Enum

engine = RuleEngine()


class Color(str, Enum):
    red = "R"
    green = "G"
    blue = "B"


@engine.condition("Primeira Condição")
def first_condition(lower_number: int = 10, greater_number: int = 20) -> bool:
    """
    Checks if first number is lower than the first
    - lower_number: Number expected to be low
    - higher_number: Number expected to be high
    """
    return lower_number < greater_number


@engine.condition("é vermelho?")
def is_red(color: Color) -> bool:
    """
    Checks if the color is red
    """
    return color == color.red