Update build and basic DS test framework.
This commit is contained in:
parent
eb37973147
commit
8ea78af90b
|
@ -21,6 +21,8 @@ then
|
|||
mkdir -p $BUILDDIR && cd $BUILDDIR
|
||||
autoreconf -i $SRCDIR
|
||||
bash $SRCDIR/configure $CONFOPTS
|
||||
[ -d "$BUILDDIR/data" ] || mkdir "$BUILDDIR/data"
|
||||
cp $SRCDIR/data/corpus* "$BUILDDIR/data"
|
||||
else
|
||||
autoreconf -i
|
||||
./configure $CONFOPTS
|
||||
|
|
|
@ -8,5 +8,5 @@ ods-cpp/main.cpp: ods-cpp.tgz
|
|||
|
||||
ODS_SAMPLE_CODE_URL := http://opendatastructures.org/ods-cpp.tgz
|
||||
ods-cpp.tgz:
|
||||
if command -v curl 2>&1 > /dev/null ; then curl -L -O $(ODS_SAMPLE_CODE_URL) \
|
||||
if command -v curl 2>&1 > /dev/null ; then curl -L -O $(ODS_SAMPLE_CODE_URL) ; \
|
||||
elif command -v curl 2>&1 > /dev/null ; then wget $(ODS_SAMPLE_CODE_URL) ; fi
|
||||
|
|
|
@ -148,6 +148,8 @@ Run times come in three flavours:
|
|||
interfaces. These do not have to be efficient. They can be used later to
|
||||
test the correctness and performance of more efficient implementations.
|
||||
|
||||
In progress: src/ch01ex06.cc, src/ods/simplist.h, src/ods/uset.h.
|
||||
|
||||
7. Work to improve the performance of your implementations
|
||||
from the previous question using any tricks you can think of. Experiment
|
||||
and think about how you could improve the performance of add(i,x) and
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
AM_CPPFLAGS = -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align
|
||||
AM_CPPFLAGS += -Wwrite-strings -Wmissing-declarations -Wno-long-long -Werror
|
||||
AM_CPPFLAGS += -Wunused-variable -std=c++14 -D_XOPEN_SOURCE -O0 -g -I.
|
||||
AM_CPPFLAGS += -Wunused-variable -std=c++17 -D_XOPEN_SOURCE -O0 -g -I.
|
||||
AM_CPPFLAGS += -fno-elide-constructors -Weffc++
|
||||
|
||||
bin_PROGRAMS := ch01ex01 ch01ex03 ch01ex04 ch01ex05 ch01ex06
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <ods/simplist.h>
|
||||
#include <ods/simpuset.h>
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
@ -12,6 +14,54 @@ check_simplist(void)
|
|||
sl.add(1, 2);
|
||||
sl.add(2, 3);
|
||||
assert(sl.size() == 3);
|
||||
|
||||
sl.add(0, 4);
|
||||
sl.add(1, 5);
|
||||
sl.add(2, 6);
|
||||
assert(sl.size() == 6);
|
||||
|
||||
int expected[6] = {4, 5, 6, 1, 2, 3};
|
||||
for (size_t i = 0; i < 6; i++) {
|
||||
assert(sl.get(i) == expected[i]);
|
||||
}
|
||||
|
||||
bool caught = false;
|
||||
try {
|
||||
sl.add(8, 8);
|
||||
} catch (std::invalid_argument) {
|
||||
caught = true;
|
||||
}
|
||||
assert(caught);
|
||||
|
||||
assert(sl.get(2) == 6);
|
||||
sl.remove(2);
|
||||
assert(sl.get(2) == 1);
|
||||
assert(sl.size() == 5);
|
||||
sl.set(2, 6);
|
||||
assert(sl.get(2) == 6);
|
||||
|
||||
// expected = {1, 2, 3, 4, 5, 6};
|
||||
for (size_t i = 0; i < 6; i++) {
|
||||
expected[i] = i+1;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 5; i++) {
|
||||
sl.set(i, i+1);
|
||||
}
|
||||
sl.add(5, 6);
|
||||
|
||||
for (size_t i = 0; i < 6; i++) {
|
||||
assert(sl.get(i) == expected[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
check_simpuset(void)
|
||||
{
|
||||
ods::SimpUSet<int> us;
|
||||
|
||||
assert(us.add(1));
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,4 +69,6 @@ int
|
|||
main(void)
|
||||
{
|
||||
check_simplist();
|
||||
check_simpuset();
|
||||
cout << "OK" << endl;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue