-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtester.cpp
82 lines (66 loc) · 1.73 KB
/
tester.cpp
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
/*
* This is a driver to test pass1 and the Label Table functions.
*
* Author: Alyce Brady
* Date: 2/18/99
* Modified by: Caitlin Braun and Giancarlo Anemone to test pass2 of the assembler.
*/
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include "LableTable.h"
#include <sstream>
#include "phase2.h"
#include "phase1.h"
using namespace std;
LableTable phase1 (char * filename);
LableTable phase2 (char * filename, LableTable table);
int compare_files(ifstream& in_file1, ifstream& in_file2)
{
while (!in_file1.eof() && !in_file2.eof())
{
string line1;
string line2;
getline(in_file1, line1);
getline(in_file2, line2);
if(line1 != line2){
cout << "line1:"<< line1 <<endl;
cout << "line2:"<<line2 << endl;
return -1;
}
}
return 0;
}
int main (int argc, char * argv[])
{
if(argc < 4)
{
printf("Please enter an input file, an output file, and expected output file \n");
}
LableTable table;
table = phase1(argv[1]);
map<string, int>::iterator it;
for (it = table.begin(); it != table.end(); it++)
cout << it->first << " " << it->second << endl;
(void)phase2(argv[1], table);
FILE* fp1;
FILE* fp2;
fp1 = fopen(argv[3], "r");
fp2 = fopen(argv[2], "r");
if(fp1 == NULL || fp2 == NULL){
printf("Error: Files are not open correctly \n");
}
ifstream in_file1;
ifstream in_file2;
in_file1.open(argv[3]);
in_file2.open(argv[2]);
int res = compare_files(in_file1, in_file2);
if(res == 0){
printf("ALL PASSED! CONGRATS :) \n");
}else{
printf("YOU DID SOMETHING WRONG :( \n");
}
fclose(fp1);
fclose(fp2);
return 0;
}