Exemple #1
0
def test_function_usage():
    @fed_by('Integer')
    def integer_plus_one(integer):
        return integer + 1

    expected = 1
    actual, = strategery.execute(targets=[integer_plus_one],
                                 input={'Integer': 0})
    assert actual == expected
Exemple #2
0
def test_series_of_dependencies():
    @fed_by('Integer')
    def func_one(integer):
        return integer

    @fed_by(func_one)
    def func_two(same_integer):
        return same_integer

    actual, = strategery.execute(targets=[func_two], input={'Integer': 0})
    assert actual == 0
Exemple #3
0
def test_class_usage():
    class IntegerPlusOne(StrategeryFeature):
        @staticmethod
        @fed_by('IntegerParameter')
        def compute(integer):
            return integer + 1

    expected = 1
    actual, = strategery.execute(targets=[IntegerPlusOne],
                                 input={'IntegerParameter': 0})
    assert actual == expected
Exemple #4
0
def test_class_usage_unambiguous():
    class IntegerPlus1(StrategeryFeature):
        @staticmethod
        @fed_by('Integer')
        def compute(integer):
            return integer + 1

    class IntegerPlus2(StrategeryFeature):
        @staticmethod
        @fed_by(IntegerPlus1)
        def compute(integer):
            return integer + 2

    actual, = strategery.execute(targets=[IntegerPlus2], input={'Integer': 0})
    assert actual == 3
Exemple #5
0
def test_series_of_class_usage():
    class IntegerPlusOne(StrategeryFeature):
        def __init__(self, value):
            self.value = value

        @staticmethod
        @fed_by('IntegerParameter')
        def compute(integer: int):
            return IntegerPlusOne(integer + 1)

    class IntegerPlusTwo(StrategeryFeature):
        def __init__(self, value: int):
            self.value = value

        @staticmethod
        @fed_by(IntegerPlusOne)
        def compute(ipo: IntegerPlusOne):
            return IntegerPlusTwo(value=ipo.value + 2)

    expected = 3
    actual, = strategery.execute(targets=[IntegerPlusTwo],
                                 input={'IntegerParameter': 0})
    assert actual.value == expected
Exemple #6
0
    return min(numbers)


@fed_by('ParamListOfNumbers')
def Mean(numbers):
    ''' AKA Average '''
    return 1.0 * sum(numbers) / len(numbers)


@fed_by(Minimum)
def AbsoluteValueMinimum(minimum):
    ''' A highly contrived task for example purposes '''
    return abs(minimum)


# Enable verbose logging:
strategery.engine.logger = sys.stdout

# Provide a list of numbers, get AbsoluteValueMinimum, let strategery figure out the rest.
mean, absolute_value_minimum = strategery.execute(
    targets=[Mean, AbsoluteValueMinimum],
    input={'ParamListOfNumbers': [-1, -2, -3, -4, -5]})

# Disable verbose logging:
strategery.engine.logger = strategery.logging.BypassLogger()

print("")
print('Input: [-1, -2, -3, -4, -5]')
print(f'Mean: {mean}')
print(f'AbsoluteValueMinimum: {absolute_value_minimum}')