Repository navigation
Expand file tree
/
Copy pathtest_space_separated_functions.py
More file actions
144 lines (112 loc) · 4.52 KB
/
Copy pathtest_space_separated_functions.py
File metadata and controls
144 lines (112 loc) · 4.52 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""
Test script to verify that space-separated function applications are handled correctly.
Tests the specific case: k_e a mapped by b should give (b∘k_e)a, not bk_e a
"""
from PyQt6.QtWidgets import QApplication
from PyQt6.QtCore import QPointF
import sys
# Add the project root to Python path
sys.path.insert(0, r'C:\Users\fruit\OneDrive\Desktop\erro')
from core.app import App
from widget.main_window import MainWindow
from widget.object_node import Object
from widget.arrow import Arrow
from widget.diagram_scene import DiagramScene
from PyQt6.QtWidgets import QGraphicsView
from core.proof_step import MapElementProofStep
def test_space_separated_functions():
"""Test that space-separated function applications are handled correctly."""
app = App(sys.argv)
# Create scene directly for testing
scene = DiagramScene()
view = QGraphicsView(scene)
print("Testing space-separated function applications:")
print("=" * 55)
# Test Case 1: k_e a mapped by b should give (b∘k_e)a
print("\nTest Case 1: 'k_e a' mapped by 'b'")
print("-" * 40)
# Create domain with space-separated function application
domain1 = Object(text="k_e a:X")
domain1.setPos(QPointF(100, 100))
scene.addItem(domain1)
# Create codomain
codomain1 = Object(text="Y")
codomain1.setPos(QPointF(300, 100))
scene.addItem(codomain1)
# Arrow b
arrow1 = Arrow(start_node=domain1, end_node=codomain1, text="b")
scene.addItem(arrow1)
print(f"Before mapping:")
print(f" Domain: '{domain1.get_display_text()}'")
print(f" Codomain: '{codomain1.get_display_text()}'")
print(f" Arrow: '{arrow1.get_text()}'")
# Apply MapElement
step1 = MapElementProofStep(scene, [], [arrow1])
step1.apply()
print(f"After mapping 'k_e a' via 'b':")
print(f" Codomain: '{codomain1.get_display_text()}'")
print(f" Expected: '(b∘k_e)a:Y'")
print(f" Match: {codomain1.get_display_text() == '(b∘k_e)a:Y'}")
print(f" NOT bk_e a: {codomain1.get_display_text() != 'bk_e a:Y'}")
# Test Case 2: Simple space-separated like "f x"
print("\nTest Case 2: 'f x' mapped by 'g'")
print("-" * 35)
# Clear scene
scene.clear()
# Create domain with simple space-separated function application
domain2 = Object(text="f x:Z")
domain2.setPos(QPointF(100, 200))
scene.addItem(domain2)
# Create codomain
codomain2 = Object(text="W")
codomain2.setPos(QPointF(300, 200))
scene.addItem(codomain2)
# Arrow g
arrow2 = Arrow(start_node=domain2, end_node=codomain2, text="g")
scene.addItem(arrow2)
print(f"Before mapping:")
print(f" Domain: '{domain2.get_display_text()}'")
print(f" Codomain: '{codomain2.get_display_text()}'")
print(f" Arrow: '{arrow2.get_text()}'")
# Apply MapElement
step2 = MapElementProofStep(scene, [], [arrow2])
step2.apply()
print(f"After mapping 'f x' via 'g':")
print(f" Codomain: '{codomain2.get_display_text()}'")
print(f" Expected: '(g∘f)x:W'")
print(f" Match: {codomain2.get_display_text() == '(g∘f)x:W'}")
# Test Case 3: Multi-character function with underscore
print("\nTest Case 3: 'π_1 t' mapped by 'h'")
print("-" * 40)
# Clear scene
scene.clear()
# Create domain with projection function
domain3 = Object(text="π_1 t:U")
domain3.setPos(QPointF(100, 300))
scene.addItem(domain3)
# Create codomain
codomain3 = Object(text="V")
codomain3.setPos(QPointF(300, 300))
scene.addItem(codomain3)
# Arrow h
arrow3 = Arrow(start_node=domain3, end_node=codomain3, text="h")
scene.addItem(arrow3)
print(f"Before mapping:")
print(f" Domain: '{domain3.get_display_text()}'")
print(f" Codomain: '{codomain3.get_display_text()}'")
print(f" Arrow: '{arrow3.get_text()}'")
# Apply MapElement
step3 = MapElementProofStep(scene, [], [arrow3])
step3.apply()
print(f"After mapping 'π_1 t' via 'h':")
print(f" Codomain: '{codomain3.get_display_text()}'")
print(f" Expected: '(h∘π_1)t:V'")
print(f" Match: {codomain3.get_display_text() == '(h∘π_1)t:V'}")
print("\n" + "=" * 55)
print("Test completed!")
print("Space-separated function applications are now handled correctly.")
print("Format: 'func elem' mapped by 'g' → '(g∘func)elem'")
# Don't show the main window for this test
app.quit()
if __name__ == "__main__":
test_space_separated_functions()