Skip to content

Commit

Permalink
adding more test cases for UserSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewedy committed May 18, 2024
1 parent ea5438e commit dc870ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ def test_select_non_excluded_3_users(self):
selected = selector.select(users)
self.assertEqual(selected, expected_selection)

def test_select_non_excluded_3_users_with_ids(self):
selector = UserSelector()
users = [(1, "Alice"), (1, "Alice"), (2, "Bob"), (2, "Bob"), (3, "Charlie"), (3, "Charlie"), (3, "Charlie")]
selector.history = [(1, "Alice"), (2, "Bob"), (3, "Charlie")]

expected_selections = [(1, "Alice"), (2, "Bob"), (3, "Charlie"), (1, "Alice"), (2, "Bob"), (3, "Charlie")]
for expected_selection in expected_selections:
selected = selector.select(users)
self.assertEqual(selected, expected_selection)

def test_select_never_picks_last_n_from_history(self):
for _ in range(100):
selector = UserSelector()
Expand Down
4 changes: 2 additions & 2 deletions util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import random
import time
from typing import Any
from typing import Callable
from typing import List, Any

from telegram import Update
from telegram.ext import ContextTypes
Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(self):
self.history = []
self.selection_gap = 2

def select(self, users: List[str]) -> [str | None]:
def select(self, users):
if not users:
raise ValueError('users list should not be empty')

Expand Down

0 comments on commit dc870ed

Please sign in to comment.