コード例 #1
0
    def test_comparison(self):
        score_1 = Score(4, 2)
        score_2 = Score(8, 4)
        member = Member(123)

        assert score_1 <= score_2
        assert score_2 >= score_1
        assert score_1 < score_2
        assert score_2 > score_1
        assert score_1 != score_2

        score_1 = Score(3, 1)
        score_2 = Score(4, 1)

        assert score_1 >= score_2
        assert score_2 <= score_1
        assert score_1 > score_2
        assert score_2 < score_1
        assert score_1 != score_2

        assert score_1 >= score_1
        assert score_1 <= score_1
        assert not score_1 > score_1
        assert not score_1 < score_1
        assert score_1 == score_1

        assert not (score_1 < member)
        assert not (score_1 <= member)
        assert not (score_1 > member)
        assert not (score_1 >= member)
コード例 #2
0
    def test_init(self):
        score = Score()
        assert score.answers == 0
        assert score.correct == 0

        score = Score(answers=2, correct=1, member=Member(123))
        assert score.answers == 2
        assert score.correct == 1
        assert score.member == Member(123)
コード例 #3
0
    def test_equality(self):
        a = Score(7, 5)
        b = Score(7, 5)
        c = Score(6, 5)
        d = Score(7, 6)
        e = Score()
        f = Member(123)

        assert a == b
        assert a != c
        assert a != d
        assert a != e
        assert a != f
コード例 #4
0
    def test_scores(self, today):
        todays_score = score_orchestra(today).todays_score
        weeks_score = score_orchestra(today - dt.timedelta(
            days=today.weekday())).weeks_score
        months_score = score_orchestra(today - dt.timedelta(days=today.day -
                                                            1)).months_score
        years_score = score_orchestra(dt.date(today.year, 1, 1)).years_score
        overall_score = score_orchestra(today).overall_score

        for score in [todays_score, weeks_score, months_score, years_score]:
            assert score[0].member == Member(1)
            assert score[0] == Score(8, 4)
            assert score[1].member == Member(2)
            assert score[1] == Score(4, 2)
            assert score[2].member == Member(3)
            assert score[2] == Score(3, 1)
            assert score[3].member == Member(4)
            assert score[3] == Score(4, 1)

        assert overall_score[0].member == Member(2)
        assert overall_score[0] == Score(14, 12)
        assert overall_score[1].member == Member(3)
        assert overall_score[1] == Score(13, 11)
        assert overall_score[2].member == Member(4)
        assert overall_score[2] == Score(14, 11)
        assert overall_score[3].member == Member(1)
        assert overall_score[3] == Score(18, 14)
コード例 #5
0
ファイル: userscore.py プロジェクト: paulypeter/AkaNamen-Bot
    def _cumulative_score(self, start: dt.date = None) -> Score:
        c_score = Score()

        with self._high_score_lock:
            for date, score in self._high_score.items():
                if start is None or date >= start:
                    c_score.answers += score.answers
                    c_score.correct += score.correct
        return c_score
コード例 #6
0
    def test_properties(self):
        score = Score()
        with pytest.raises(ValueError, match='smaller than zero'):
            score.answers = -1
        with pytest.raises(ValueError, match='smaller than zero'):
            score.correct = -1

        score.answers = 10
        score.correct = 5
        assert score.answers == 10
        assert score.correct == 5

        with pytest.raises(ValueError, match='Fewer'):
            score.answers = 4
        with pytest.raises(ValueError, match='Fewer'):
            score.correct = 11
コード例 #7
0
ファイル: userscore.py プロジェクト: paulypeter/AkaNamen-Bot
 def _default_factory() -> Score:
     # needed for backwards compatibility only. Can be dropped in future versions
     return Score()  # pragma: no cover
コード例 #8
0
 def test_bool(self):
     score = Score(0, 0)
     assert not score
     score.answers += 1
     assert score
コード例 #9
0
 def test_ratio(self):
     score = Score()
     assert score.ratio == 0
     score = Score(7, 5)
     assert score.ratio == 71.43
コード例 #10
0
ファイル: questioner.py プロジェクト: paulypeter/AkaNamen-Bot
    def __init__(
        self,
        user_id: int,
        orchestra: Orchestra,
        hint_attributes: List[str],
        question_attributes: List[str],
        number_of_questions: int,
        bot: Bot,
        multiple_choice: bool = True,
    ) -> None:

        self.bot = bot
        self.multiple_choice = multiple_choice
        self.orchestra = orchestra
        self.member = self.orchestra.members[user_id]
        self.score = Score(member=self.member)
        self.current_question: Optional[Question] = None
        self._available_members_recurse = True

        if number_of_questions <= 0:
            raise ValueError('Number of questions must be greater than zero. Joke Cookie.')
        self.number_of_questions = number_of_questions
        self.number_of_questions_asked = 0

        # Filter stupid input
        if (
            len(hint_attributes) == 1
            and len(question_attributes) == 1
            and hint_attributes == question_attributes
        ):
            raise ValueError(
                'Allowing the same single attribute for both hints and questions '
                'wont be very interesting.'
            )

        # Filter generally unsupported input
        for index, h_a in enumerate(hint_attributes):
            if h_a in Question.SUPPORTED_ATTRIBUTES:
                hint_attributes[index] = h_a
            else:
                raise ValueError(f'Unsupported hint attribute {h_a}.')
        for index, q_a in enumerate(question_attributes):
            if q_a in Question.SUPPORTED_ATTRIBUTES:
                question_attributes[index] = q_a
            else:
                raise ValueError(f'Unsupported question attribute {q_a}.')

        # Filter input unsupported for the orchestras state
        questionable = self.orchestra.questionable(
            self.multiple_choice, exclude_members=[self.member]
        )

        available_hints = [q[0] for q in questionable]
        available_questions = [q[1] for q in questionable]
        for h_a in hint_attributes:
            if h_a not in available_hints:
                raise ValueError(f'Attribute {h_a} not available as hint for this orchestra.')
        for q_a in question_attributes:
            if q_a not in available_questions:
                raise ValueError(f'Attribute {q_a} not available as question for this orchestra.')

        if not hint_attributes:
            hint_attributes = list(q[0].description for q in questionable)
        if not question_attributes:
            question_attributes = list(q[1].description for q in questionable)

        if not any(
            (ha, qa) in questionable for ha in hint_attributes for qa in question_attributes
        ):
            raise ValueError('No valid hint-question combination available.')

        self.hint_attributes = hint_attributes
        self.question_attributes = question_attributes
コード例 #11
0
 def _default_factory(self: 'UserScore') -> Score:
     return Score(member=self.member)