-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestFile.cpp
More file actions
131 lines (106 loc) · 3.49 KB
/
testFile.cpp
File metadata and controls
131 lines (106 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
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
// CMSC 411 Project - Summer 2025
// File: testFile.cpp
// Desc: The Test File
// Date: June 28, 2025
//Author: Qanita Baqibillah
#include <iostream>
#include <string>
#include <fstream>
#include "Processor.h"
#include "Instruction.h"
using namespace std;
class Tester{
public:
void testLoadInstructions(const string& filename);
void testExportSpreadsheet();
void testAddressToIndex();
void testStore();
void testLoad();
void testConvertPipline();
private:
};
int main(){
string testFilename = "InstructionText.txt";
Tester test;
test.testLoadInstructions(testFilename);
test.testExportSpreadsheet();
test.testAddressToIndex();
test.testStore();
test.testLoad();
test.testConvertPipline();
Processor p;
p.displayMemory();
p.displayRegistersF();
p.displayRegistersInt();
return 0;
}
void Tester::testLoadInstructions(const string& filename){
Processor proc;
proc.loadInstructions(filename);
// To disisplay the loaded instructions
// cout << "Loaded Instructions from txt: " << endl;
// for (int i = 0; i < 6; i++) {
// Instruction* instr = proc.getInstructionAt(i);
// if (instr != nullptr) {
// cout << i + 1 << ": " << instr->getPlaintext() << endl;
// }
// }
}
void Tester::testExportSpreadsheet(){
int rows = 3;
int cols = 4;
// create the dynamic 2D array
string** spreadsheet = new string*[rows];
for (int i = 0; i < rows; ++i) {
spreadsheet[i] = new string[cols];
}
// populate the spreadsheet with some test data
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
spreadsheet[i][j] = "R" + to_string(i) + "C" + to_string(j);
}
}
// create the processor instance just to use export function
Processor proc;
string filename = "outputSpreadsheet.txt";
proc.exportSpreadsheet(filename, spreadsheet, rows, cols);
// clean up memory later if needed
// for (int i = 0; i < rows; ++i) {
// delete[] spreadsheet[i];
// }
// delete[] spreadsheet;
}
void Tester::testAddressToIndex(){
Processor p;
// Last four are error cases and should return -1
string testCases[] = {"$0", "$5", "$18", "$19", "$20", "0($0)", "4($1)", "16($18)", "100($19)","($2)",
"1", "18", "100", "( $3 )", "invalid", "", "$"};
cout << "Testing memoryAddressToIndex: " << endl;
for (int i = 0; i < sizeof(testCases) / sizeof(testCases[0]); i++) {
int index = p.memoryAddressToIndex(testCases[i]);
cout << "memAddress: " << testCases[i] << "-> Index: " << index << endl;
}
}
void Tester::testStore(){
// Processor p;
// p.setRegisterValue("$5", 101);
// p.store("$5", "0($2)");
// int expectedIndex = p.memoryAddressToIndex("0($2)");
// int actualValue = p.getMemoryValue(expectedIndex);
// cout << "Testing store(): " << endl;
// cout << "Expected memory[" << expectedIndex << "] = 101. Got: " << actualValue << endl;
}
void Tester::testLoad(){
// Processor p;
// int expectedValue = 101;
// int memoryIndex = 5;
// p.setRegisterValue("$1", expectedValue);
// p.store("$1", "$5");
// p.load("$10", "$5");
// int actual = p.getRegisterValue("$10");
// cout << "Testing load(): " << endl;
// cout << "Register $10 contains " << actual << ". Expected: " << expectedValue << endl;
}
void Tester::testConvertPipline(){
Processor p;
}