Ejemplo n.º 1
0
def test_dense_prop_const_int64():

    my_monitor = dense_timed_monitor(
        pattern="{speed > 12.0}",
        semantics="boolean",
        piecewise='linear'
    )

    input_sequence = [
        dict(time=0.0, speed=3.0),
        dict(time=10.0, speed=9.0),
        dict(time=12.0, speed=13.0),
        dict(time=14.0, speed=11.0),
        dict(time=15.0, speed=9.0),
        dict(time=18.0, speed=6.0),
        dict(time=19.0, speed=14.0)
        ]

    result = []
    for x in input_sequence:
        chunk = my_monitor.update(x)
        result.extend(chunk)

    expected = [
        {'time': 0, 'value': False},
        {'time': 11.5, 'value': True},
        {'time': 13.0, 'value': False},
        {'time': 18.75, 'value': True}
    ]

    approx_expected = [pytest.approx(x, 0.001) for x in expected]

    assert result == approx_expected
def check_event(event):
    global last_time, tl_oracle, property, last_res
    event_dict = json.loads(event)
    if not tl_oracle:
        if model == 'dense' and 'time' in event_dict:
            tl_oracle = reelay.dense_timed_monitor(pattern=property.PROPERTY)
        else:
            tl_oracle = reelay.discrete_timed_monitor(
                pattern=property.PROPERTY)
    if 'time' in event_dict:
        if last_time is None:
            last_time = event_dict['time']
            event_dict['time'] = 0
        else:
            event_dict['time'] = event_dict['time'] - last_time
    abs_msg = property.abstract_message(event_dict)
    res = tl_oracle.update(abs_msg)
    if model == 'discrete' and res:
        last_res = res['value']
    if model == 'dense' and res:
        last_res = True
        for d in res:
            if not d['value']:
                last_res = False
                break
    return last_res
Ejemplo n.º 3
0
def test_dense_robust_const_float64():

    my_monitor = dense_timed_monitor(
        pattern=r"{speed > 130} since[:40] {lights_on: true}",
        semantics="robustness",
        piecewise='constant')

    input_sequence = [
        dict(time=0.0, speed=33, lights_on=False),
        dict(time=12.0, speed=63, lights_on=False),
        dict(time=14.0, speed=93, lights_on=True),
        dict(time=18.0, speed=133, lights_on=False),
        dict(time=21.0, speed=134, lights_on=False),
        dict(time=26.0, speed=133, lights_on=False),
        dict(time=45.0, speed=132, lights_on=False),
        dict(time=68.0, speed=132, lights_on=False),
    ]

    result = []
    for x in input_sequence:
        chunk = my_monitor.update(x)
        result.extend(chunk)

    print(result)

    expected = [{
        'time': 0.0,
        'value': -float('inf')
    }, {
        'time': 14.0,
        'value': float('inf')
    }, {
        'time': 18.0,
        'value': 3
    }, {
        'time': 45.0,
        'value': 2
    }, {
        'time': 58.0,
        'value': -float('inf')
    }]

    approx_expected = [pytest.approx(x, 0.001) for x in expected]

    assert result == approx_expected
def test_dense_categ_const_float64():

    my_monitor = dense_timed_monitor(pattern=r"""forall[sensor].
            {sensor_id: *sensor, action: send_data}
                implies
            once[:40]{sensor_id: *sensor, action: calibrated}
            """,
                                     semantics="boolean",
                                     piecewise='constant')

    input_sequence = [
        dict(time=0.0),
        dict(time=6.0, sensor_id="1", action="calibrated"),
        dict(time=12.0, sensor_id="2", action="calibrated"),
        dict(time=15.0, sensor_id="1", action="send_data"),
        dict(time=24.0, sensor_id="1", action="send_data"),
        dict(time=27.0, sensor_id="1", action="send_data"),
        dict(time=32.0, sensor_id="1", action="calibrated"),
        dict(time=46.0, sensor_id="2", action="send_data"),
        dict(time=49.0, sensor_id="1", action="send_data"),
        dict(time=56.0, sensor_id="1", action="send_data"),
        dict(time=62.0, sensor_id="2", action="send_data"),
        dict(time=67.0, sensor_id="1", action="send_data"),
    ]

    result = []
    for x in input_sequence:
        chunk = my_monitor.update(x)
        print(chunk)
        result.extend(chunk)

    expected = [
        {
            'time': 0.0,
            'value': True
        },
        {
            'time': 62.0,
            'value': False
        },
    ]

    approx_expected = [pytest.approx(x, 0.001) for x in expected]

    assert result == approx_expected
Ejemplo n.º 5
0
faulty_sys_behavior = [
    dict(time=0,
         door_open=False,
         dow_suppressed=False,
         door_open_warning=False),
    dict(time=1, door_open=True, dow_suppressed=False,
         door_open_warning=False),
    dict(time=6, door_open=True, dow_suppressed=False, door_open_warning=True),
    dict(time=7, door_open=True, dow_suppressed=True, door_open_warning=False),
    dict(time=8, door_open=True, dow_suppressed=True, door_open_warning=True),
    dict(time=9),
]

my_monitor_1 = reelay.dense_timed_monitor(
    pattern=
    r"(historically[0:5]{door_open} and not {dow_suppressed}) -> {door_open_warning}"
)

my_monitor_2 = reelay.dense_timed_monitor(
    pattern=r"{door_open_warning} -> historically[0:5]{door_open}")

my_monitor_3 = reelay.dense_timed_monitor(
    pattern=r"{door_open_warning} -> not {dow_suppressed}")

my_monitor_4 = reelay.dense_timed_monitor(
    pattern=
    r"{door_open_warning} -> not(once[1:1]({door_open} since {door_open_warning}))"
)

ar1 = []
ar2 = []