-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_genai_logic_hello.py
More file actions
94 lines (74 loc) · 3.36 KB
/
test_genai_logic_hello.py
File metadata and controls
94 lines (74 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
"""
Tests for GenAI-Logic Hello World Example
"""
import unittest
from genai_logic_hello import GenAILogicHello
class TestGenAILogicHello(unittest.TestCase):
"""Test cases for GenAI-Logic Hello World functionality."""
def setUp(self):
"""Set up test fixtures."""
self.genai_logic = GenAILogicHello()
def test_generate_greeting(self):
"""Test AI greeting generation."""
greeting = self.genai_logic.generate_greeting("TestUser")
self.assertIn("TestUser", greeting)
self.assertTrue(len(greeting) > 0)
def test_generate_greeting_default(self):
"""Test AI greeting with default name."""
greeting = self.genai_logic.generate_greeting()
self.assertIn("World", greeting)
def test_apply_logic_time_based(self):
"""Test time-based logic rules."""
context = {"time": "morning"}
result = self.genai_logic.apply_logic(context)
self.assertIn("morning", result.lower())
context = {"time": "afternoon"}
result = self.genai_logic.apply_logic(context)
self.assertIn("afternoon", result.lower())
def test_apply_logic_mood_based(self):
"""Test mood-based logic rules."""
context = {"mood": "excited"}
result = self.genai_logic.apply_logic(context)
self.assertIn("excitement", result.lower())
context = {"mood": "curious"}
result = self.genai_logic.apply_logic(context)
self.assertIn("curiosity", result.lower())
def test_apply_logic_unknown_context(self):
"""Test logic with unknown context."""
context = {"unknown": "value"}
result = self.genai_logic.apply_logic(context)
self.assertTrue(len(result) > 0)
def test_hello_world_basic(self):
"""Test basic hello world functionality."""
result = self.genai_logic.hello_world()
self.assertIn("ai_greeting", result)
self.assertIn("logical_response", result)
self.assertIn("combined_message", result)
self.assertIn("World", result["ai_greeting"])
def test_hello_world_personalized(self):
"""Test personalized hello world."""
result = self.genai_logic.hello_world("Alice")
self.assertIn("Alice", result["ai_greeting"])
self.assertIn("Alice", result["combined_message"])
def test_hello_world_with_context(self):
"""Test hello world with context."""
context = {"time": "evening", "mood": "focused"}
result = self.genai_logic.hello_world("Bob", context)
# Should contain the name
self.assertIn("Bob", result["ai_greeting"])
# Should apply one of the logic rules (time takes precedence)
self.assertTrue(
"evening" in result["logical_response"].lower() or
"focus" in result["logical_response"].lower()
)
def test_greeting_templates_variety(self):
"""Test that different greeting templates are used."""
greetings = set()
for _ in range(20): # Generate multiple greetings
greeting = self.genai_logic.generate_greeting("Test")
greetings.add(greeting)
# Should have at least 2 different templates (randomness permitting)
self.assertGreaterEqual(len(greetings), 1)
if __name__ == "__main__":
unittest.main()