Ejemplo n.º 1
0
    def test_output(self):
        matches = komode.prepare_matches([1,2,3,4,5,6])
        printed = komode.print_knockout(matches)
        # remove the whitespace to the right of the printed lines
        printed = re.sub(r'\s+$', '', printed, flags=re.MULTILINE)
        outcome = """\
         1 ┐
           ├─ ??? ┐
         2 ┘      │
                  ├─ ??? ┐
         3 ┐      │      │
           ├─ ??? ┘      │  ┏━━━━━┓
         4 ┘             ├──┨ ??? ┃
                         │  ┗━━━━━┛
         5 ┐             │
           ├─ ??? ───────┘
         6 ┘"""
        self.assertEqual(dedent(printed), dedent(outcome))

        matches = komode.prepare_matches([1,2,3,4,5,6], bonusmatch=True)
        printed = komode.print_knockout(matches)
        print(printed)
        # remove the whitespace to the right of the printed lines
        printed = re.sub(r'\s+$', '', printed, flags=re.MULTILINE)
        outcome = """\
         1 ┐
           ├─ ??? ┐
         4 ┘      │
                  ├─ ??? ┐
         2 ┐      │      │
           ├─ ??? ┘      ├─ ??? ┐
         3 ┘             │      │  ┏━━━━━┓
                         │      ├──┨ ??? ┃
         5 ──────────────┘      │  ┗━━━━━┛
                                │
         6 ─────────────────────┘"""
        self.assertEqual(dedent(printed), dedent(outcome))
Ejemplo n.º 2
0
    def test_output(self):
        matches = komode.prepare_matches([1, 2, 3, 4, 5, 6])
        printed = komode.print_knockout(matches)
        # remove the whitespace to the right of the printed lines
        printed = re.sub(r'\s+$', '', printed, flags=re.MULTILINE)
        outcome = """\
         1 ┐
           ├─ ??? ┐
         2 ┘      │
                  ├─ ??? ┐
         3 ┐      │      │
           ├─ ??? ┘      │  ┏━━━━━┓
         4 ┘             ├──┨ ??? ┃
                         │  ┗━━━━━┛
         5 ┐             │
           ├─ ??? ───────┘
         6 ┘"""
        self.assertEqual(dedent(printed), dedent(outcome))

        matches = komode.prepare_matches([1, 2, 3, 4, 5, 6], bonusmatch=True)
        printed = komode.print_knockout(matches)
        print(printed)
        # remove the whitespace to the right of the printed lines
        printed = re.sub(r'\s+$', '', printed, flags=re.MULTILINE)
        outcome = """\
         1 ┐
           ├─ ??? ┐
         4 ┘      │
                  ├─ ??? ┐
         2 ┐      │      │
           ├─ ??? ┘      ├─ ??? ┐
         3 ┘             │      │  ┏━━━━━┓
                         │      ├──┨ ??? ┃
         5 ──────────────┘      │  ┗━━━━━┛
                                │
         6 ─────────────────────┘"""
        self.assertEqual(dedent(printed), dedent(outcome))
Ejemplo n.º 3
0
    def test_prepared_matches(self):
        with self.assertRaises(ValueError):
            none = komode.prepare_matches([])
        with self.assertRaises(ValueError):
            none = komode.prepare_matches([], bonusmatch=True)

        single = komode.prepare_matches([1])
        self.assertEqual(single, komode.Team(name=1))
        single = komode.prepare_matches([1], bonusmatch=True)
        self.assertEqual(single, komode.Team(name=1))

        pair = komode.prepare_matches([1,2])
        self.assertEqual(pair, Match(t1=Team(name=1), t2=Team(name=2)))
        pair = komode.prepare_matches([1,2], bonusmatch=True)
        self.assertEqual(pair, Match(t1=Team(name=1), t2=Team(name=2)))

        triple = komode.prepare_matches([1,2,3])
        self.assertEqual(triple, Match(t1=Match(t1=Team(name=1), t2=Team(name=2)), t2=Bye(team=Team(name=3))))
        triple = komode.prepare_matches([1,2,3], bonusmatch=True)
        self.assertEqual(triple, Match(t1=Match(t1=Team(name=1), t2=Team(name=2)), t2=Bye(team=Team(name=3))))

        matches = komode.prepare_matches([1,2,3,4])
        outcome = Match(t1=Match(t1=Team(name=1), t2=Team(name=2)), t2=Match(t1=Team(name=3), t2=Team(name=4)))
        self.assertEqual(matches, outcome)
        matches = komode.prepare_matches([1,2,3,4], bonusmatch=True)
        outcome = Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=2)), t2=Bye(team=Team(name=3))), t2=Bye(team=Bye(team=Team(name=4))))
        self.assertEqual(matches, outcome)

        matches = komode.prepare_matches([1,2,3,4,5])
        outcome = Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=2)), t2=Match(t1=Team(name=3), t2=Team(name=4))), t2=Bye(team=Bye(team=Team(name=5))))
        self.assertEqual(matches, outcome)
        matches = komode.prepare_matches([1,2,3,4,5], bonusmatch=True)
        outcome = Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=4)), t2=Match(t1=Team(name=2), t2=Team(name=3))), t2=Bye(team=Bye(team=Team(name=5))))
        self.assertEqual(matches, outcome)

        matches = komode.prepare_matches([1,2,3,4,5,6])
        outcome = Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=2)), t2=Match(t1=Team(name=3), t2=Team(name=4))), t2=Bye(team=Match(t1=Team(name=5), t2=Team(name=6))))
        self.assertEqual(matches, outcome)
        matches = komode.prepare_matches([1,2,3,4,5,6], bonusmatch=True)
        outcome = Match(t1=Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=4)), t2=Match(t1=Team(name=2), t2=Team(name=3))), t2=Bye(team=Bye(team=Team(name=5)))), t2=Bye(team=Bye(team=Bye(team=Team(name=6)))))
        self.assertEqual(matches, outcome)
Ejemplo n.º 4
0
    def test_prepared_matches(self):
        with pytest.raises(ValueError):
            none = komode.prepare_matches([])
        with pytest.raises(ValueError):
            none = komode.prepare_matches([], bonusmatch=True)

        single = komode.prepare_matches([1])
        assert single == komode.Team(name=1)
        single = komode.prepare_matches([1], bonusmatch=True)
        assert single == komode.Team(name=1)

        pair = komode.prepare_matches([1,2])
        assert pair == Match(t1=Team(name=1), t2=Team(name=2))
        pair = komode.prepare_matches([1,2], bonusmatch=True)
        assert pair == Match(t1=Team(name=1), t2=Team(name=2))

        triple = komode.prepare_matches([1,2,3])
        assert triple == Match(t1=Match(t1=Team(name=1), t2=Team(name=2)), t2=Bye(team=Team(name=3)))
        triple = komode.prepare_matches([1,2,3], bonusmatch=True)
        assert triple == Match(t1=Match(t1=Team(name=1), t2=Team(name=2)), t2=Bye(team=Team(name=3)))

        matches = komode.prepare_matches([1,2,3,4])
        outcome = Match(t1=Match(t1=Team(name=1), t2=Team(name=2)), t2=Match(t1=Team(name=3), t2=Team(name=4)))
        assert matches == outcome
        matches = komode.prepare_matches([1,2,3,4], bonusmatch=True)
        outcome = Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=2)), t2=Bye(team=Team(name=3))), t2=Bye(team=Bye(team=Team(name=4))))
        assert matches == outcome

        matches = komode.prepare_matches([1,2,3,4,5])
        outcome = Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=2)), t2=Match(t1=Team(name=3), t2=Team(name=4))), t2=Bye(team=Bye(team=Team(name=5))))
        assert matches == outcome
        matches = komode.prepare_matches([1,2,3,4,5], bonusmatch=True)
        outcome = Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=4)), t2=Match(t1=Team(name=2), t2=Team(name=3))), t2=Bye(team=Bye(team=Team(name=5))))
        assert matches == outcome

        matches = komode.prepare_matches([1,2,3,4,5,6])
        outcome = Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=2)), t2=Match(t1=Team(name=3), t2=Team(name=4))), t2=Bye(team=Match(t1=Team(name=5), t2=Team(name=6))))
        assert matches == outcome
        matches = komode.prepare_matches([1,2,3,4,5,6], bonusmatch=True)
        outcome = Match(t1=Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=4)), t2=Match(t1=Team(name=2), t2=Team(name=3))), t2=Bye(team=Bye(team=Team(name=5)))), t2=Bye(team=Bye(team=Bye(team=Team(name=6)))))
        assert matches == outcome
Ejemplo n.º 5
0
    def test_prepared_matches(self):
        with self.assertRaises(ValueError):
            none = komode.prepare_matches([])
        with self.assertRaises(ValueError):
            none = komode.prepare_matches([], bonusmatch=True)

        single = komode.prepare_matches([1])
        self.assertEqual(single, komode.Team(name=1))
        single = komode.prepare_matches([1], bonusmatch=True)
        self.assertEqual(single, komode.Team(name=1))

        pair = komode.prepare_matches([1, 2])
        self.assertEqual(pair, Match(t1=Team(name=1), t2=Team(name=2)))
        pair = komode.prepare_matches([1, 2], bonusmatch=True)
        self.assertEqual(pair, Match(t1=Team(name=1), t2=Team(name=2)))

        triple = komode.prepare_matches([1, 2, 3])
        self.assertEqual(
            triple,
            Match(t1=Match(t1=Team(name=1), t2=Team(name=2)),
                  t2=Bye(team=Team(name=3))))
        triple = komode.prepare_matches([1, 2, 3], bonusmatch=True)
        self.assertEqual(
            triple,
            Match(t1=Match(t1=Team(name=1), t2=Team(name=2)),
                  t2=Bye(team=Team(name=3))))

        matches = komode.prepare_matches([1, 2, 3, 4])
        outcome = Match(t1=Match(t1=Team(name=1), t2=Team(name=2)),
                        t2=Match(t1=Team(name=3), t2=Team(name=4)))
        self.assertEqual(matches, outcome)
        matches = komode.prepare_matches([1, 2, 3, 4], bonusmatch=True)
        outcome = Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=2)),
                                 t2=Bye(team=Team(name=3))),
                        t2=Bye(team=Bye(team=Team(name=4))))
        self.assertEqual(matches, outcome)

        matches = komode.prepare_matches([1, 2, 3, 4, 5])
        outcome = Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=2)),
                                 t2=Match(t1=Team(name=3), t2=Team(name=4))),
                        t2=Bye(team=Bye(team=Team(name=5))))
        self.assertEqual(matches, outcome)
        matches = komode.prepare_matches([1, 2, 3, 4, 5], bonusmatch=True)
        outcome = Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=4)),
                                 t2=Match(t1=Team(name=2), t2=Team(name=3))),
                        t2=Bye(team=Bye(team=Team(name=5))))
        self.assertEqual(matches, outcome)

        matches = komode.prepare_matches([1, 2, 3, 4, 5, 6])
        outcome = Match(t1=Match(t1=Match(t1=Team(name=1), t2=Team(name=2)),
                                 t2=Match(t1=Team(name=3), t2=Team(name=4))),
                        t2=Bye(team=Match(t1=Team(name=5), t2=Team(name=6))))
        self.assertEqual(matches, outcome)
        matches = komode.prepare_matches([1, 2, 3, 4, 5, 6], bonusmatch=True)
        outcome = Match(t1=Match(t1=Match(t1=Match(t1=Team(name=1),
                                                   t2=Team(name=4)),
                                          t2=Match(t1=Team(name=2),
                                                   t2=Team(name=3))),
                                 t2=Bye(team=Bye(team=Team(name=5)))),
                        t2=Bye(team=Bye(team=Bye(team=Team(name=6)))))
        self.assertEqual(matches, outcome)