Exemple #1
0
def test_conjoin_type_hints():
    fol = _fol.Context()
    fol.declare(x=(-4, 5), y=(-7, 15))
    vrs = ['x']
    u = tyh._conjoin_type_hints(vrs, fol)
    u_ = fol.add_expr('-4 <= x  /\  x <= 5')
    assert u == u_, (u, u_)
    vrs = ['y']
    u = tyh._conjoin_type_hints(vrs, fol)
    u_ = fol.add_expr('-7 <= y  /\  y <= 15')
    assert u == u_, (u, u_)
    vrs = ['x', 'y']
    u = tyh._conjoin_type_hints(vrs, fol)
    u_ = fol.add_expr('-4 <= x  /\  x <= 5 /\ ' '-7 <= y  /\  y <= 15')
    assert u == u_, (u, u_)
Exemple #2
0
def test_conjoin_type_hints():
    fol = _fol.Context()
    fol.declare(x=(-4, 5), y=(-7, 15))
    vrs = ['x']
    u = tyh._conjoin_type_hints(vrs, fol)
    u_ = fol.add_expr('-4 <= x  /\  x <= 5')
    assert u == u_, (u, u_)
    vrs = ['y']
    u = tyh._conjoin_type_hints(vrs, fol)
    u_ = fol.add_expr('-7 <= y  /\  y <= 15')
    assert u == u_, (u, u_)
    vrs = ['x', 'y']
    u = tyh._conjoin_type_hints(vrs, fol)
    u_ = fol.add_expr(
        '-4 <= x  /\  x <= 5 /\ '
        '-7 <= y  /\  y <= 15')
    assert u == u_, (u, u_)
Exemple #3
0
def _care_implies_type_hints(f, care, fol):
    """Return `True` if `|= care => type_hints`."""
    vrs = joint_support([f, care], fol)
    type_hints = tyh._conjoin_type_hints(vrs, fol)
    r = type_hints | ~care
    if r != fol.true:
        vrs = fol.support(r)
        s = ('`care => type_hints` fails '
             'for variables: {vrs}').format(vrs=_comma_sorted(vrs))
        log.warning(s)
    return r == fol.true
Exemple #4
0
def _care_implies_type_hints(f, care, fol):
    """Return `True` if `|= care => type_hints`."""
    vrs = joint_support([f, care], fol)
    type_hints = tyh._conjoin_type_hints(vrs, fol)
    r = type_hints | ~ care
    if r != fol.true:
        vrs = fol.support(r)
        s = ('`care => type_hints` fails '
             'for variables: {vrs}').format(
                vrs=_comma_sorted(vrs))
        log.warning(s)
    return r == fol.true
Exemple #5
0
def test_dumps_cover():
    fol = _fol.Context()
    fol.declare(x=(0, 4), y=(-5, 9))
    # care = TRUE
    s = '2 <= x  /\  x <= 4'
    u = fol.add_expr(s)
    care = fol.true
    cover = cov.minimize(u, care, fol)
    s = cov.dumps_cover(cover, u, care, fol)
    s_ = (
        '(* `f` depends on:  x *)\n'
        '(* `care` depends on:   *)\n'
        '(* The minimal cover is: *)\n'
        '(x \in 2 .. 4)')
    assert s == s_, (s, s_)
    # care doesn't imply type hints
    s = cov.dumps_cover(
        cover, u, care, fol,
        show_dom=True)
    s_ = (
        '(* `f` depends on:  x *)\n'
        '(* `care` depends on:   *)\n'
        '(* The minimal cover is: *)\n'
        '(x \in 2 .. 4)')
    assert s == s_, (s, s_)
    # with limits
    s = cov.dumps_cover(
        cover, u, care, fol,
        show_dom=True,
        show_limits=True)
    s_ = (
        '(* `f` depends on:  x *)\n'
        '(* `care` depends on:   *)\n'
        '(* The minimal cover is: *)\n'
        ' /\ x \in 0 .. 7\n'
        ' /\ (x \in 2 .. 4)')
    assert s == s_, (s, s_)
    # care = type hints
    care = tyh._conjoin_type_hints(['x', 'y'], fol)
    cover = cov.minimize(u, care, fol)
    s = cov.dumps_cover(
        cover, u, care, fol,
        show_dom=True)
    s_ = (
        '(* `f` depends on:  x *)\n'
        '(* `care` depends on:  x, y *)\n'
        '(* The minimal cover is: *)\n'
        ' /\ x \in 0 .. 4\n'
        ' /\ y \in -5 .. 9\n'
        ' /\ (x \in 2 .. 4)\n'
        ' /\ care expression')
    assert s == s_, (s, s_)
Exemple #6
0
    def implies_type_hints(self, u, vrs):
        """Return `True` if `u => TypeInv` for all vars.

        All declared variables and constants are taken into
        account.
        """
        # not named `assert_type_invariant` because the
        # assertion is about the state predicate `u`,
        # so a static conclusion.
        vrs = {var for var in self.vars
               if not stx.isprimed(var)}
        type_hints = tyh._conjoin_type_hints(vrs, self)
        r = type_hints | ~ u
        return r == self.true
Exemple #7
0
    def implies_type_hints(self, u, vrs=None):
        """Return `True` if `u => TypeHints` for `vrs`.

        If `vrs is None`, then all declared variables and constants
        are taken into account.
        """
        # This function is not named `assert_type_invariant`
        # because the assertion is about the state predicate `u`,
        # so a static conclusion.
        #
        if vrs is None:
            vrs = {var for var in self.vars if not stx.isprimed(var)}
        type_hints = tyh._conjoin_type_hints(vrs, self)
        r = type_hints | ~u
        return r == self.true