Exemplo n.º 1
0
        public void TestConditionalIf()
        {
            string            q1      = "\"Whats the question?\"";
            string            q2      = "\"Oh is that it?\"";
            string            code    = "form \r\n{ \r\n" + q1 + " bAnswer : Boolean\r\nif(bAnswer)\r\n { \r\n" + q2 + " bYesNo : Boolean \r\n} \r\n}";
            Form              parse   = init_parse(code);
            Identifier        bYesNo  = new InputIdentifier("bYesNo", new BoolType(), 1);
            Identifier        bAnswer = new InputIdentifier("bAnswer", new BoolType(), 1);
            Question          q2o     = new Question(new QSString(q2, 1), bYesNo, 1);
            Question          q1o     = new Question(new QSString(q1, 1), bAnswer, 1);
            List <IStatement> ilist   = new List <IStatement>();

            ilist.Add(q2o);
            CodeBlock         cb           = new CodeBlock(ilist);
            Identifier        bAnswerUndec = new Identifier("bAnswer", 1);
            IfStatement       ifstat       = new IfStatement(bAnswerUndec, cb, 1);
            List <IStatement> ilist2       = new List <IStatement>();

            ilist2.Add(q1o);
            ilist2.Add(ifstat);
            CodeBlock cb2       = new CodeBlock(ilist2);
            Form      construct = new Form(cb2, 1);

            TypeChecker.StartVisit(parse);
            TypeChecker.StartVisit(construct);
            Assert.AreEqual(construct, parse);
        }
 public void TestAssociativityDivide()
 {
     string q1 = "\"Whats the question?\"";
     string q2 = "\"Oh is that it?\"";
     string code = "form \r\n{ \r\n" + q1 + " iAnswer : Integer  " + q2 + " iDivAnswer = iAnswer + iAnswer / 2 : Integer \r\n}";
     Identifier iAnswer = new InputIdentifier("iAnswer", new IntegerType(), 1);
     Question q1o = new Question(new QSString(q1, 1), iAnswer, 1);
     Identifier iAnswer2 = new Identifier("iAnswer", 1);
     Identifier iAnswer3 = new Identifier("iAnswer", 1);
     Identifier iAnswerDiv = new Identifier("iDivAnswer", new IntegerType(), new Add(iAnswer2, new Divide(iAnswer3, new QSInteger(2, 1), 1), 1), 1);
     Question q2o = new Question(new QSString(q2, 1), iAnswerDiv, 1);
     List<IStatement> ilist = new List<IStatement>();
     ilist.Add(q1o);
     ilist.Add(q2o);
     Form f = new Form(new CodeBlock(ilist), 1);
     Form parse = init_parse(code);
     TypeChecker.StartVisit(f);
     TypeChecker.StartVisit(parse);
     Assert.AreEqual(f, parse);
 }
Exemplo n.º 3
0
        public void RecordRemoved(IDataRecord record)
        {
            if (record == null)
            {
                return;
            }

            if (record.Identifier == OutputIdentifier || record.Identifier == InputIdentifier)
            {
                Repository.Remove(this);
            }

            if (OutputIdentifier != null && InputIdentifier != null)
            {
                if (InputIdentifier.StartsWith(record.Identifier) || OutputIdentifier.StartsWith(record.Identifier))
                {
                    Repository.Remove(this);
                }
            }
        }
Exemplo n.º 4
0
        public void TestAssociativityDivide()
        {
            string            q1         = "\"Whats the question?\"";
            string            q2         = "\"Oh is that it?\"";
            string            code       = "form \r\n{ \r\n" + q1 + " iAnswer : Integer  " + q2 + " iDivAnswer = iAnswer + iAnswer / 2 : Integer \r\n}";
            Identifier        iAnswer    = new InputIdentifier("iAnswer", new IntegerType(), 1);
            Question          q1o        = new Question(new QSString(q1, 1), iAnswer, 1);
            Identifier        iAnswer2   = new Identifier("iAnswer", 1);
            Identifier        iAnswer3   = new Identifier("iAnswer", 1);
            Identifier        iAnswerDiv = new Identifier("iDivAnswer", new IntegerType(), new Add(iAnswer2, new Divide(iAnswer3, new QSInteger(2, 1), 1), 1), 1);
            Question          q2o        = new Question(new QSString(q2, 1), iAnswerDiv, 1);
            List <IStatement> ilist      = new List <IStatement>();

            ilist.Add(q1o);
            ilist.Add(q2o);
            Form f     = new Form(new CodeBlock(ilist), 1);
            Form parse = init_parse(code);

            TypeChecker.StartVisit(f);
            TypeChecker.StartVisit(parse);
            Assert.AreEqual(f, parse);
        }
        public void TestConditionalIfElse()
        {
            string q1 = "\"Whats the question?\"";
            string q2 = "\"Oh is that it?\"";
            string q3 = "\"Last Question?\"";
            string code = "form \r\n{ \r\n" + q1 + " bAnswer : Boolean\r\nif(bAnswer)\r\n { \r\n" + q2 + " bYesNo : Boolean \r\n} else { " + q3 + " bAnswer } \r\n}";
            Form parse = init_parse(code);
            Identifier bYesNo = new InputIdentifier("bYesNo", new BoolType(), 1);
            Identifier bAnswer = new InputIdentifier("bAnswer", new BoolType(), 1);

            // now we need to set the type and the declaration
            Identifier bAnswerUndec = new Identifier("bAnswer", 1);
            Identifier bAnswerUndec2 = new Identifier("bAnswer", 1);

            Question q2o = new Question(new QSString(q2, 1), bYesNo, 1);
            Question q1o = new Question(new QSString(q1, 1), bAnswer, 1);
            Question q3o = new Question(new QSString(q3, 1), bAnswerUndec2, 1);

            List<IStatement> ilist = new List<IStatement>();
            ilist.Add(q2o);
            CodeBlock cb = new CodeBlock(ilist);
            List<IStatement> ilist3 = new List<IStatement>();
            ilist3.Add(q3o);
            CodeBlock cb3 = new CodeBlock(ilist3);

            IfStatement ifstat = new IfStatement(bAnswerUndec, cb, cb3, 1);

            List<IStatement> ilist2 = new List<IStatement>();
            ilist2.Add(q1o);
            ilist2.Add(ifstat);

            CodeBlock cb2 = new CodeBlock(ilist2);

            Form construct = new Form(cb2, 1);
            TypeChecker.StartVisit(construct);
            TypeChecker.StartVisit(parse);
            Assert.AreEqual(construct, parse);
        }