コード例 #1
0
ファイル: tests.py プロジェクト: Loptr250/ifind
    def test_game_scoring(self):
        self.logger.info("Testing Game Scoring with a Dummy SearchEngine")
        #print "Testing Game Scoring with a Dummy SearchEngine"
        se = EngineFactory("Dummy")
        u = User.objects.get(username='******')
        c = Category.objects.get(name='Numbers')

        gm = GameMechanic(se)
        gm.create_game(u,c)
        self.logger.info("Checking if the category Numbers has four pages.")
        #print "Checking if the category Numbers has four pages."
        self.assertEquals(len(gm.pages), 4)

        gm.handle_query('one')
        gm.take_points()
        gm.set_next_page()
        self.logger.info("Checking whether the query, one, scores 1000 points-\
                         which it should given the data and dummy search engine")
        #print "Checking whether the query, one, scores 1000 points -
        #which it should given the data and dummy search engine"
        self.assertEquals(gm.get_current_score(),1000)
コード例 #2
0
def main():

    logger = create_ifind_logger('test_game_mech.log')
    logger.info("Program started")
    logger.info('Testing game mechanics')

    print "This script is to test the GameMechanics and interaction with the Models"

    ds = EngineFactory("Dummy")

    gm = GameMechanic(ds)
    print gm
    u = User.objects.filter(username='******')
    if u:
        u = u[0]
    else:
        print "Adding testy user"
        u = User(username='******', password='******')
        u.save()

    c = Category.objects.filter(name='Numbers')

    if c:
        c = c[0]
    else:
        print "Adding a Numbers Category"
        c = Category(name='Numbers',
                     desc='Looking for sites that around about numbers')
        c.save()

    pages = Page.objects.filter(category=c)

    if not pages:
        print "Adding pages"

        for pn in ['one', 'two', 'three', 'four']:
            p = Page(category=c,
                     title=pn,
                     url='www.' + pn + '.com',
                     snippet=pn,
                     desc=('desc: ' + pn))
            p.save()

        pages = Page.objects.filter(category=c)

    print u
    print c
    print pages

    gm.create_game(u, c)

    print gm

    print "Game is set up to play"
    raw_input('Press enter to continue')

    while not gm.is_game_over():
        clear_screen()
        print gm
        last_query = gm.get_last_query()
        if last_query:
            print "\nLast Query: %s and Query Score: %d" % (
                last_query, gm.get_last_query_score())
        state = handle_game_input()
        if state == 1:
            gm.take_points()
            gm.set_next_page()
            state = 0
        if state == 2:
            query = handle_query_input()
            gm.handle_query(query)

    print '\nGame Over!!\n'
    print gm
    logger.info("Done!")
コード例 #3
0
def main():

    logger = create_ifind_logger("test_game_mech.log")
    logger.info("Program started")
    logger.info("Testing game mechanics")

    print "This script is to test the GameMechanics and interaction with the Models"

    ds = EngineFactory("Dummy")

    gm = GameMechanic(ds)
    print gm
    u = User.objects.filter(username="******")
    if u:
        u = u[0]
    else:
        print "Adding testy user"
        u = User(username="******", password="******")
        u.save()

    c = Category.objects.filter(name="Numbers")

    if c:
        c = c[0]
    else:
        print "Adding a Numbers Category"
        c = Category(name="Numbers", desc="Looking for sites that around about numbers")
        c.save()

    pages = Page.objects.filter(category=c)

    if not pages:
        print "Adding pages"

        for pn in ["one", "two", "three", "four"]:
            p = Page(category=c, title=pn, url="www." + pn + ".com", snippet=pn, desc=("desc: " + pn))
            p.save()

        pages = Page.objects.filter(category=c)

    print u
    print c
    print pages

    gm.create_game(u, c)

    print gm

    print "Game is set up to play"
    raw_input("Press enter to continue")

    while not gm.is_game_over():
        clear_screen()
        print gm
        last_query = gm.get_last_query()
        if last_query:
            print "\nLast Query: %s and Query Score: %d" % (last_query, gm.get_last_query_score())
        state = handle_game_input()
        if state == 1:
            gm.take_points()
            gm.set_next_page()
            state = 0
        if state == 2:
            query = handle_query_input()
            gm.handle_query(query)

    print "\nGame Over!!\n"
    print gm
    logger.info("Done!")
コード例 #4
0
ファイル: tests.py プロジェクト: leifos/pagefetch
    def test_game_scoring(self):
        self.logger.info("Testing Game Scoring with a Dummy SearchEngine")
        #print "Testing Game Scoring with a Dummy SearchEngine"
        se = EngineFactory("Dummy")
        u = User.objects.get(username='******')
        c = Category.objects.get(name='Numbers')

        gm = GameMechanic(se)
        gm.create_game(u, c)
        self.logger.info("Checking if the category Numbers has four pages.")
        #print "Checking if the category Numbers has four pages."
        self.assertEquals(len(gm.pages), 4)

        gm.handle_query('one')
        gm.take_points()
        gm.set_next_page()
        self.logger.info("Checking whether the query, one, scores 1000 points-\
                         which it should given the data and dummy search engine"
                         )
        #print "Checking whether the query, one, scores 1000 points -
        #which it should given the data and dummy search engine"
        self.assertEquals(gm.get_current_score(), 1000)