[Checkins] SVN: Sandbox/adamg/ocql/trunk/src/ocql/ more tests to improve coverage

Charith Paranaliyanage paranaliyanage at gmail.com
Sat Aug 23 01:10:11 EDT 2008


Log message for revision 90142:
  more tests to improve coverage

Changed:
  U   Sandbox/adamg/ocql/trunk/src/ocql/parser/parser.txt
  U   Sandbox/adamg/ocql/trunk/src/ocql/parser/queryparser.py
  U   Sandbox/adamg/ocql/trunk/src/ocql/queryobject/interfaces.py
  U   Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py
  U   Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.txt
  U   Sandbox/adamg/ocql/trunk/src/ocql/rewriter/rewriter.txt

-=-
Modified: Sandbox/adamg/ocql/trunk/src/ocql/parser/parser.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/parser/parser.txt	2008-08-23 04:32:21 UTC (rev 90141)
+++ Sandbox/adamg/ocql/trunk/src/ocql/parser/parser.txt	2008-08-23 05:10:10 UTC (rev 90142)
@@ -103,3 +103,34 @@
 
     >>> QueryParser("set [ i in IPerson; isinstance(i, Tutor) | i ]")(None)
     Head(Query(<type 'set'>, In(Identifier(i), Identifier(IPerson)); Isinstance(Identifier(i), Tutor), Identifier(i)))
+
+    >>> QueryParser("set [ s in Staff; set [st in IStudents; some st.takes == atleast 2 s.teaches | st.name] == 'St1' | i.name ]")(None)
+    Head(Query(<type 'set'>, In(Identifier(s), Identifier(Staff)); Eq(Query(<type 'set'>, In(Identifier(st), Identifier(IStudents)); 
+    Eq((Some, Property(Identifier(st), Identifier(takes))), (Atleast(2, Property(Identifier(s), Identifier(teaches))))), 
+    Property(Identifier(st), Identifier(name))), Constant('St1')), Property(Identifier(i), Identifier(name))))
+
+    >>> QueryParser("set [ s in Staff; set [st in IStudents; some st.takes == just 2 s.teaches | st.name] == 'St1' | i.name ]")(None)
+    Head(Query(<type 'set'>, In(Identifier(s), Identifier(Staff)); Eq(Query(<type 'set'>, In(Identifier(st), Identifier(IStudents)); 
+    Eq((Some, Property(Identifier(st), Identifier(takes))), (Just(2, Property(Identifier(s), Identifier(teaches))))), 
+    Property(Identifier(st), Identifier(name))), Constant('St1')), Property(Identifier(i), Identifier(name))))
+
+    >>> QueryParser("set [ s in Staff; set [st in IStudents; some st.takes == atmost 2 s.teaches | st.name] == 'St1' | i.name ]")(None)
+    Head(Query(<type 'set'>, In(Identifier(s), Identifier(Staff)); Eq(Query(<type 'set'>, In(Identifier(st), Identifier(IStudents)); 
+    Eq((Some, Property(Identifier(st), Identifier(takes))), (Atmost(2, Property(Identifier(s), Identifier(teaches))))), 
+    Property(Identifier(st), Identifier(name))), Constant('St1')), Property(Identifier(i), Identifier(name))))
+
+    >>> QueryParser("len ( set [ i in IStaff | i ] ) + len ( set [ j in IVisitingStaff | j ] )")(None)
+    Head(Add(Count(Query(<type 'set'>, In(Identifier(i), Identifier(IStaff)), Identifier(i))), 
+    Count(Query(<type 'set'>, In(Identifier(j), Identifier(IVisitingStaff)), Identifier(j)))))
+
+    >>> QueryParser("len ( set [ i in IStaff | i ] ) - len ( set [ j in IVisitingStaff | j ] )")(None)
+    Head(Sub(Count(Query(<type 'set'>, In(Identifier(i), Identifier(IStaff)), Identifier(i))), 
+    Count(Query(<type 'set'>, In(Identifier(j), Identifier(IVisitingStaff)), Identifier(j)))))
+
+    >>> QueryParser("len ( set [ i in IStaff | i ] ) * len ( set [ j in IVisitingStaff | j ] )")(None)
+    Head(Mul(Count(Query(<type 'set'>, In(Identifier(i), Identifier(IStaff)), Identifier(i))), 
+    Count(Query(<type 'set'>, In(Identifier(j), Identifier(IVisitingStaff)), Identifier(j)))))
+
+    >>> QueryParser("len ( set [ i in IStaff | i ] ) / len ( set [ j in IVisitingStaff | j ] )")(None)
+    Head(Div(Count(Query(<type 'set'>, In(Identifier(i), Identifier(IStaff)), Identifier(i))), 
+    Count(Query(<type 'set'>, In(Identifier(j), Identifier(IVisitingStaff)), Identifier(j)))))

Modified: Sandbox/adamg/ocql/trunk/src/ocql/parser/queryparser.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/parser/queryparser.py	2008-08-23 04:32:21 UTC (rev 90141)
+++ Sandbox/adamg/ocql/trunk/src/ocql/parser/queryparser.py	2008-08-23 05:10:10 UTC (rev 90142)
@@ -43,7 +43,8 @@
           'DOT', 'IN', 'LTE', 'SOME', 'AND', 'CBRACKET_L', 'CONSTANT',
           'EQUAL', 'GTE', 'ISINSTANCE', 'SEMI_COLON', 'BRACKET_L', 'ASSIGN',
           'NOT_ASSIGN', 'FOR', 'CBRACKET_R', 'JUST', 'IDENTIFIER', 'DIFFER',
-          'LEN', 'BAG', 'SBRACKET_L', 'NOT', 'ATLEAST', 'SBRACKET_R')
+          'LEN', 'BAG', 'SBRACKET_L', 'NOT', 'ATLEAST', 'SBRACKET_R', 
+          'PLUS', 'MINUS', 'MUL', 'DIV')
 
 precedence = (
     ('left', 'UNION'),
@@ -55,8 +56,8 @@
     ('left', 'OR'),
     ('right', 'NOT'),
 #   ('left', 'COND_OP'),
-#   ('left', 'PLUS', 'MINUS'),
-#   ('left', 'MUL', 'DIV'),
+   ('left', 'PLUS', 'MINUS'),
+   ('left', 'MUL', 'DIV'),
 #   ('token', 'IDENTIFIER'),
 #   ('token', 'BRACEL'),
 #   ('token', 'BRACER'),
@@ -170,7 +171,6 @@
         r','
         return t
 
-#this may be != sign
     def t_NOT_EQUAL(self, t):
         r'!='
         return t
@@ -239,17 +239,17 @@
         r'~='
         return t
 
-#    def t_DIV(self, t):
-#        r'/'
-#        return t
+    def t_PLUS(self, t):
+        r'\+'
+        return t
 
-#    def t_PLUS(self, t):
-#        r'\+'
-#        return t
+    def t_MINUS(self, t):
+        r'-'
+        return t
 
-#    def t_MINUS(self, t):
-#        r'-'
-#        return t
+    def t_DIV(self, t):
+        r'/'
+        return t
 
     def t_SBRACKET_L(self, t):
         r'\['
@@ -288,6 +288,30 @@
         t[0] = Differ(self.metadata, self.symbols, t[1], t[3])
         if DEBUG: print 'reducing "expression DIFFER expression" to "expression"', t[0]
 
+    def p_expr_plus(self, t):
+        r'''expression : expression PLUS expression
+        '''
+        t[0] = Add(self.metadata, self.symbols, t[1], t[3])
+        if DEBUG: print 'reducing "expression UNION expression" to "expression"', t[0]
+
+    def p_expr_minus(self, t):
+        r'''expression : expression MINUS expression
+        '''
+        t[0] = Sub(self.metadata, self.symbols, t[1], t[3])
+        if DEBUG: print 'reducing "expression UNION expression" to "expression"', t[0]
+
+    def p_expr_mul(self, t):
+        r'''expression : expression MUL expression
+        '''
+        t[0] = Mul(self.metadata, self.symbols, t[1], t[3])
+        if DEBUG: print 'reducing "expression UNION expression" to "expression"', t[0]
+
+    def p_expr_div(self, t):
+        r'''expression : expression DIV expression
+        '''
+        t[0] = Div(self.metadata, self.symbols, t[1], t[3])
+        if DEBUG: print 'reducing "expression UNION expression" to "expression"', t[0]
+
 #    def p_expr_3(self, t):
 #        r'''expression : collection SBRACKET_L expression SBRACKET_R
 #        '''
@@ -499,12 +523,6 @@
         t[0] = Some(self.metadata, self.symbols, t[2])
         if DEBUG: print 'reducing "quantification expression" to "quantified"', t[0]
 
-    def p_quantified_just(self, t):
-        r'''quantified : JUST expression
-        '''
-        t[0] = Just(self.metadata, self.symbols, t[2])
-        if DEBUG: print 'reducing "quantification expression" to "quantified"', t[0]
-
     def p_quantified_every(self, t):
         r'''quantified : EVERY expression
         '''
@@ -512,17 +530,23 @@
         if DEBUG: print 'reducing "quantification expression" to "quantified"', t[0]
 
     def p_quantified_atleast(self, t):
-        r'''quantified : ATLEAST expression
+        r'''quantified : ATLEAST CONSTANT expression
         '''
-        t[0] = Atleast(self.metadata, self.symbols, t[2])
+        t[0] = Atleast(self.metadata, self.symbols, t[2], t[3])
         if DEBUG: print 'reducing "quantification expression" to "quantified"', t[0]
 
     def p_quantified_almost(self, t):
-        r'''quantified : ATMOST expression
+        r'''quantified : ATMOST CONSTANT expression
         '''
-        t[0] = Atmost(self.metadata, self.symbols, t[2])
+        t[0] = Atmost(self.metadata, self.symbols, t[2], t[3])
         if DEBUG: print 'reducing "quantification expression" to "quantified"', t[0]
 
+    def p_quantified_just(self, t):
+        r'''quantified : JUST CONSTANT expression
+        '''
+        t[0] = Just(self.metadata, self.symbols, t[2], t[3])
+        if DEBUG: print 'reducing "quantification expression" to "quantified"', t[0]
+
     def p_definition_as(self, t):
         r'''definition : IDENTIFIER AS expression
         '''

Modified: Sandbox/adamg/ocql/trunk/src/ocql/queryobject/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/queryobject/interfaces.py	2008-08-23 04:32:21 UTC (rev 90141)
+++ Sandbox/adamg/ocql/trunk/src/ocql/queryobject/interfaces.py	2008-08-23 05:10:10 UTC (rev 90142)
@@ -1,7 +1,7 @@
 # -*- coding: UTF-8 -*-
 
 from zope.interface import Attribute, Interface
-from zope.schema import TextLine
+from zope.schema import TextLine, Int
 
 from ocql.interfaces import IObjectQuery
 
@@ -180,6 +180,13 @@
     """
     expr = Attribute('expression')
 
+class INumericalQuantor(IQuantor):
+    """Objects providing this interface represent the
+    NeumericalQuantor Query object
+    """
+    quantity = Int(title=u"numerical quantity")
+    expr = Attribute('expression')
+
 class IQuanted(IObjectQueryChild):
     """Objects providing this interface represent the
     Quanted Query object

Modified: Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py	2008-08-23 04:32:21 UTC (rev 90141)
+++ Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py	2008-08-23 05:10:10 UTC (rev 90142)
@@ -373,6 +373,22 @@
             str(self.expr)
             )
 
+class NumericalQuantor(Quantor):
+    implements(INumericalQuantor)
+    def __init__(self, metadata, symbols, quantity, expr):
+        self.metadata = metadata
+        self.symbols = symbols
+        Child.__init__(self)
+        self.setProp('expr', expr)
+        self.setProp('quantity', quantity)
+
+    def __repr__(self):
+        return "(%s(%s, %s))" % (
+            self.__class__.__name__,
+            str(self.quantity),
+            str(self.expr)
+            )
+
 class Quanted(Child):
     implements(IQuanted)
     quantor = None
@@ -398,16 +414,14 @@
 class Some(Quantor):
     implements(ISome)
 
-class Atmost(Quantor):
+class Atmost(NumericalQuantor):
     implements(IAtmost)
 
-class Atleast(Quantor):
+class Atleast(NumericalQuantor):
     implements(IAtleast)
-    #expr = None
 
-class Just(Quantor):
+class Just(NumericalQuantor):
     implements(IJust)
-    #expr = None
 
 # Logical operators
 class Condition(Expression):

Modified: Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.txt	2008-08-23 04:32:21 UTC (rev 90141)
+++ Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.txt	2008-08-23 05:10:10 UTC (rev 90142)
@@ -167,6 +167,11 @@
     >>> verifyObject(IQuantor, Quantor(metadata, symbols, child))
     True
 
+    >>> verifyClass(INumericalQuantor, NumericalQuantor)
+    True
+    >>> verifyObject(INumericalQuantor, NumericalQuantor(metadata, symbols, 2, child))
+    True
+
     >>> verifyClass(IQuanted, Quanted)
     True
     >>> verifyObject(IQuanted, Quanted(metadata, symbols, child, child))
@@ -184,17 +189,17 @@
 
     >>> verifyClass(IAtmost, Atmost)
     True
-    >>> verifyObject(IAtmost, Atmost(metadata, symbols, child))
+    >>> verifyObject(IAtmost, Atmost(metadata, symbols, 2, child))
     True
 
     >>> verifyClass(IAtleast, Atleast)
     True
-    >>> verifyObject(IAtleast, Atleast(metadata, symbols, child))
+    >>> verifyObject(IAtleast, Atleast(metadata, symbols, 2, child))
     True
 
     >>> verifyClass(IJust, Just)
     True
-    >>> verifyObject(IJust, Just(metadata, symbols, child))
+    >>> verifyObject(IJust, Just(metadata, symbols, 2, child))
     True
 
     >>> verifyClass(ICondition, Condition)

Modified: Sandbox/adamg/ocql/trunk/src/ocql/rewriter/rewriter.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/rewriter/rewriter.txt	2008-08-23 04:32:21 UTC (rev 90141)
+++ Sandbox/adamg/ocql/trunk/src/ocql/rewriter/rewriter.txt	2008-08-23 05:10:10 UTC (rev 90142)
@@ -123,6 +123,40 @@
     >>> print str(alg)
     Head(Iter(<type 'set'>, Lambda s: If(s.major.address.street == `'Hillhead Street'`, Single(<type 'set'>, s), Empty(<type 'set'>)), Make(<type 'set'>, <type 'set'>, IStudents)))
 
+    >>> qo = QueryParser("set [ c in ICourse; c.credits == 2 and c.code == 'C1' | c ]")(TestMetadata())
+    >>> opt = QueryOptimizer(qo)()
+    >>> alg = Rewriter(opt)()
+    >>> print str(alg)
+    Head(Iter(<type 'set'>, Lambda c: If(c.credits == `2` and c.code == `'C1'`, Single(<type 'set'>, c), Empty(<type 'set'>)), Make(<type 'set'>, <type 'set'>, ICourse)))
+
+    >>> qo = QueryParser("len ( set [ i in IStaff | i ] ) + len ( set [ j in IVisitingStaff | j ] )")(TestMetadata())
+    >>> opt = QueryOptimizer(qo)()
+    >>> alg = Rewriter(opt)()
+    >>> print str(alg)
+    Head(Reduce(<type 'set'>, `0`, Lambda i: `1`, +, Iter(<type 'set'>, Lambda i: Single(<type 'set'>, i), Make(<type 'set'>, <type 'set'>, IStaff))) + 
+    Reduce(<type 'set'>, `0`, Lambda i: `1`, +, Iter(<type 'set'>, Lambda j: Single(<type 'set'>, j), Make(<type 'set'>, <type 'set'>, IVisitingStaff))))
+
+    >>> qo = QueryParser("len ( set [ i in IStaff | i ] ) - len ( set [ j in IVisitingStaff | j ] )")(TestMetadata())
+    >>> opt = QueryOptimizer(qo)()
+    >>> alg = Rewriter(opt)()
+    >>> print str(alg)
+    Head(Reduce(<type 'set'>, `0`, Lambda i: `1`, +, Iter(<type 'set'>, Lambda i: Single(<type 'set'>, i), Make(<type 'set'>, <type 'set'>, IStaff))) -
+    Reduce(<type 'set'>, `0`, Lambda i: `1`, +, Iter(<type 'set'>, Lambda j: Single(<type 'set'>, j), Make(<type 'set'>, <type 'set'>, IVisitingStaff))))
+
+    >>> qo = QueryParser("len ( set [ i in IStaff | i ] ) * len ( set [ j in IVisitingStaff | j ] )")(TestMetadata())
+    >>> opt = QueryOptimizer(qo)()
+    >>> alg = Rewriter(opt)()
+    >>> print str(alg)
+    Head(Reduce(<type 'set'>, `0`, Lambda i: `1`, +, Iter(<type 'set'>, Lambda i: Single(<type 'set'>, i), Make(<type 'set'>, <type 'set'>, IStaff))) *
+    Reduce(<type 'set'>, `0`, Lambda i: `1`, +, Iter(<type 'set'>, Lambda j: Single(<type 'set'>, j), Make(<type 'set'>, <type 'set'>, IVisitingStaff))))
+
+    >>> qo = QueryParser("len ( set [ i in IStaff | i ] ) / len ( set [ j in IVisitingStaff | j ] )")(TestMetadata())
+    >>> opt = QueryOptimizer(qo)()
+    >>> alg = Rewriter(opt)()
+    >>> print str(alg)
+    Head(Reduce(<type 'set'>, `0`, Lambda i: `1`, +, Iter(<type 'set'>, Lambda i: Single(<type 'set'>, i), Make(<type 'set'>, <type 'set'>, IStaff))) /
+    Reduce(<type 'set'>, `0`, Lambda i: `1`, +, Iter(<type 'set'>, Lambda j: Single(<type 'set'>, j), Make(<type 'set'>, <type 'set'>, IVisitingStaff))))
+
 #    >>> qo = QueryParser("set [ s in IStudents; a as s.major.address.street; a=='Hillhead Street' | s ]")(TestMetadata())
 #    >>> opt = QueryOptimizer(qo)()
 #    >>> alg = Rewriter(opt)()



More information about the Checkins mailing list