コード例 #1
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
    def test_StarAtom_empty_entailment_failure(self, x):
        """
        Check that the empty StarAtom does not contain a non-empty StarAtom.
        """
        e1 = StarAtom(*x)
        e2 = StarAtom()

        assert not e2.contains(e1)
コード例 #2
0
ファイル: test_products.py プロジェクト: elhusseiniali/sre
    def test_containment_success(self):
        e1 = StarAtom("start", "stop")
        e2 = StarAtom("start")

        p1 = Product(e1)
        p2 = Product(e2)

        assert p1.contains(p2)
コード例 #3
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
    def test_StarAtom_empty_entailment_success(self, x):
        """
        Check that a StarAtom made with non-empty allowed messages contains
        the StarAtom made with the empty sequence.
        """
        e1 = StarAtom(*x)
        e2 = StarAtom()

        assert e1.contains(e2)
コード例 #4
0
ファイル: test_products.py プロジェクト: elhusseiniali/sre
    def test_containment_failure(self, x, y):
        z = set.union(x, y)
        e1 = StarAtom(*x)
        e2 = StarAtom(*z)

        p1 = Product(e1)
        p2 = Product(e2)

        assert not p1.contains(p2)
コード例 #5
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
    def test_Mixed_containment_failure(self, x):
        """
        Check that a LetterAtom cannot contain a StarAtom,
        and that a StarAtom contains a LetterAtom (when they're
        made from the same message).
        """
        e1 = LetterAtom(x)
        e2 = StarAtom(x)

        assert not e1.contains(e2)
        assert e2.contains(e1)
コード例 #6
0
ファイル: test_products.py プロジェクト: elhusseiniali/sre
    def test_create_from_product(self, x, y):
        """
        Check that a product made from products is a list of atoms (and not
        a list of products and atoms).
        """
        e1 = StarAtom(*x)
        e2 = StarAtom(*y)

        p1 = Product(e1)
        p2 = Product(p1, e2)

        assert p2.atoms == tuple([e1, e2])
コード例 #7
0
ファイル: test_products.py プロジェクト: elhusseiniali/sre
    def test_phs(self):
        '''Suggested tests by Dr. Philippe (phs75).
        '''
        ea = LetterAtom('a')
        eb = LetterAtom('b')
        zs = StarAtom()
        a_s = StarAtom('a')
        bs = StarAtom('b')
        a_bs = StarAtom('a', 'b')
        ep = Product()

        assert ea.contains(zs)
        assert Product(ea).contains(ep)
        assert not ea.contains(a_s)
        assert a_s.contains(ea)
        assert a_s.contains(zs)
        assert Product(a_s).contains(ep)
        assert not a_s.contains(bs)
        assert not a_s.contains(a_bs)
        assert not ep.contains(ea)
        assert not ep.contains(a_s)
        assert not ep.contains(a_bs)
        assert not ep.contains(Product(ea, ea))
        assert ep.contains(ep)
        assert ep.contains(zs)
        assert ep.contains(Product(zs))
        assert ep.contains(Product(zs, zs))
        assert ea.contains(zs)
        assert Product(ea).contains(Product(zs, ep, ea, zs))
        assert not ea.contains(a_s)
        assert Product(a_s).contains(Product(ea, a_s))
        assert Product(a_s).contains(Product(ea, ep, zs, ea, a_s))
        assert Product(a_bs).contains(Product(ea, bs, a_s, bs))
        assert not Product(a_s).contains(Product(ea, a_bs, eb))
コード例 #8
0
    def test_simple_creation(self):
        """Check that we can plainly create an SRE from atoms
        or from products.
        """
        e1 = StarAtom("start", "stop")
        e2 = LetterAtom("reset")
        e3 = StarAtom("help")

        p1 = Product(e1, e2)
        p2 = Product(e3)

        s1 = SRE(p1, p2)
        s2 = SRE(e1, e2, e3)
        assert s1
        assert s2
コード例 #9
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
    def test_StarAtom_entailment_success(self, x, y):
        """
        Input:
            x, y: sets of allowed messages

        e1 = StarAtom(x)
        e2 = StarAtom(x UNION y)

        Output:
            True (e2 contains e1)
        """
        z = set.union(x, y)
        e1 = StarAtom(*x)
        e2 = StarAtom(*z)

        assert e2.contains(e1)
コード例 #10
0
        def test_containment_failure(self, x, y):
            """Check that a smaller SRE does not contain a larger one.

            Parameters
            ----------
            x, y : [set]
                sets of allowed messages.
            """
            z = set.union(x, y)
            e1 = StarAtom(*x)
            e2 = StarAtom(*z)

            s1 = SRE(e1)
            s2 = SRE(e2)

            assert not s1.contains(s2)
コード例 #11
0
ファイル: test_products.py プロジェクト: elhusseiniali/sre
    def test_containment_naive_success(self, x):
        e1 = StarAtom(*x)
        p1 = Product(e1)
        p2 = Product(e1)

        assert p1.contains(p2)
        assert p2.contains(p1)
コード例 #12
0
        def test_general_containment_success(self, x, y):
            """Check that a bigger (or equal) SRE contains a smaller one.

            Parameters
            ----------
            x, y : [set]
                sets of allowed messages.
            """
            z = set.union(x, y)
            e1 = StarAtom(*x)
            e2 = StarAtom(*z)

            s1 = SRE(e1)
            s2 = SRE(e2)

            assert s2.contains(s1)
コード例 #13
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
 def test_StarAtom_creation_failure(self, x):
     """
     Check that creation fails with a forbidden message.
     The pattern should be changed if ALLOWED_MESSAGES is changed.
     """
     e1 = StarAtom(*x)
     e1
コード例 #14
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
 def test_StarAtom_empty_string_create_fail(self):
     """
     Check that we cannot create an object of type StarAtom
     using an empty string.
     """
     e1 = StarAtom("")
     e1
コード例 #15
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
    def test_empty_star_in_letter(self, x):
        """
        Check that the empty StarAtom is in an arbitrary LetterAtom.
        """
        e1 = LetterAtom(x)
        e2 = StarAtom()

        assert e1.contains(e2)
コード例 #16
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
 def test_StarAtom_list_creation(self):
     """
     Check that you can create a StarAtom
     using a list (or a set, or a tuple).
     """
     # Use * if passing a list, set, or tuple
     e1 = StarAtom(*['a', 'b', 'c'])
     assert e1
コード例 #17
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
 def test_StarAtom_empty_create(self):
     """
     Check that we can create an object of type StarAtom
     without passing any messages (i.e. it is a language
     over the empty sequence of messages).
     """
     e1 = StarAtom()
     assert len(e1) == 0
コード例 #18
0
ファイル: test_products.py プロジェクト: elhusseiniali/sre
    def test_plain_empty_containment(self):
        """ Check that the empty product and the product made with the empty
        StarAtom contain each other.
        """
        p1 = Product(StarAtom())
        p2 = Product()

        assert p1.contains(p2)
        assert p2.contains(p1)
コード例 #19
0
ファイル: test_operations.py プロジェクト: elhusseiniali/sre
    def test_single_write(self):
        e1 = StarAtom("start", "stop")
        p1 = Product(e1)
        p2 = p1.write("test")

        s1 = SRE(p1)
        s2 = s1.write("test")

        assert p2.contains(LetterAtom("test"))
        assert s2.contains(SRE(Product(LetterAtom("test"))))
コード例 #20
0
ファイル: test_products.py プロジェクト: elhusseiniali/sre
    def test_general_containment_success(self, x, y):
        """Check that a bigger product contains a smaller one.

        Parameters
        ----------
        x, y : [set]
            sets of allowed messages.

        e1 = StarAtom(x)
        e2 = StarAtom(x UNION y)
        """
        z = set.union(x, y)
        e1 = StarAtom(*x)
        e2 = StarAtom(*z)

        p1 = Product(e1)
        p2 = Product(e2)

        assert p2.contains(p1)
コード例 #21
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
    def test_StarAtom_entailment_failure(self, x, y):
        """
        Input:
            x, y: sets of allowed messages

        e1 = StarAtom(x)
        e2 = StarAtom(x UNION y)

        Output:
            False (e1 does not contain e2)

        Note:
            Size constraints used to make sure the sets aren't identical.
        """
        z = set.union(x, y)
        e1 = StarAtom(*x)
        e2 = StarAtom(*z)

        assert not e1.contains(e2)
コード例 #22
0
    def test_empty_creation(self):
        """Check that we can create an SRe from the empty StarAtom
        or from the empty Product, or from Product(StarAtom()).
        """
        e1 = StarAtom()
        p1 = Product(e1)
        p2 = Product()

        s1 = SRE(p1, p2)

        assert s1
コード例 #23
0
ファイル: test_operations.py プロジェクト: elhusseiniali/sre
    def test_single_read(self):
        e1 = StarAtom("start", "stop")
        e2 = LetterAtom("reset")

        p1 = Product(e1, e2)
        p2 = p1.read("reset")

        s1 = SRE(p1)
        s2 = s1.read("reset")

        assert not s2.messages()
        assert not p2.messages()
コード例 #24
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
    def test_LetterAtom_absorption(self, x):
        """
        Check that a LetterAtom does not absorb itself, it does
        not absorb another LetterAtom made from the same message,
        but only absorbs an empty StarAtom.
        """
        e1 = LetterAtom(x)
        e2 = LetterAtom(x)
        e3 = StarAtom()

        assert not e1.absorbs(e1)
        assert not e1.absorbs(e2)
        assert e1.absorbs(e3)
コード例 #25
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
    def test_StarAtom_naive_entailment_success(self, x):
        """
        Check that two StarAtoms, made from the same messages,
        contain each other.
        """
        e1 = StarAtom(*x)
        e2 = StarAtom(*x)

        assert e1.contains(e2) & e2.contains(e1)
コード例 #26
0
ファイル: test_atoms.py プロジェクト: elhusseiniali/sre
    def test_StarAtom_absorption(self, x, y):
        """Check that a StarAtom absorbs a LetterAtom made of the same
        message, and that it is absorbed by a StarAtom made of (at least)
        the same message.
        """
        e1 = StarAtom(x)
        e2 = LetterAtom(x)
        e3 = StarAtom(x, y)

        assert e1.absorbs(e2)
        assert e3.absorbs(e1)
コード例 #27
0
    def test_naive_containment(self):
        """Check that two SREs made of the same products contain each other.
        Also check that an SRE made from a product made of one atom,
        contains an SRE made of the atom directly.
        """
        e1 = StarAtom("start")
        p1 = Product(e1)

        s0 = SRE()
        s1 = SRE(p1)
        s2 = SRE(p1)
        s3 = SRE(e1)

        assert s1.contains(s2)
        assert s2.contains(s1)
        assert s1.contains(s0)
        assert s2.contains(s0)
        assert not s0.contains(s1)
        assert not s0.contains(s2)
        assert s3.contains(s1)
        assert s1.contains(s3)

        @given(sets(from_regex(ALLOWED_MESSAGES, fullmatch=True), min_size=0),
               sets(from_regex(ALLOWED_MESSAGES, fullmatch=True), min_size=0))
        def test_general_containment_success(self, x, y):
            """Check that a bigger (or equal) SRE contains a smaller one.

            Parameters
            ----------
            x, y : [set]
                sets of allowed messages.
            """
            z = set.union(x, y)
            e1 = StarAtom(*x)
            e2 = StarAtom(*z)

            s1 = SRE(e1)
            s2 = SRE(e2)

            assert s2.contains(s1)

        @given(
            sets(from_regex(ALLOWED_MESSAGES, fullmatch=True),
                 min_size=0,
                 max_size=2),
            sets(from_regex(ALLOWED_MESSAGES, fullmatch=True), min_size=3))
        def test_containment_failure(self, x, y):
            """Check that a smaller SRE does not contain a larger one.

            Parameters
            ----------
            x, y : [set]
                sets of allowed messages.
            """
            z = set.union(x, y)
            e1 = StarAtom(*x)
            e2 = StarAtom(*z)

            s1 = SRE(e1)
            s2 = SRE(e2)

            assert not s1.contains(s2)
コード例 #28
0
ファイル: test_products.py プロジェクト: elhusseiniali/sre
    def test_empty_containment(self, x):
        p0 = Product()
        p1 = Product(StarAtom(*x))

        assert p1.contains(p0)
        assert not p0.contains(p1)
コード例 #29
0
ファイル: test_products.py プロジェクト: elhusseiniali/sre
    def test_two_mixed_atoms(self, x, y):
        e1 = StarAtom(*x)
        e2 = LetterAtom(y)

        p = Product(e1, e2)
        assert p
コード例 #30
0
ファイル: test_products.py プロジェクト: elhusseiniali/sre
    def test_star_atom(self, x):
        e1 = StarAtom(*x)

        p = Product(e1)
        assert p