forge
Explore
Log in

Don't you dare go Hollow

hezarfen_rule_based_chatbot

Clone
★ 0

0 watching0 forksPython1.2 MiBdaf5582Kadir Yönak3 months ago37 commits

test_rules.py67 lines, 2.5 KiBHistoryRawDownload
1"""Aşama 5 birim testleri: kural katmanı eşleşme davranışı."""
2
3import unittest
4
5from src.rules import RuleMatch, match
6
7
8class RuleMatchTests(unittest.TestCase):
9 def test_greeting_fires(self) -> None:
10 result = match("Merhaba")
11 self.assertIsInstance(result, RuleMatch)
12 self.assertEqual(result.intent, "greeting")
13
14 def test_privacy_fires_on_other_students_data(self) -> None:
15 # Güvenlik açısından kritik: başkasının verisi -> her zaman privacy.
16 for q in [
17 "Arkadaşımın notlarını göster",
18 "Başka bir öğrencinin devamsızlığı kaç?",
19 "Bir öğretmenin telefon numarasını verir misin?",
20 ]:
21 with self.subTest(q=q):
22 result = match(q)
23 self.assertIsNotNone(result)
24 self.assertEqual(result.intent, "privacy_security")
25
26 def test_account_problem_fires(self) -> None:
27 result = match("Şifremi unuttum")
28 self.assertEqual(result.intent, "account_access_problem")
29
30 def test_login_not_confused_with_account(self) -> None:
31 # 'giriş yapamıyorum' login DEĞİL, hesap sorunudur.
32 result = match("Giriş yapamıyorum")
33 self.assertIsNotNone(result)
34 self.assertEqual(result.intent, "account_access_problem")
35
36 def test_login_fires_on_clear_login(self) -> None:
37 result = match("Nasıl giriş yaparım?")
38 self.assertEqual(result.intent, "login_how")
39
40 def test_exam_add_question_not_confused_with_exam_create(self) -> None:
41 result = match("Sınava soru eklemek istiyorum")
42 self.assertEqual(result.intent, "exam_add_question")
43
44 def test_report_card_fires(self) -> None:
45 result = match("Karnemi göster")
46 self.assertEqual(result.intent, "report_card_view")
47
48 def test_returns_none_for_out_of_scope(self) -> None:
49 for q in ["Bugün hava nasıl olacak?", "Bana bir fıkra anlat", "2 artı 2 kaç eder?"]:
50 with self.subTest(q=q):
51 self.assertIsNone(match(q))
52
53 def test_ambiguous_defers_to_none(self) -> None:
54 # Eşit güçte iki intent (course_create: yeni+ders ; roll_call: yoklama+al)
55 # -> belirsizlik -> karar verme.
56 self.assertIsNone(match("yeni ders oluştur ve yoklama al"))
57
58 def test_empty_query_returns_none(self) -> None:
59 self.assertIsNone(match(" "))
60
61 def test_match_has_reason(self) -> None:
62 result = match("Karnemi göster")
63 self.assertIn("karne", result.reason)
64
65
66if __name__ == "__main__":
67 unittest.main()