-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBasicListTest.cpp
More file actions
55 lines (48 loc) · 1.14 KB
/
BasicListTest.cpp
File metadata and controls
55 lines (48 loc) · 1.14 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
#include <iostream>
using namespace std;
#include "SLList.h"
using namespace ods;
bool testGetSet(SLList<char>& L) {
int n = 5;
L.clear();
bool pass = true;
// test get
for (int i = 0; i < n; ++i)
L.push('e' - i);
if (L.size() != n) pass = false;;
for (int i = 0; i < n; ++i)
if (L.get(i) != 'a'+i)
pass = false;
if (L.size() != n) pass = false; // get should not change size!
if (not pass) {
cout << "error in get" << endl;
return false;
}
// test get after a change
L.pop(); --n;
for (int i = 0; i < n; ++i)
if (L.get(i) != 'b'+i)
pass = false;
if (L.size() != n) pass = false;;
if (not pass) {
cout << "error in get after change" << endl;
return false;
}
// test set
for (int i = 0; i < n; ++i)
L.set(i, '0'+i);
if (L.size() != n) pass = false; // set should not change size!
for (int i = 0; i < n; ++i)
if (L.get(i) != '0'+i)
pass = false;
if (not pass)
cout << "error in set" << endl;
return pass;
}
int main(){
SLList<char> L;
if (testGetSet(L))
cout << "Passed test of get/set part of List interface" << endl;
else
cout << "FAILED test of get/set part of List interface" << endl;
}