swh:1:snp:e65ec12a3dc489100df2dfc1b0eab4915109f830
Tip revision: d6748f9a1e915d476d4fadb28bb5dd6d378b2286 authored by Jesper Nielsen on 29 September 2022, 15:30:57 UTC
Merge pull request #1993 from GPflow/develop
Merge pull request #1993 from GPflow/develop
Tip revision: d6748f9
test_tag.py
# Copyright 2022 The GPflow Contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import AbstractSet
import pytest
from benchmark.tag import NO_REQ, Tag, TagReq
class TestTag(Tag["TestTag"]):
pass
t1 = TestTag("t1")
t2 = TestTag("t2")
t3 = TestTag("t3")
@pytest.mark.parametrize(
"req,tags,expected_satisfied,expected_repr",
[
# Test single operations:
(NO_REQ, {}, True, "NO_REQ"),
(t1, {t1, t2}, True, "t1"),
(t3, {t1, t2}, False, "t3"),
(t1 & t2, {t1, t2}, True, "t1 & t2"),
(t1 & t3, {t1, t2}, False, "t1 & t3"),
(t1 | t2, {t2}, True, "t1 | t2"),
(t1 | t3, {t2}, False, "t1 | t3"),
(~t1, {t1, t2}, False, "~t1"),
(~t3, {t1, t2}, True, "~t3"),
# Test composition:
(t1 | (t2 & ~t3), {}, False, "t1 | (t2 & (~t3))"),
(t1 | (t2 & ~t3), {t3}, False, "t1 | (t2 & (~t3))"),
(t1 | (t2 & ~t3), {t2}, True, "t1 | (t2 & (~t3))"),
(t1 | (t2 & ~t3), {t2, t3}, False, "t1 | (t2 & (~t3))"),
(t1 | (t2 & ~t3), {t1}, True, "t1 | (t2 & (~t3))"),
(t1 | (t2 & ~t3), {t1, t3}, True, "t1 | (t2 & (~t3))"),
(t1 | (t2 & ~t3), {t1, t2}, True, "t1 | (t2 & (~t3))"),
(t1 | (t2 & ~t3), {t1, t2, t3}, True, "t1 | (t2 & (~t3))"),
],
)
def test_tag_req(
req: TagReq[TestTag], tags: AbstractSet[TestTag], expected_satisfied: bool, expected_repr: str
) -> None:
assert expected_satisfied == req.satisfied(tags)
assert expected_repr == repr(req)