예제 #1
0
    def test_load(self):
        with open(self.fn, 'w') as f:
            f.write("""{
    "8:8:10" : [
        ["gamer1", 8000],
        ["gamer2", 12000]
    ],

    "8" : [ ["name", 123] ],
    "8:8" : [ ["name", 123] ],
    "8:8:8:8:8" : [ ["name", 123] ],

    "x:8:10" : [ ["name", 123] ],
    "0:8:10" : [ ["name", 123] ],
    "-1:8:10" : [ ["name", 123] ],

    "8:x:10" : [ ["name", 123] ],
    "8:0:10" : [ ["name", 123] ],
    "8:-1:10" : [ ["name", 123] ],

    "8:8:x" : [ ["name", 123] ],
    "8:8:0" : [ ["name", 123] ],
    "8:8:-1" : [ ["name", 123] ],

    "8:8:11" : "wrong",
    "8:8:12" : 12345,
    "10:10:10" : [
        "wrong",
        12345,
        ["user", 100],
        ["wrong1", -100],
        ["wrong2", 0],
        ["wrong3", 200, 200],
        ["gamer", 4500.1],
        [500, 200],
        ["wrong", "value"]
    ],

    "8:8:16" : []
}""")

        scoreboard = Scoreboard(self.fn)
        self.assertSetEqual(
            {((8, 8), 10), ((8, 8), 16), ((10, 10), 10), ((8, 8, 8, 8), 8)},
            set(scoreboard.get_params()))
        self.assertSetEqual(set(), set(scoreboard.get_scores((8, 8), 16)))
        self.assertSetEqual({("gamer1", 8000), ("gamer2", 12000)},
                            set(scoreboard.get_scores((8, 8), 10)))
        self.assertSetEqual({("user", 100), ("gamer", 4500)},
                            set(scoreboard.get_scores((10, 10), 10)))
예제 #2
0
    def test_load(self):
        with open(self.fn, 'w') as f:
            f.write("""{
    "8:8:10" : [
        ["gamer1", 8000],
        ["gamer2", 12000]
    ],

    "8" : [ ["name", 123] ],
    "8:8" : [ ["name", 123] ],
    "8:8:8:8:8" : [ ["name", 123] ],

    "x:8:10" : [ ["name", 123] ],
    "0:8:10" : [ ["name", 123] ],
    "-1:8:10" : [ ["name", 123] ],

    "8:x:10" : [ ["name", 123] ],
    "8:0:10" : [ ["name", 123] ],
    "8:-1:10" : [ ["name", 123] ],

    "8:8:x" : [ ["name", 123] ],
    "8:8:0" : [ ["name", 123] ],
    "8:8:-1" : [ ["name", 123] ],

    "8:8:11" : "wrong",
    "8:8:12" : 12345,
    "10:10:10" : [
        "wrong",
        12345,
        ["user", 100],
        ["wrong1", -100],
        ["wrong2", 0],
        ["wrong3", 200, 200],
        ["gamer", 4500.1],
        [500, 200],
        ["wrong", "value"]
    ],

    "8:8:16" : []
}""")

        scoreboard = Scoreboard(self.fn)
        self.assertSetEqual({((8, 8), 10), ((8, 8), 16), ((10, 10), 10),
                             ((8, 8, 8, 8), 8)},
                            set(scoreboard.get_params()))
        self.assertSetEqual(set(), set(scoreboard.get_scores((8, 8), 16)))
        self.assertSetEqual({("gamer1", 8000), ("gamer2", 12000)},
                            set(scoreboard.get_scores((8, 8), 10)))
        self.assertSetEqual({("user", 100), ("gamer", 4500)},
                            set(scoreboard.get_scores((10, 10), 10)))
예제 #3
0
    def test_add_score(self):
        scoreboard = Scoreboard(self.fn)

        params = ((8, 8), 10)
        self.assertListEqual([], scoreboard.get_scores(*params))

        scoreboard.add_score(Field.generate(*params), "u1", 1500)
        scoreboard.add_score(Field.generate(*params), "u2", 400)
        scoreboard.add_score(Field.generate(*params), "u3", 5000)
        self.assertListEqual([("u2", 400.0), ("u1", 1500.0), ("u3", 5000.0)],
                             scoreboard.get_scores(*params))

        _ = Scoreboard(self.fn)
        self.assertEqual(3, len(scoreboard.get_scores(*params)))
예제 #4
0
    def test_add_score(self):
        scoreboard = Scoreboard(self.fn)

        params = ((8, 8), 10)
        self.assertListEqual([], scoreboard.get_scores(*params))

        scoreboard.add_score(Field.generate(*params), "u1", 1500)
        scoreboard.add_score(Field.generate(*params), "u2", 400)
        scoreboard.add_score(Field.generate(*params), "u3", 5000)
        self.assertListEqual([("u2", 400.0), ("u1", 1500.0), ("u3", 5000.0)],
                             scoreboard.get_scores(*params))

        _ = Scoreboard(self.fn)
        self.assertEqual(3, len(scoreboard.get_scores(*params)))