ArrayList_tests.cpp 1.8 KB
Newer Older
Matthew P. Russell's avatar
Matthew P. Russell committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
ArraryList_tests.cpp
matt russell
comp15 2020 summer

This file demonstrates a few tests you might run on an ArrayList class.

The format followed below will work correctly with the COMP15 autograding framework.

Rules:
    All tests must return void, and have no arguments

    If a test finishes execution, it is considered successful.

    Use assert(boolean_condition) to test for a known condition.
Matthew P. Russell's avatar
Matthew P. Russell committed
16

Matthew P. Russell's avatar
Matthew P. Russell committed
17
18
19
20
    If the condition evaluates to false, then the assertion fails, the test will fail.

    You should #include any .h files (as in #include "ArrayList.h" below) as necessary

Matthew P. Russell's avatar
Matthew P. Russell committed
21
22
    You may have multiple _tests.cpp files, but each test must have a unique name

Matthew P. Russell's avatar
Matthew P. Russell committed
23
24
25
26
27
28
29
30
31
32
33
Note that valgrind will be run automatically on all tests, so even tests that seem to do 
nothing (i.e. constructor_0) can still be quite useful. 

You are encouraged to write MANY, MANY tests!!!

Furthermore, you are encouraged to write tests immediately after writing a function.

So, write a function, then write test cases for it, and run the test cases, and so on.

*****It is usually wise to debug BEFORE moving on to writing the next function.*****

Matthew P. Russell's avatar
Matthew P. Russell committed
34
35
NB: The ArrayList code has bugs, so the tests will fail first on purpose!

Matthew P. Russell's avatar
Matthew P. Russell committed
36
37
38
39
40
41
42
43
*/

#include <cassert>
#include "ArrayList.h"

/*
 * constructor test 0 - make sure no fatal errors/memory leaks in the default constructor
 */
44
void constructor_0() {
Matthew P. Russell's avatar
Matthew P. Russell committed
45
46
47
48
49
50
51
  ArrayList list = ArrayList();
}

/*
 * constructor test 1 - make sure no items exist in the list upon construction
 * note: given the provided code, this test should fail. 
 */
52
void constructor_1() {
Matthew P. Russell's avatar
Matthew P. Russell committed
53
54
55
56
57
58
59
60
  ArrayList list = ArrayList();
  assert(list.numitems() == 0);
}

/*
 * destructor test (destructor called implicitly)
 * make sure no fatal errors/memory leaks in the destructor (based on default constructor)
 */
61
void destructor() {
Matthew P. Russell's avatar
Matthew P. Russell committed
62
63
64
65
  ArrayList list = ArrayList();  
}