-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGENERATE_UNIT_TEST_METHODS.CPP
90 lines (80 loc) · 1.89 KB
/
GENERATE_UNIT_TEST_METHODS.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
81
82
83
84
85
86
87
88
89
90
#include<iostream>
#include<fstream>
using namespace std;
//right function for testing grades
string getGradeExpectedValue(int mid, int ct, int finalExam, int attendance) {
int total = mid+ct+finalExam+attendance;
string grade = "";
if(total >= 80) {
grade = "A+";
}
else if(total >=70) {
grade = "A";
}
else if (total >= 60) {
grade = "B";
}
else if (total >= 50) {
grade = "C";
}
else if (total <= 50) {
grade = "F";
}
return grade;
}
string getGradeValue(int mid, int ct, int finalExam, int attendance) {
int total = mid+ct+finalExam+attendance;
string grade = "";
if(total >= 80) {
grade = "A+";
}
if(total >=70) {
grade = "A";
}
if (total >= 60) {
grade = "B";
}
if (total >= 50) {
grade = "C";
}
if (total <= 50) {
grade = "F";
}
return grade;
}
bool openFile(string fileName,ofstream &ofile){
ofile.open(fileName);
if(!ofile.is_open()) {
cout<<"problem"<<endl;
return false;
};
return true;
}
bool readFile(string fileName,ifstream &ifile){
ifile.open(fileName);
if(!ifile.is_open()) {
cout<<"problem in reading"<<endl;
return false;
};
return true;
}
int main(){
ifstream ifile;
ofstream ofile,ofileresult;
char ch;
string s;
int id,mid,ct,finel,att;
if(readFile("worst.csv",ifile) && openFile("methods.java",ofile) && openFile("data.csv",ofileresult)){
//cout<<id<<" calling"<<endl;
while(ifile>>id>>ch>>mid>>ch>>ct>>ch>>finel>>ch>>att){
ofile<<"@Test\n";
ofile<<"public void getGradeTestWorstCase"<<id<<" () {"<<endl;
ofile<<"\tGradeCalculator gc= new GradeCalculator();"<<endl;
ofile<<"\tString grade = gc.getGrade("<<mid<<","<<ct<<","<<finel<<","<<att<<");"<<endl;
ofile<<"\tString expected = \"Z\";"<<endl;
ofile<<"\tassertEquals(expected,grade);"<<endl;
ofile<<"}"<<endl;
ofileresult<<id<<","<<mid<<","<<ct<<","<<finel<<","<<att<<","<<"Z"<<","<<getGradeValue(mid,ct,finel,att)<<","<<"Fail"<<endl;
}
}
}