Added unit tests for new sparse vector routines.

This commit is contained in:
Davis King 2012-04-30 22:06:37 -04:00
parent 7f43406195
commit 3321b43e67
3 changed files with 69 additions and 0 deletions

View File

@ -101,6 +101,7 @@ set (tests
sockets2.cpp sockets2.cpp
sockets.cpp sockets.cpp
sockstreambuf.cpp sockstreambuf.cpp
sparse_vector.cpp
stack.cpp stack.cpp
static_map.cpp static_map.cpp
static_set.cpp static_set.cpp

View File

@ -116,6 +116,7 @@ SRC += smart_pointers.cpp
SRC += sockets2.cpp SRC += sockets2.cpp
SRC += sockets.cpp SRC += sockets.cpp
SRC += sockstreambuf.cpp SRC += sockstreambuf.cpp
SRC += sparse_vector.cpp
SRC += stack.cpp SRC += stack.cpp
SRC += static_map.cpp SRC += static_map.cpp
SRC += static_set.cpp SRC += static_set.cpp

View File

@ -0,0 +1,67 @@
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include "tester.h"
#include <dlib/svm.h>
#include <dlib/rand.h>
#include <dlib/string.h>
#include <vector>
#include <sstream>
#include <ctime>
namespace
{
using namespace test;
using namespace dlib;
using namespace std;
using namespace dlib::sparse_vector;
dlib::logger dlog("test.sparse_vector");
class sparse_vector_tester : public tester
{
public:
sparse_vector_tester (
) :
tester (
"test_sparse_vector", // the command line argument name for this test
"Run tests on the sparse_vector routines.", // the command line argument description
0 // the number of command line arguments for this test
)
{
}
void perform_test (
)
{
std::map<unsigned int, double> v;
v[4] = 8;
v[2] = -4;
v[9] = 10;
DLIB_TEST(max(v) == 10);
DLIB_TEST(min(v) == -4);
v.clear();
v[4] = 8;
v[9] = 10;
DLIB_TEST(max(v) == 10);
DLIB_TEST(min(v) == 0);
v.clear();
v[4] = -9;
v[9] = -4;
DLIB_TEST(max(v) == 0);
DLIB_TEST(min(v) == -9);
}
};
sparse_vector_tester a;
}