예제 #1
0
 def test_length(self):
     nlst= NodeList.empty()
     self.assertEqual(0, len(nlst))
      
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     nlst= NodeList.from_list([a, b, c])
     self.assertEqual(3, len(nlst))
예제 #2
0
 def test_length(self):
     nlst= NodeList.empty()
     self.assertEqual(0, len(nlst))
      
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     nlst= NodeList.from_list([a, b, c])
     self.assertEqual(3, len(nlst))
예제 #3
0
 def test_extend_unique(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     beg = NodeList.from_list([a])
     end = NodeList.from_list([a, b,c])
     
     
     beg.extend(end, unique=True)
     self.assertEquals(beg[0], a)
     self.assertEquals(beg[1], b)
     self.assertEquals(beg[2], c)
예제 #4
0
 def test_extend_unique(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     beg = NodeList.from_list([a])
     end = NodeList.from_list([a, b,c])
     
     
     beg.extend(end, unique=True)
     self.assertEquals(beg[0], a)
     self.assertEquals(beg[1], b)
     self.assertEquals(beg[2], c)
예제 #5
0
 def test_insert_after(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     
     # empty
     nlst= NodeList.empty()
     with self.assertRaises(ValueError):
         nlst.insert_after(iter(nlst), a)
     
     # filled
     nlst.append(a)
     it = iter(nlst)
     nlst.insert_after(it, b)
     self.assertEqual(2, len(nlst))
     self.assertEqual(a, nlst[0])
     self.assertEqual(b, nlst[1])
     
     # at end
     it = iter(nlst)
     it.__next__()
     nlst.insert_after(it, c)
     self.assertEqual(3, len(nlst))
     self.assertEqual(a, nlst[0])
     self.assertEqual(b, nlst[1])
     self.assertEqual(c, nlst[2])
예제 #6
0
 def test_print_nodes(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     nlst= NodeList.from_list([a, b, c])
     
     nlst.print_nodes(StdioFile.stdout())
예제 #7
0
    def test_insert_before(self):
        a   = self.node_from_expr("a = 1")
        b   = self.node_from_expr("b = 2")
        c   = self.node_from_expr("c = 3")
        
        # empty
        nlst= NodeList.empty()
        nlst.insert_before(iter(nlst), a)
        self.assertEqual(1, len(nlst))
        self.assertEqual(a, nlst[0])
        
        # filled
        it = iter(nlst)
        it.__next__()
        nlst.insert_before(it, b)
        self.assertEqual(2, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(b, nlst[1])

        # in the middle
        it = iter(nlst)
        it.__next__()
        nlst.insert_before(it, c)
        self.assertEqual(3, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(c, nlst[1])
        self.assertEqual(b, nlst[2])
예제 #8
0
 def test_insert_after(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     
     # empty
     nlst= NodeList.empty()
     with self.assertRaises(ValueError):
         nlst.insert_after(iter(nlst), a)
     
     # filled
     nlst.append(a)
     it = iter(nlst)
     nlst.insert_after(it, b)
     self.assertEqual(2, len(nlst))
     self.assertEqual(a, nlst[0])
     self.assertEqual(b, nlst[1])
     
     # at end
     it = iter(nlst)
     it.__next__()
     nlst.insert_after(it, c)
     self.assertEqual(3, len(nlst))
     self.assertEqual(a, nlst[0])
     self.assertEqual(b, nlst[1])
     self.assertEqual(c, nlst[2])
예제 #9
0
    def test_insert_before(self):
        a   = self.node_from_expr("a = 1")
        b   = self.node_from_expr("b = 2")
        c   = self.node_from_expr("c = 3")
        
        # empty
        nlst= NodeList.empty()
        nlst.insert_before(iter(nlst), a)
        self.assertEqual(1, len(nlst))
        self.assertEqual(a, nlst[0])
        
        # filled
        it = iter(nlst)
        it.__next__()
        nlst.insert_before(it, b)
        self.assertEqual(2, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(b, nlst[1])

        # in the middle
        it = iter(nlst)
        it.__next__()
        nlst.insert_before(it, c)
        self.assertEqual(3, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(c, nlst[1])
        self.assertEqual(b, nlst[2])
예제 #10
0
 def test_print_nodes(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     nlst= NodeList.from_list([a, b, c])
     
     nlst.print_nodes(StdioFile.stdout())
예제 #11
0
 def test_count(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     nlst= NodeList.from_list([a, a, b])
     self.assertEqual(nlst.count(a), 2)
     self.assertEqual(nlst.count(b), 1)
     self.assertEqual(nlst.count(c), 0)
예제 #12
0
 def test_count(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     nlst= NodeList.from_list([a, a, b])
     self.assertEqual(nlst.count(a), 2)
     self.assertEqual(nlst.count(b), 1)
     self.assertEqual(nlst.count(c), 0)
예제 #13
0
파일: trace.py 프로젝트: yyaan/pynusmv
 def symbols(self):
     """
     Returns a NodeList (:class:`pynusmv.collections.NodeList`)
     exposing the symbols of the trace language.
     
     :returns: a NodeList exposing the symbols of the trace language
     """
     return NodeList(_trace.Trace_get_symbols(self._ptr))
예제 #14
0
파일: trace.py 프로젝트: yyaan/pynusmv
 def input_vars(self):
     """
     Returns a NodeList  (:class:`pynusmv.collections.NodeList`)
     exposing the input variables that exist in the trace language
     
     :return: a NodeList containing the input variables of the trace language
     """
     return NodeList(_trace.Trace_get_i_vars(self._ptr))
예제 #15
0
 def test_delitem(self):
     a   = self.node_from_expr("a = 1")
     lst = NodeList.from_list([a])
     self.assertEqual(1, len(lst))
     self.assertTrue(a in lst)
       
     del lst[0]
     self.assertTrue(a not in lst)
     self.assertEqual(0, len(lst))
예제 #16
0
파일: trace.py 프로젝트: yyaan/pynusmv
 def state_frozen_vars(self):
     """
     Returns a NodeList  (:class:`pynusmv.collections.NodeList`)
     exposing the state and frozen variables that exist in the trace language
     
     :return: a NodeList containing the state and frozen variables of the 
         trace language
     """
     return NodeList(_trace.Trace_get_sf_vars(self._ptr))
예제 #17
0
 def test_reverse(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     nlst= NodeList.from_list([a, b, c])
     nlst.reverse()
     self.assertEqual(3, len(nlst))
     self.assertEqual(c, nlst[0])
     self.assertEqual(b, nlst[1])
     self.assertEqual(a, nlst[2])
예제 #18
0
 def test_delitem(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     lst = NodeList.from_list([a, b])
     self.assertEqual(2, len(lst))
     self.assertTrue(a in lst)
       
     del lst[1]
     self.assertTrue(b not in lst)
     self.assertEqual(1, len(lst))
예제 #19
0
 def test_reverse(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     nlst= NodeList.from_list([a, b, c])
     nlst.reverse()
     self.assertEqual(3, len(nlst))
     self.assertEqual(c, nlst[0])
     self.assertEqual(b, nlst[1])
     self.assertEqual(a, nlst[2])
예제 #20
0
 def test_getitem(self):
     a   = self.node_from_expr("a = 1")
     lst = NodeList.empty()
     try: 
         lst[0]
     except KeyError:
         self.assertTrue(True)
           
     lst.append(a)
     self.assertEqual(a, lst[0])
예제 #21
0
 def test_getitem(self):
     a   = self.node_from_expr("a = 1")
     lst = NodeList.empty()
     try: 
         lst[0]
     except KeyError:
         self.assertTrue(True)
           
     lst.append(a)
     self.assertEqual(a, lst[0])
예제 #22
0
 def test_iter_string(self):
     nlst = NodeList.empty()
     a = self.node_from_expr("a = 1")
     b = self.node_from_expr("b = 2")
     c = self.node_from_expr("c = 3")
     nlst.append(a)
     nlst.append(b)
     nlst.append(c) 
     
     it = iter(nlst)
     self.assertEqual(str(it), "NodeListIter[a = 1, b = 2, c = 3]")
예제 #23
0
 def test_copy(self):
     a = self.node_from_expr("a = 12")
     
     nlst= NodeList.empty()
     cpy = nlst.copy()
     
     self.assertTrue(a not in cpy)
     
     nlst.append(a)
     cpy = nlst.copy()
     
     self.assertTrue(a in cpy)
예제 #24
0
 def test_copy(self):
     a = self.node_from_expr("a = 12")
     
     nlst= NodeList.empty()
     cpy = nlst.copy()
     
     self.assertTrue(a not in cpy)
     
     nlst.append(a)
     cpy = nlst.copy()
     
     self.assertTrue(a in cpy)
예제 #25
0
    def test_is_complete(self):
        with BmcSupport():
            sexp_fsm = master_bool_sexp_fsm()
            be_fsm = master_be_fsm()

            trace = Trace.create("Dummy example",
                                 TraceType.COUNTER_EXAMPLE,
                                 sexp_fsm.symbol_table,
                                 sexp_fsm.symbols_list,
                                 is_volatile=True)

            # vacuously true
            self.assertTrue(trace.is_complete(NodeList.from_list([])))

            v = be_fsm.encoding.by_name['v'].name
            self.assertFalse(trace.is_complete(NodeList.from_list([v])))

            step = trace.steps[1]
            yes = Node.from_ptr(parse_simple_expression("TRUE"))
            step += (v, yes)

            self.assertTrue(trace.is_complete(NodeList.from_list([v])))
예제 #26
0
 def test_from_list(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     lst = [a, b, c]
     nlst= NodeList.from_list(lst)
     
     self.assertTrue(a in nlst)
     self.assertTrue(b in nlst)
     self.assertTrue(c in nlst)
     
     self.assertEqual(nlst[0], a)
     self.assertEqual(nlst[1], b)
     self.assertEqual(nlst[2], c)
예제 #27
0
 def test_from_list(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     lst = [a, b, c]
     nlst= NodeList.from_list(lst)
     
     self.assertTrue(a in nlst)
     self.assertTrue(b in nlst)
     self.assertTrue(c in nlst)
     
     self.assertEqual(nlst[0], a)
     self.assertEqual(nlst[1], b)
     self.assertEqual(nlst[2], c)
예제 #28
0
 def test_iter(self):    
     nlst= NodeList.empty()
     a = self.node_from_expr("a = 1")
     b = self.node_from_expr("b = 2")
     c = self.node_from_expr("c = 3")
     nlst.append(a)
     nlst.append(b)
     nlst.append(c) 
     
     lst = [a,b,c]
     out = []
     for v in nlst:
         out.append(v)
         
     self.assertListEqual(out, lst)
예제 #29
0
 def test_iter(self):
     nlst= NodeList.empty()
     a = self.node_from_expr("a = 1")
     b = self.node_from_expr("b = 2")
     c = self.node_from_expr("c = 3")
     nlst.append(a)
     nlst.append(b)
     nlst.append(c) 
     
     lst = [a,b,c]
     out = []
     for v in nlst:
         out.append(v)
         
     self.assertListEqual(out, lst)
예제 #30
0
    def test_is_complete(self):
        with BmcSupport():
            sexp_fsm = master_bool_sexp_fsm()
            be_fsm = master_be_fsm()

            trace = Trace.create(
                "Dummy example",
                TraceType.COUNTER_EXAMPLE,
                sexp_fsm.symbol_table,
                sexp_fsm.symbols_list,
                is_volatile=True,
            )

            # vacuously true
            self.assertTrue(trace.is_complete(NodeList.from_list([])))

            v = be_fsm.encoding.by_name["v"].name
            self.assertFalse(trace.is_complete(NodeList.from_list([v])))

            step = trace.steps[1]
            yes = Node.from_ptr(parse_simple_expression("TRUE"))
            step += (v, yes)

            self.assertTrue(trace.is_complete(NodeList.from_list([v])))
예제 #31
0
 def test_append(self):
     nlst= NodeList.empty()
      
     # append on empty works
     a = self.node_from_expr("a = 12")
     self.assertTrue(a not in nlst)
     nlst.append(a)
     self.assertTrue(a in nlst)
     self.assertEqual(a, nlst[0])
      
     # append on non empty works
     b = self.node_from_expr("b = 23")
     self.assertTrue(b not in nlst)
     nlst.append(b)
     self.assertTrue(b in nlst)
     self.assertEqual(b, nlst[1])
예제 #32
0
 def test_append(self):
     nlst= NodeList.empty()
      
     # append on empty works
     a = self.node_from_expr("a = 12")
     self.assertTrue(a not in nlst)
     nlst.append(a)
     self.assertTrue(a in nlst)
     self.assertEqual(a, nlst[0])
      
     # append on non empty works
     b = self.node_from_expr("b = 23")
     self.assertTrue(b not in nlst)
     nlst.append(b)
     self.assertTrue(b in nlst)
     self.assertEqual(b, nlst[1])
예제 #33
0
파일: encoder.py 프로젝트: yyaan/pynusmv
 def encode_to_bits(self, name_node):
     """
     Returns the list of bits variable names used to encode the SMV variable
     denoted by `name_node` in the boolean model.
     
     :param name_node: the node symbol representing the expression to break
         down to bits.
     :return: the list of bits names (in the form of nodes) which are used
         to encode `name_node`.
     """
     try:
         # raises a KeyError when 'name' is not found
         self.by_name[str(name_node)]
         # if found, its ok to just use 'symbol'
         return [name_node]
     except KeyError:
         # the encoder doesn't know 'name' we need to find the bits
         boolenc = self._bool_enc
         node_lst= NodeList(_bool.BoolEnc_get_var_bits(boolenc, name_node._ptr))
         return list(node_lst)
예제 #34
0
    def test_insert_at(self):
        a   = self.node_from_expr("a = 1")
        b   = self.node_from_expr("b = 2")
        c   = self.node_from_expr("c = 3")
        
        # empty
        nlst= NodeList.empty()
        nlst.insert_at(0, a)
        self.assertEqual(1, len(nlst))
        self.assertEqual(a, nlst[0])
        
        # filled
        nlst.insert_at(1, b)
        self.assertEqual(2, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(b, nlst[1])

        # in the middle
        nlst.insert_at(1, c)
        self.assertEqual(3, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(c, nlst[1])
        self.assertEqual(b, nlst[2])
예제 #35
0
    def test_insert_at(self):
        a   = self.node_from_expr("a = 1")
        b   = self.node_from_expr("b = 2")
        c   = self.node_from_expr("c = 3")
        
        # empty
        nlst= NodeList.empty()
        nlst.insert_at(0, a)
        self.assertEqual(1, len(nlst))
        self.assertEqual(a, nlst[0])
        
        # filled
        nlst.insert_at(1, b)
        self.assertEqual(2, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(b, nlst[1])

        # in the middle
        nlst.insert_at(1, c)
        self.assertEqual(3, len(nlst))
        self.assertEqual(a, nlst[0])
        self.assertEqual(c, nlst[1])
        self.assertEqual(b, nlst[2])
예제 #36
0
 def test_contains(self):
     a   = self.node_from_expr("a = 1")
     nlst= NodeList.empty()
     self.assertTrue(a not in nlst)
     nlst.append(a)
     self.assertTrue(a in nlst)
예제 #37
0
 def test_empty(self):
     lst = NodeList.empty()
     self.assertEqual(len(lst), 0, "lst should be empty")
예제 #38
0
 def test_to_list(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     nlst= list(NodeList.from_list([a, b, c]))
     self.assertListEqual(nlst, [a, b, c])
예제 #39
0
 def test_to_list(self):
     a   = self.node_from_expr("a = 1")
     b   = self.node_from_expr("b = 2")
     c   = self.node_from_expr("c = 3")
     nlst= list(NodeList.from_list([a, b, c]))
     self.assertListEqual(nlst, [a, b, c])
예제 #40
0
파일: fsm.py 프로젝트: yyaan/pynusmv
 def variables_list(self):
     """
     :return: the set of variables in the FSM
     """
     return NodeList(_sexp.SexpFsm_get_vars_list(self._as_SexpFsm_ptr()))
예제 #41
0
 def test_empty(self):
     lst = NodeList.empty()
     self.assertEqual(len(lst), 0, "lst should be empty")
예제 #42
0
파일: fsm.py 프로젝트: yyaan/pynusmv
 def symbols_list(self):
     """
     :return: the set of symbols in the FSM
     """
     return NodeList(_sexp.SexpFsm_get_symbols_list(self._as_SexpFsm_ptr()))
예제 #43
0
 def test_contains(self):
     a   = self.node_from_expr("a = 1")
     nlst= NodeList.empty()
     self.assertTrue(a not in nlst)
     nlst.append(a)
     self.assertTrue(a in nlst)