forked from nus-tic2002-2021/duke
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCoreFunction.java
More file actions
97 lines (81 loc) · 3.49 KB
/
Copy pathTestCoreFunction.java
File metadata and controls
97 lines (81 loc) · 3.49 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
import ui.WhatsAppStyleChatUI;
import java.lang.reflect.Method;
/**
* Test class to verify core functionality of natural language processing
*/
public class TestCoreFunction {
public static void main(String[] args) {
try {
// Create an instance to test preprocessing
WhatsAppStyleChatUI chatUI = new WhatsAppStyleChatUI();
// Use reflection to access the private preprocessInput method
Method preprocessMethod = WhatsAppStyleChatUI.class.getDeclaredMethod("preprocessInput", String.class);
preprocessMethod.setAccessible(true);
System.out.println("🧪 Testing Core Natural Language Processing");
System.out.println("===========================================\n");
// Test cases
String[] testInputs = {
// Event tests
"meeting tomorrow at 2pm",
"event meeting tomorrow at 2pm",
"add meeting tomorrow at 2pm",
"appointment with doctor on friday 3pm",
"lunch with client next monday at 12pm",
// Deadline tests
"deadline project by friday",
"submit report by tomorrow 5pm",
"finish homework by next week",
"project due next friday",
// Todo tests
"add buy milk",
"todo tell baby a joke",
"create shopping list",
"buy groceries",
"call mom",
// Direct commands (should pass through)
"list",
"help",
"done 1",
"delete 2"
};
for (String input : testInputs) {
try {
String result = (String) preprocessMethod.invoke(chatUI, input);
System.out.printf("Input: \"%s\"\n", input);
System.out.printf("Output: \"%s\"\n", result);
System.out.println("Status: " + (isValidCommand(result) ? "✅ VALID" : "❌ INVALID"));
System.out.println();
} catch (Exception e) {
System.out.printf("Input: \"%s\"\n", input);
System.out.printf("Error: %s\n", e.getMessage());
System.out.println("Status: ❌ ERROR");
System.out.println();
}
}
} catch (Exception e) {
System.err.println("Failed to test: " + e.getMessage());
e.printStackTrace();
}
}
private static boolean isValidCommand(String command) {
String cmd = command.toLowerCase().trim();
// Check for valid todo format
if (cmd.startsWith("todo ") && cmd.length() > 5) {
return true;
}
// Check for valid event format
if (cmd.startsWith("event ") && cmd.contains(" /at ")) {
return true;
}
// Check for valid deadline format
if (cmd.startsWith("deadline ") && cmd.contains(" /by ")) {
return true;
}
// Check for direct commands
if (cmd.equals("list") || cmd.equals("help") || cmd.startsWith("done ") ||
cmd.startsWith("delete ") || cmd.startsWith("search ")) {
return true;
}
return false;
}
}