-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainMenuTest.java
More file actions
86 lines (69 loc) · 3.02 KB
/
Copy pathMainMenuTest.java
File metadata and controls
86 lines (69 loc) · 3.02 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
import static org.junit.jupiter.api.Assertions.*;
import java.util.*;
import java.io.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class MainMenuTest {
@BeforeEach
void setUp() throws Exception {
//clear all pre-existing logs before "each" test to prevent data contamination
//Add random missing logs as samples
HashMap<String, String> entry1 = new HashMap<>();
entry1.put("log", "Had a great day!");
entry1.put("logDate", "2025-02-20");
entry1.put("logTime", "10:30:00");
entry1.put("sentimentScore", "9");
HashMap<String, String> entry2 = new HashMap<>();
entry2.put("log", "Feeling sad today.");
entry2.put("logDate", "2025-02-19");
entry2.put("logTime", "14:15:00");
entry2.put("sentimentScore", "3");
HashMap<String, String> entry3 = new HashMap<>();
entry3.put("log", "Super happy and excited!");
entry3.put("logDate", "2025-02-18");
entry3.put("logTime", "08:45:00");
entry3.put("sentimentScore", "10");
HashMap<String, String> entry4 = new HashMap<>();
entry4.put("log", "Feeling neutral.");
entry4.put("logDate", "2025-02-17");
entry4.put("logTime", "09:20:00");
entry4.put("sentimentScore", "5");
HashMap<String, String> entry5 = new HashMap<>();
entry5.put("log", "Worst day ever...");
entry5.put("logDate", "2025-02-16");
entry5.put("logTime", "20:10:00");
entry5.put("sentimentScore", "1");
HashMap<String, String> entry6 = new HashMap<>();
entry6.put("log", "Feeling okay.");
entry6.put("logDate", "2025-02-15");
entry6.put("logTime", "11:50:00");
entry6.put("sentimentScore", "6");
//adds examples of entries to main menu logs
MainMenu.logs.add(entry1);
MainMenu.logs.add(entry2);
MainMenu.logs.add(entry3);
MainMenu.logs.add(entry4);
MainMenu.logs.add(entry5);
MainMenu.logs.add(entry6);
}
@Test
void testMostPositiveDays(){
List<HashMap<String,String>> result = MainMenu.mostPositiveDays();
int expected = 3;//since from the example logs, there are 3 sent values greater than6
int actual = result.size();//actual values the function returns
assertEquals(expected, actual);
//assertEquals checks the first 'expected' entries after checking if the expected logs = actual size of return logs
assertEquals("10", result.get(0).get("sentimentScore"));//should list in descending order(highest sent score first)
assertEquals("9", result.get(1).get("sentimentScore"));
assertEquals("6", result.get(2).get("sentimentScore"));
}
@Test
void testMostNegativeDays(){
List<HashMap<String,String>> result = MainMenu.mostNegativeDays();
int expected = 2;//there are 2 negative days in the example logs
int actual = result.size();//actual values the function returns
assertEquals(expected, actual);//checks if the expected logs = actual size of return logs
assertEquals("1", result.get(0).get("sentimentScore"));//lowest score first(ascending order)
assertEquals("3", result.get(1).get("sentimentScore"));
}
}