-
Notifications
You must be signed in to change notification settings - Fork 0
/
testrest.cpp
85 lines (68 loc) · 1.82 KB
/
testrest.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
// testlist.cpp
// Tests intlist.cpp
#include "intlist.h"
#include <cstdlib> // provides atoi
#include <iostream>
#include <cassert>
using namespace std;
void test_copyconstructor(){
IntList list1;
int arr[] ={10, 50, 60, 70, 100};
for(int i = 0; i<5; i++){
list1.append(arr[i]);
}
IntList list2(list1);
assert(list1.count()== 5);
assert(list2.count()==list1.count());
for(int i = 0; i<5; i++){
list1.append(2*arr[i]);
}
assert(list1.count()== 10);
assert(list2.count()== 5);
}
void test_destructor(){
IntList *list1 = new IntList;
int arr[] ={10, 50, 60, 70, 100};
for(int i = 0; i<5; i++){
list1->append(arr[i]);
}
delete list1;
}
void test_assignmentOperator(){
IntList list1, list2;
int arr[] ={10, 50, 60, 70, 100};
for(int i = 0; i<5; i++){
list1.append(arr[i]);
}
for(int i = 0; i<5; i++){
list2.append(2*arr[i]);
}
list2 = list1;
assert(list2.sum()==list1.sum());
list1.append(100);
assert((list2.sum()+100) == list1.sum());
list1 = IntList();
assert(list1.sum() == 0);
assert(list1.count() == 0);
}
// creates two lists (one empty), and does simple tests of list methods
int main(int argc, char* argv[]) {
if (argc != 2) {
cout << "error: need at least one int arg on command line" << endl;
cout << "usage: " << argv[0] << " testid " << endl;
return 1;
}
if(atoi(argv[1])==1){
test_copyconstructor();
cout<<"PASSED copy constructor tests"<<endl;
}
if(atoi(argv[1])==2){
test_destructor();
cout<<"Testing destructor, run in valgrind to check for leaks"<<endl;
}
if(atoi(argv[1])==3){
test_assignmentOperator();
cout<<"PASSED assignment operator tests"<<endl;
}
return 0;
}