Ejemplo n.º 1
0
    def test_remove(self):
        """Validates the behavior of remove"""
        a = Slist.from_list([1, 2, 3, 1, 4, 1], self.IntConversion)
        b = Slist.from_list([2, 3, 4], self.IntConversion)

        a.remove(1)
        self.assertEqual(a, b)
Ejemplo n.º 2
0
    def test_conversion_from_builtin_list(self):
        """Tests the conversion from a builtin list to an Slist"""
        lst = Slist.from_list([4, 3, 2, 1, 0], self.IntConversion)

        self.assertEqual(len(lst), 5)
        for i in range(5):
            self.assertEqual(4 - i, lst.pop())
Ejemplo n.º 3
0
    def test_pop_single(self):
        """This test verifies the behavior of pop when a single push is made"""
        lst = Slist.empty(self.IntConversion)
        lst.push(42)

        self.assertEqual(lst.pop(), 42)
        self.assertTrue(lst.is_empty(), "pop removes the top of the list")
Ejemplo n.º 4
0
    def test_len(self):
        """Validates the behavior of __len__"""
        lst = Slist.empty(self.IntConversion)
        self.assertEqual(len(lst), 0)

        lst.push(1)
        self.assertEqual(len(lst), 1)
Ejemplo n.º 5
0
    def test_conversion_to_builtin_list(self):
        """Validates the behavior of __list__"""
        lst = Slist.empty(self.IntConversion)
        for i in range(5):
            lst.push(i)

        self.assertListEqual(list(lst), [4, 3, 2, 1, 0])
Ejemplo n.º 6
0
    def test_del(self):
        """Validates the __delitem__ behavior"""
        lst = Slist.empty(self.IntConversion)
        for i in range(10):
            lst.push(i)

        del lst[5]
        self.assertFalse(4 in lst)
Ejemplo n.º 7
0
    def test_eq(self):
        """Validates the behavior of the equality test"""
        a = Slist.empty(self.IntConversion)
        b = Slist.empty(self.IntConversion)

        self.assertEqual(a, b, "Both lists are empty, they should be equal")

        a.push(42)
        self.assertFalse(a == b)

        a.pop()
        self.assertTrue(a == b)

        a.push(42)
        b.push(42)
        self.assertTrue(a == b)

        self.assertFalse(a == 1)
Ejemplo n.º 8
0
    def vars_list(self):
        """
        Returns the list of independent variables in the CNF representation.

        :return:the independent variables list in the CNF representation
        """
        return Slist(_be.Be_Cnf_GetVarsList(self._ptr),
                     IntConversion(),
                     freeit=False)
Ejemplo n.º 9
0
    def test_push_multi(self):
        """The test verifies the behavior of push when many pushes are made"""
        lst = Slist.empty(self.IntConversion)

        self.assertTrue(lst.is_empty())
        for i in range(10):
            lst.push(i)
        self.assertEqual(len(lst), 10, "list should contain 10 items")
        for i in range(10):
            self.assertEqual(lst[i], 9 - i)
Ejemplo n.º 10
0
 def test_pop_multi(self):
     """This test verifies the behavior of pop when a single push is made"""
     lst = Slist.empty(self.IntConversion)
     for i in range(10):
         lst.push(i)
     self.assertEqual(len(lst), 10)
     for i in range(10):
         self.assertEqual(lst.pop(), 9 - i)
     self.assertTrue(lst.is_empty(), "pop removes the top of the list")
     self.assertEqual(len(lst), 0)
Ejemplo n.º 11
0
    def test_contains(self):
        """Validates the __contains__ behavior"""
        lst = Slist.empty(self.IntConversion)
        for i in range(10):
            lst.push(i)

        self.assertFalse(42 in lst, "42 was never added to the list")
        self.assertTrue(42 not in lst, "42 was never added to the list")
        for i in range(10):
            self.assertTrue(i in lst)
Ejemplo n.º 12
0
    def test_reverse(self):
        """This method vefifies the behavior of the reverse (mutating) method"""
        lst = Slist.empty(self.IntConversion)

        # push prepends to the list, so the numbers are in reverse order
        for i in range(10):
            lst.push(i)
        # here the numbers should be in the right order again
        lst.reverse()
        for i in range(10):
            self.assertEqual(lst[i], i, "lst[{}] != {}".format(i, i))
Ejemplo n.º 13
0
    def test_reversed(self):
        """This method vefifies the behavior of the reversed method"""
        lst = Slist.empty(self.IntConversion)

        # push prepends to the list, so the numbers are in reverse order
        for i in range(10):
            lst.push(i)
        # here the numbers should be in the right order again
        rev = reversed(lst)
        self.assertEqual(len(rev), 10, "reversing a list removes no item")
        for i in range(10):
            self.assertEqual(rev[i], i, "rev[{}] != {}".format(i, i))
Ejemplo n.º 14
0
    def clauses_list(self):
        """
        :return: a list of lists which contains the CNF-ed formula]

        Each list in the list is a set of integers which represents a single clause.
        Any integer value depends on the variable name and the time which the variable
        is considered in, whereas the integer sign is the variable polarity in
        the CNF-ed representation.
        """
        return Slist(_be.Be_Cnf_GetClausesList(self._ptr),
                     ArrayOfClauses(),
                     freeit=False)
Ejemplo n.º 15
0
    def cnf_to_be_model(self, slist):
        """
        Converts the given CNF model (dimacs obtained from `solver.model` into 
        an equivalent model.

        :param slist: the cnf model in the form of a slist (as is the case from 
          `solver.model`).
        :return: Converts the given CNF model into BE model
        """
        # note: this is never used in NuSMV
        return Slist(_be.Be_CnfModelToBeModel(self._ptr, slist._ptr),
                     IntConversion())
Ejemplo n.º 16
0
    def test_push_single(self):
        """
        This test verifies the behavior of push when a single push is made
        and is also responsible for validating the  the behavior of the 
        is_empty() method
        """
        lst = Slist.empty(self.IntConversion)
        lst.push(42)

        self.assertFalse(lst.is_empty(), "The list should contain '42'")
        self.assertEqual(len(lst), 1, "The list should contain one item")
        self.assertEqual(lst[0], 42)
Ejemplo n.º 17
0
    def test_copy(self):
        """This test verifies the behavior of the copy method"""
        lst = Slist.empty(self.IntConversion)
        lst.push(42)

        cpy = lst.copy()
        self.assertIsNotNone(cpy, "the copy should not be none")
        self.assertFalse(cpy.is_empty(),
                         "like the original list, cpy contains 42")
        self.assertEqual(lst, cpy, "the two lists are supposed to be equal")
        self.assertFalse(
            lst._ptr == cpy._ptr,
            "the two copies are supposed to be physically different")
Ejemplo n.º 18
0
    def test_getitem(self):
        """tests the behavior of the getitem function"""
        lst = Slist.empty(self.IntConversion)

        self.assertTrue(lst.is_empty())
        for i in range(10):
            lst.push(i)

        for i in lst:
            self.assertEqual(lst[i], 9 - i, "lst[{}] != 9-{}".format(i, i))

        with self.assertRaises(KeyError):
            lst[10]
Ejemplo n.º 19
0
    def test_extend(self):
        """Validates the extend behavior"""
        a = Slist.empty(self.IntConversion)
        b = Slist.empty(self.IntConversion)

        for i in range(5):
            a.push(i)
        for i in range(5):
            b.push(9 - i)

        # initially a and b are disjoint
        self.assertEqual(len(a), 5)
        for i in range(5):
            self.assertTrue(i in a)
            self.assertFalse(9 - i in a)

        a.extend(b)
        # after extension there should be 5 more items
        self.assertEqual(len(a), 10)
        for i in range(5):
            self.assertTrue(9 - i in a)

        # and they should be appended in the right order
        self.assertEqual(a[0], 9)
        self.assertEqual(a[1], 8)
        self.assertEqual(a[2], 7)
        self.assertEqual(a[3], 6)
        self.assertEqual(a[4], 5)
        self.assertEqual(a[5], 4)
        self.assertEqual(a[6], 3)
        self.assertEqual(a[7], 2)
        self.assertEqual(a[8], 1)
        self.assertEqual(a[9], 0)

        # but it should leave b untouched
        self.assertEqual(len(b), 5)
        for i in range(5):
            self.assertFalse(i in b)
            self.assertTrue(9 - i in b)
Ejemplo n.º 20
0
Archivo: sat.py Proyecto: yyaan/pynusmv
 def model(self):
     """
     Returns a list of values in dimacs form that satisfy the set of formulas
      
     The previous solving call should have returned SATISFIABLE.
     The returned list is a list of values in dimac form (positive literal
     is included as the variable index, negative literal as the negative
     variable index, if a literal has not been set its value is not included).
     
     :return: a list of values in dimac form that satisfy the set of formulas
     """
     lst = _sat.SatSolver_get_model(self._as_SatSolver_ptr())
     return Slist(lst, IntConversion(), freeit=False)
Ejemplo n.º 21
0
    def test_clear(self):
        """Validates the behavior of clear"""
        lst = Slist.empty(self.IntConversion)

        # it doesn't harm to clear an empty list
        lst.clear()
        self.assertTrue(lst.is_empty())
        self.assertTrue(lst.is_empty())

        # when a non empty list is cleared, it is made empty again
        for i in range(5):
            lst.push(i)
        self.assertEquals(len(lst), 5)
        lst.clear()
        self.assertEquals(len(lst), 0)
        self.assertTrue(lst.is_empty())
Ejemplo n.º 22
0
 def test_top(self):
     """Validates the behavior of the top function"""
     lst = Slist.empty(self.IntConversion)
     for i in range(10):
         lst.push(i)
     self.assertEqual(lst.top(), 9, "The top should be 9")
Ejemplo n.º 23
0
    def test_empty(self):
        """This test verifies the behavior of the 'empty' factory method"""
        lst = Slist.empty(self.IntConversion)

        self.assertIsNotNone(lst)
        self.assertTrue(lst.is_empty())
Ejemplo n.º 24
0
 def test_iterator_string(self):
     """Tests Slist iterator string representation"""
     lst = Slist.from_list([4, 3, 2, 1, 0], self.IntConversion)
     it = iter(lst)
     self.assertEqual(str(it), "SlistIterator[4, 3, 2, 1, 0]")
Ejemplo n.º 25
0
    def test_to_std_set(self):
        """Conversion to standard collections should come for free"""
        lst = Slist.empty(self.IntConversion)
        lst.push(42)

        self.assertEqual({42}, set(lst))