示例#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)
示例#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())
示例#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")
示例#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)
示例#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])
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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))
示例#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))
示例#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)
示例#15
0
文件: manager.py 项目: yyaan/pynusmv
    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())
示例#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)
示例#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")
示例#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]
示例#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)
示例#20
0
文件: sat.py 项目: 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)
示例#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())
示例#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")
示例#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())
示例#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]")
示例#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))