You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 24, 2019. It is now read-only.
There is a file named count_if_followed_by.cpp in the assignment directory:
// .-------------------------------------------------------
// | count_if_followed_by (data, len, a, b);
// |
// | About: Returns the number of occurances of
// | a followed by b in the range [data, data+len).
// ’-------------------------------------------------------
int count_if_followed_by (char const * p, int len, char a, char b) {
int count = 0;
char const * end = p + len;
while (p != end) {
if (*p == a && *(p+1) == b)
count += 1;
++p;
}
return count;
}
0.4.1 cxxtest; a unit test framework
A unit test framework, such as cxxtest, allows a developer to specify
constraints, and the expected behavior, of an implementation that he/she would
like to test.
These rules are later used to generate unit tests. These unit tests will test
to see that an implementation behaves as it shall (according to the previously
stated specification).
The steps associated with using a unit test framework for C++ typically
includes the following:
Specify the constraints and requirements that you would like to test.
Ask the unit test framework to generate a test runner having semantics
associated with your specifications.
Compile the test runner into an executable.
Invoke the executable to commence testing.
0.4.1.1 Generating a test runner
There is a file named simple.cxxtest.cpp in the assignment directory.
Asking cxxtest to generate a test runner from the contents of this file can
be accomplished through the following:
Before we can execute our test runner, the test runner itself must be
compiled it into an executable. This includes linking it together with an
object file that contains our implementation.
The test can be run by invoking ./simple_test.out.
0.4.1.3 Writing a test using_cxxtest_
Note: You may simplify the task of generating, and compiling, test runners by
writing a new rule inside your makefile.
There is an intentional bug in the definition of count_if_followed_by; it
will poten- tially access one element outside the range specified.
Collectively, bugs of this sort is most often referred to as "off-by-one
errors".
// expected: result == 0
// outcome: result == 1 (!!!)
char const data[4] = {’G’,’G’,’X’,’G’};
int const result = count_if_followed_by (data, 3, ’X’, ’G’);
0.4.2 Requirements
Submit three (3) different tests to Kattis that test the correct, and
incorrect, behavior of count_if_followed_by. The tests shall be presented
during your oral presentation.
0.4.3 Questions
Why is it important to test the boundary conditions of an implementation,
especially in the case of count_if_followed_by?
The text was updated successfully, but these errors were encountered:
Errors often happen at the boundaries if you're careless
Sometimes errors are more easily exposed at the boundaries even when they
affect program flow elsewhere as well (and so, testing boundary conditions
can help expose problems that may not be apparent otherwise).
Especially in the case of count_if_followed_by because it does pointer
arithmetic, which doesn't necessarily cause compile-time errors nor runtime
crashes.
#0.4 Does It Fit? (unit testing)
There is a file named
count_if_followed_by.cpp
in the assignment directory:0.4.1
cxxtest
; a unit test frameworkA unit test framework, such as cxxtest, allows a developer to specify
constraints, and the expected behavior, of an implementation that he/she would
like to test.
These rules are later used to generate unit tests. These unit tests will test
to see that an implementation behaves as it shall (according to the previously
stated specification).
The steps associated with using a unit test framework for C++ typically
includes the following:
associated with your specifications.
0.4.1.1 Generating a test runner
There is a file named
simple.cxxtest.cpp
in the assignment directory.Asking cxxtest to generate a test runner from the contents of this file can
be accomplished through the following:
0.4.1.2 Compiling the test runner
Before we can execute our test runner, the test runner itself must be
compiled it into an executable. This includes linking it together with an
object file that contains our implementation.
Create an object file of our implementation:
Compile our test runner, and link it with the object file:
The test can be run by invoking
./simple_test.out
.0.4.1.3 Writing a test using_cxxtest_
There is an intentional bug in the definition of
count_if_followed_by
; itwill poten- tially access one element outside the range specified.
Collectively, bugs of this sort is most often referred to as "off-by-one
errors".
0.4.2 Requirements
incorrect, behavior of
count_if_followed_by
. The tests shall be presentedduring your oral presentation.
0.4.3 Questions
especially in the case of
count_if_followed_by
?The text was updated successfully, but these errors were encountered: