forge
Explore
Log in

Don't you dare go Hollow

hezarfen_rule_based_chatbot

Clone
★ 0

0 watching0 forksPython1.2 MiBa039b60Ahmet Kaan Gümüş2 months ago64 commits

test_domain.py81 lines, 2.6 KiBHistoryRawDownload
1"""Aşama 11 birim testleri: alan (domain) kapısı."""
2
3import unittest
4
5from src.domain import (
6 STOPWORDS,
7 build_domain_vocab,
8 get_domain_vocab,
9 is_in_domain,
10 is_explicitly_out_of_scope,
11)
12
13
14class VocabTests(unittest.TestCase):
15 def test_vocab_nonempty(self) -> None:
16 self.assertGreater(len(build_domain_vocab()), 0)
17
18 def test_vocab_contains_domain_words(self) -> None:
19 vocab = build_domain_vocab()
20 self.assertIn("ders", vocab)
21
22 def test_vocab_excludes_stopwords(self) -> None:
23 vocab = build_domain_vocab()
24 for stop in ["nasil", "nerede", "bir"]:
25 self.assertNotIn(stop, vocab)
26
27 def test_cached(self) -> None:
28 self.assertIs(get_domain_vocab(), get_domain_vocab())
29
30
31class IsInDomainTests(unittest.TestCase):
32 def test_in_domain_queries(self) -> None:
33 for q in ["Karnemi göster", "sınav oluştur", "yoklama al", "derslerim neler"]:
34 with self.subTest(q=q):
35 self.assertTrue(is_in_domain(q))
36
37 def test_out_of_domain_queries(self) -> None:
38 for q in [
39 "Bana bir fıkra anlat",
40 "En yakın pizzacı nerede?",
41 "Bugün hava nasıl?",
42 "Kilo vermek için ödev önerir misin?",
43 "Matematik ödevimi çözer misin?",
44 ]:
45 with self.subTest(q=q):
46 self.assertFalse(is_in_domain(q))
47
48 def test_only_stopwords_is_out(self) -> None:
49 self.assertFalse(is_in_domain("nasıl nerede bir"))
50
51 def test_empty_is_out(self) -> None:
52 self.assertFalse(is_in_domain(""))
53
54 def test_explicit_oos_variants_do_not_reenter_via_product_words(self) -> None:
55 for query in (
56 "Bugün hava ne şekilde olacak",
57 "Hezarfen'de en yakın pizzacı nerede",
58 "Fizik konusunu adım adım özetle",
59 "Yarın okul var mı tatil mi",
60 "Sınıfın en çalışkanı kim",
61 "Python döngüsünü anlat",
62 ):
63 with self.subTest(query=query):
64 self.assertTrue(is_explicitly_out_of_scope(query))
65 self.assertFalse(is_in_domain(query))
66
67 def test_school_dietary_profile_is_not_hard_oos(self) -> None:
68 self.assertFalse(
69 is_explicitly_out_of_scope("öğrencinin diyet profilini güncelle")
70 )
71
72
73class StopwordsTests(unittest.TestCase):
74 def test_stopwords_are_folded_ascii(self) -> None:
75 # Katlanmış (ascii) olmalı ki içerik tokenlarıyla eşleşsin.
76 for word in STOPWORDS:
77 self.assertEqual(word, word.encode("ascii", "ignore").decode())
78
79
80if __name__ == "__main__":
81 unittest.main()