示例#1
0
    def setUpTestData(cls):
        user = User.objects.create_user(username='******',
                                        email='*****@*****.**',
                                        password='******')

        g = Grammar(prods="{'A': ['xA', 'Bz'],'B': ['yB']}",
                    nonTerminals="AB",
                    terminals="xyz",
                    startSymbol="A")
        g.save()

        q = Question(gid=g, qnum=0, category="FI", symbol="A", answer="xy")
        q.save()

        user_history = UserHistory(user=user, grammar=g)
        user_history.save()

        cls.current_site = Site.objects.get_current()

        cls.SocialApp1 = cls.current_site.socialapp_set.create(
            provider="facebook",
            name="facebook",
            client_id="1234567890",
            secret="0987654321",
        )

        cls.SocialApp2 = cls.current_site.socialapp_set.create(
            provider="google",
            name="google",
            client_id="1234567890",
            secret="0987654321",
        )
示例#2
0
 def test_log_start_grammar_unit_test(self):
     g = Grammar(prods="{'A': ['xA', 'Bz'],'B': ['yB']}",
                 nonTerminals="AB",
                 terminals="xyz",
                 startSymbol="A")
     g.save()
     g = Grammar.objects.get(pk=g.pk)
     before_nStart = g.nStart
     stats.log_start_grammar(g.pk)
     g = Grammar.objects.get(pk=g.pk)
     self.assertEqual(before_nStart + 1, g.nStart)
示例#3
0
 def test_user_history(self):
     g = Grammar(prods="{'A': ['xA', 'Bz'],'B': ['yB']}",
                 nonTerminals="AB",
                 terminals="xyz",
                 startSymbol="A")
     g.save()
     u = User.objects.get(username="******")
     t_user_history = UserHistory(user=u, grammar=g)
     self.assertEqual(t_user_history.user, u)
     self.assertEqual(t_user_history.grammar, g)
     self.assertEqual(t_user_history.complete, False)
     self.assertEqual(t_user_history.score, -1)
示例#4
0
 def test_grammar(self):
     g = Grammar(prods="{'A': ['xA', 'Bz'],'B': ['yB']}",
                 nonTerminals="AB",
                 terminals="xyz",
                 startSymbol="A")
     g.save()
     t_grammar = Grammar.objects.get(pk=g.pk)
     self.assertEqual(t_grammar.prods, "{'A': ['xA', 'Bz'],'B': ['yB']}")
     self.assertEqual(t_grammar.nonTerminals, "AB")
     self.assertEqual(t_grammar.terminals, "xyz")
     self.assertEqual(t_grammar.startSymbol, "A")
     self.assertEqual(t_grammar.nStart, 0)
     self.assertEqual(t_grammar.nComplete, 0)
     self.assertEqual(t_grammar.nSkip, 0)
示例#5
0
    def saveToDB(self, grammar, result):
        #This function takes the grammar and the result returned by gc.solve. It
        #populates the Grammar and Question table in DB with the correct fields

        firstSets, followSets, parsingTable, status, reachable, terminals = result
        newG = Grammar(prods=str(grammar),
                       nonTerminals=''.join(self.nonTerminals),
                       terminals=''.join(terminals),
                       startSymbol='A')
        newG.save()

        #First and Follow Set
        qnum = 0
        for v in self.nonTerminals:
            qFirst = Question(gid=newG,
                              qnum=qnum,
                              category='FI',
                              symbol=v,
                              answer=''.join(firstSets[v]))
            qFirst.save()
            qnum += 1

        for v in self.nonTerminals:
            qFollow = Question(gid=newG,
                               qnum=qnum,
                               category='FO',
                               symbol=v,
                               answer=''.join(followSets[v]))
            qFollow.save()
            qnum += 1

        #Parse Table Question
        qPT = Question(gid=newG,
                       qnum=qnum,
                       category='PT',
                       answer=str(parsingTable))
        qPT.save()
        qnum += 1

        #LL1 Question
        if status == 0:
            ans = 'True'
            self.statusSummary["LL1"] += 1
        else:
            ans = 'False'
            self.statusSummary["non-LL1"] += 1
        qLL = Question(gid=newG, qnum=qnum, category='LL', answer=ans)
        qLL.save()
示例#6
0
 def test_log_skip_grammar_unit_test(self):
     g = Grammar(prods="{'A': ['xA', 'Bz'],'B': ['yB']}",
                 nonTerminals="AB",
                 terminals="xyz",
                 startSymbol="A")
     g.save()
     request = HttpRequest()
     engine = import_module(settings.SESSION_ENGINE)
     session_key = None
     request.session = engine.SessionStore(session_key)
     request.session['gid'] = g.pk
     request.session['hide_explainer'] = False
     request.user = User.objects.get(username="******")
     before_nSkip = g.nSkip
     stats.log_skip_grammar(request)
     g = Grammar.objects.get(pk=g.pk)
     self.assertEqual(before_nSkip, g.nSkip)
示例#7
0
 def test_question(self):
     g = Grammar(prods="{'A': ['xA', 'Bz'],'B': ['yB']}",
                 nonTerminals="AB",
                 terminals="xyz",
                 startSymbol="A")
     g.save()
     q = Question(gid=g, qnum=0, category="FI", symbol="A", answer="xy")
     q.save()
     t_question = Question.objects.get(pk=q.pk)
     self.assertEqual(t_question.gid, g)
     self.assertEqual(t_question.qnum, 0)
     self.assertEqual(t_question.category, "FI")
     self.assertEqual(t_question.symbol, "A")
     self.assertEqual(t_question.answer, "xy")
     self.assertEqual(t_question.nCorrect, 0)
     self.assertEqual(t_question.nWrong, 0)
     self.assertEqual(t_question.nGiveUp, 0)
示例#8
0
 def test_get_random_grammar_unit_test(self):
     sample_g = Grammar(prods="{'A': ['xA', 'Bz'],'B': ['yB']}",
                        nonTerminals="AB",
                        terminals="xyz",
                        startSymbol="A")
     user = User.objects.get(username="******")
     g = practice.get_random_grammar(user)
     self.assertEqual(g.prods, sample_g.prods)
     self.assertEqual(g.nonTerminals, sample_g.nonTerminals)
     self.assertEqual(g.terminals, sample_g.terminals)
     self.assertEqual(g.startSymbol, sample_g.startSymbol)