Exemple #1
0
def thing_setup():
    from leaf.thing.job import JobThing
    from leaf.thing.base import LeaderboardThing, EntryThingTrait, BaseEntryThing
    from leaf.thing.bucket import BucketEntryThing
    from leaf.thing.block import BlockEntryThing
    from leaf.thing.chunk import ChunkEntryThing
    _things['job'] = JobThing()
    _things['leaderboard'] = LeaderboardThing()
    _things['entry'] = EntryThingTrait()

    _entrythings['base'] = BaseEntryThing()
    _entrythings['bucket'] = BucketEntryThing()
    _entrythings['block'] = BlockEntryThing()
    _entrythings['chunk'] = ChunkEntryThing()
Exemple #2
0
 def setUp(self):
     data.up(lid=2)
     self.e = BlockEntryThing()
     self.e.sort(2)
Exemple #3
0
class ChunkEntryThingTest(unittest.TestCase):
    def setUp(self):
        data.up(lid=2)
        self.e = BlockEntryThing()
        self.e.sort(2)

    def tearDown(self):
        data.down(lid=2)

    def test_rank_for_user(self):
        e = self.e.rank_for_user(2, 11)
        self.assertEquals((e.entry_id, e.score, e.rank), (11, 29, 5))
        e = self.e.rank_for_user(2, 13)
        self.assertEquals((e.entry_id, e.score, e.rank), (13, 29, 5))
        e = self.e.rank_for_user(2, 13, True)
        self.assertEquals((e.entry_id, e.score, e.rank), (13, 29, 13))

    def test_rank_for_users(self):
        es = self.e.rank_for_users(2, [11, 13])
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank), (11, 29, 5))
        self.assertEquals((es[1].entry_id, es[1].score, es[1].rank), (13, 29, 5))

        es = self.e.rank_for_users(2, [11, 13], True)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank), (11, 29, 11))
        self.assertEquals((es[1].entry_id, es[1].score, es[1].rank), (13, 29, 13))

    def test_rank_at(self):
        e = self.e.rank_at(2, 11, dense=True)
        self.assertEqual(len(e), 1)
        self.assertEquals((e[0].entry_id, e[0].score, e[0].rank), (11, 29, 11))

        es = self.e.rank_at(2, 2)
        self.assertEqual(len(es), 3)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank), (2, 32, 2))
        self.assertEquals((es[1].entry_id, es[1].score, es[1].rank), (3, 32, 2))
        self.assertEquals((es[2].entry_id, es[2].score, es[2].rank), (4, 32, 2))

    def test_rank(self):
        es = self.e.rank(2, 3, 4)
        self.assertEqual(len(es), 3)
        e = es[0]
        self.assertEquals((e.entry_id, e.score, e.rank), (5, 31, 3))

        es = self.e.rank(2, 10)
        self.assertEqual(len(es), 10)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank), (1, 33, 1))
        self.assertEquals((es[1].score, es[1].rank), (32, 2))
        self.assertEquals((es[2].score, es[2].rank), (32, 2))

        es = self.e.rank(2, 10, 0, True)
        self.assertEqual(len(es), 10)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank), (1, 33, 1))
        self.assertEquals((es[1].entry_id, es[1].score, es[1].rank), (2, 32, 2))
        self.assertEquals((es[7].entry_id, es[7].score, es[7].rank), (8, 30, 8))

        es = self.e.rank(2, 10, 1, True)
        self.assertEqual(len(es), 10)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank), (2, 32, 2))
        self.assertEquals((es[6].entry_id, es[6].score, es[6].rank), (8, 30, 8))

    def test_around_me(self):
        es = self.e.around_me(2, 1)
        self.assertEqual(len(es), 3)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank), (1, 33, 1))
        self.assertEquals((es[1].entry_id, es[1].score, es[1].rank), (2, 32, 2))
        self.assertEquals((es[2].entry_id, es[2].score, es[2].rank), (3, 32, 2))

        es = self.e.around_me(2, 1, dense=True)
        self.assertEqual(len(es), 3)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank), (1, 33, 1))
        self.assertEquals((es[1].entry_id, es[1].score, es[1].rank), (2, 32, 2))
        self.assertEquals((es[2].entry_id, es[2].score, es[2].rank), (3, 32, 3))

        es = self.e.around_me(2, 10)
        self.assertEqual(len(es), 5)
Exemple #4
0
 def setUp(self):
     data.up(lid=2)
     self.e = BlockEntryThing()
     self.e.sort(2)
Exemple #5
0
class ChunkEntryThingTest(unittest.TestCase):
    def setUp(self):
        data.up(lid=2)
        self.e = BlockEntryThing()
        self.e.sort(2)

    def tearDown(self):
        data.down(lid=2)

    def test_rank_for_user(self):
        e = self.e.rank_for_user(2, 11)
        self.assertEquals((e.entry_id, e.score, e.rank), (11, 29, 5))
        e = self.e.rank_for_user(2, 13)
        self.assertEquals((e.entry_id, e.score, e.rank), (13, 29, 5))
        e = self.e.rank_for_user(2, 13, True)
        self.assertEquals((e.entry_id, e.score, e.rank), (13, 29, 13))

    def test_rank_for_users(self):
        es = self.e.rank_for_users(2, [11, 13])
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank),
                          (11, 29, 5))
        self.assertEquals((es[1].entry_id, es[1].score, es[1].rank),
                          (13, 29, 5))

        es = self.e.rank_for_users(2, [11, 13], True)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank),
                          (11, 29, 11))
        self.assertEquals((es[1].entry_id, es[1].score, es[1].rank),
                          (13, 29, 13))

    def test_rank_at(self):
        e = self.e.rank_at(2, 11, dense=True)
        self.assertEqual(len(e), 1)
        self.assertEquals((e[0].entry_id, e[0].score, e[0].rank), (11, 29, 11))

        es = self.e.rank_at(2, 2)
        self.assertEqual(len(es), 3)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank),
                          (2, 32, 2))
        self.assertEquals((es[1].entry_id, es[1].score, es[1].rank),
                          (3, 32, 2))
        self.assertEquals((es[2].entry_id, es[2].score, es[2].rank),
                          (4, 32, 2))

    def test_rank(self):
        es = self.e.rank(2, 3, 4)
        self.assertEqual(len(es), 3)
        e = es[0]
        self.assertEquals((e.entry_id, e.score, e.rank), (5, 31, 3))

        es = self.e.rank(2, 10)
        self.assertEqual(len(es), 10)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank),
                          (1, 33, 1))
        self.assertEquals((es[1].score, es[1].rank), (32, 2))
        self.assertEquals((es[2].score, es[2].rank), (32, 2))

        es = self.e.rank(2, 10, 0, True)
        self.assertEqual(len(es), 10)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank),
                          (1, 33, 1))
        self.assertEquals((es[1].entry_id, es[1].score, es[1].rank),
                          (2, 32, 2))
        self.assertEquals((es[7].entry_id, es[7].score, es[7].rank),
                          (8, 30, 8))

        es = self.e.rank(2, 10, 1, True)
        self.assertEqual(len(es), 10)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank),
                          (2, 32, 2))
        self.assertEquals((es[6].entry_id, es[6].score, es[6].rank),
                          (8, 30, 8))

    def test_around_me(self):
        es = self.e.around_me(2, 1)
        self.assertEqual(len(es), 3)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank),
                          (1, 33, 1))
        self.assertEquals((es[1].entry_id, es[1].score, es[1].rank),
                          (2, 32, 2))
        self.assertEquals((es[2].entry_id, es[2].score, es[2].rank),
                          (3, 32, 2))

        es = self.e.around_me(2, 1, dense=True)
        self.assertEqual(len(es), 3)
        self.assertEquals((es[0].entry_id, es[0].score, es[0].rank),
                          (1, 33, 1))
        self.assertEquals((es[1].entry_id, es[1].score, es[1].rank),
                          (2, 32, 2))
        self.assertEquals((es[2].entry_id, es[2].score, es[2].rank),
                          (3, 32, 3))

        es = self.e.around_me(2, 10)
        self.assertEqual(len(es), 5)