Commit f8892759 authored by Damien L-G's avatar Damien L-G

Cleaned up tests for Map

parent b6cdc5b6
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.10)
project(noname LANGUAGES CXX)
......@@ -45,6 +45,6 @@ add_test(NAME testSpline2D COMMAND Spline2D)
# FIXME
file(COPY ${CMAKE_SOURCE_DIR}/dummy.csv DESTINATION ${CMAKE_BINARY_DIR})
add_executable(SplineMap noname_TestSplineMap.cpp)
target_link_libraries(SplineMap noname)
add_test(NAME testSplineMap COMMAND SplineMap)
add_executable(Map noname_TestMap.cpp)
target_link_libraries(Map noname)
add_test(NAME testMap COMMAND Map)
#include <noname_Map.hpp>
#include <noname_Spline2D.hpp>
#include <noname_TestAssertionMacros.hpp>
#include <cassert>
#include <stdexcept>
#include <string>
using namespace noname;
using SplineMap = Map<Spline2D<Bicubic>>;
std::string make_option(std::string const &x, std::string const &y,
std::string const &z) {
char const separator = '<';
std::string option = separator + x + separator + y + separator + z;
return option;
};
template <typename Spline>
void file_not_found() {
std::string const valid = "dummy.csv";
std::string const invalid = "does_not_exist.csv";
ASSERT_NO_THROW(Map<Spline>::get_spline(make_option(valid, valid, valid)));
ASSERT_THROW(Map<Spline>::get_spline(make_option(invalid, valid, valid)),
std::runtime_error);
ASSERT_THROW(Map<Spline>::get_spline(make_option(valid, invalid, valid)),
std::runtime_error);
ASSERT_THROW(Map<Spline>::get_spline(make_option(valid, valid, invalid)),
std::runtime_error);
}
template <typename Spline>
void invalid_number_of_options() {
std::string const valid = "dummy.csv";
char const separator = '<';
ASSERT_NO_THROW(Map<Spline>::get_spline(separator + valid + separator + valid +
separator + valid));
ASSERT_THROW(
Map<Spline>::get_spline(separator + valid + separator + valid + separator),
std::runtime_error);
ASSERT_THROW(Map<Spline>::get_spline(separator + valid + separator + valid +
separator + valid + separator +
"whatever"),
std::runtime_error);
}
template <typename Spline>
void control_map_growth() {
Map<Spline>::clear();
assert(Map<Spline>::size() == 0);
Map<Spline>::get_spline(
":dummy.csv: :dummy.csv: :dummy.csv:");
Map<Spline>::get_spline(
":dummy.csv: :dummy.csv: :dummy.csv:");
assert(Map<Spline>::size() == 1);
Map<Spline>::get_spline("|dummy.csv |dummy.csv |dummy.csv");
Map<Spline>::get_spline(
"? dummy.csv? ? ? ?dummy.csv???dummy.csv");
assert(Map<Spline>::size() == 3);
Map<Spline>::get_spline(
":dummy.csv: :dummy.csv: :dummy.csv:");
assert(Map<Spline>::size() == 3);
}
int main() {
int main() {
file_not_found<Spline2D<Bilinear>>();
file_not_found<Spline2D<Bicubic>>();
invalid_number_of_options<Spline2D<Bilinear>>();
invalid_number_of_options<Spline2D<Bicubic>>();
control_map_growth<Spline2D<Bilinear>>();
control_map_growth<Spline2D<Bicubic>>();
}
#include <noname_Map.hpp>
#include <noname_Spline2D.hpp>
#include <noname_TestAssertionMacros.hpp>
#include <cassert>
#include <stdexcept>
#include <string>
using namespace noname;
using SplineMap = Map<Spline2D<Bicubic>>;
void file_not_found() {
std::string const valid = "dummy.csv";
std::string const invalid = "does_not_exist.csv";
auto make_option = [](std::string const &x, std::string const &y,
std::string const &z) {
char const separator = '<';
std::string const filename = "dummy";
std::string const interpolation_type = "bicubic";
std::string const policy = "error";
std::string option = separator + x + separator + y + separator + z +
separator + interpolation_type + separator + policy;
return option;
};
ASSERT_NO_THROW(SplineMap::get_spline(make_option(valid, valid, valid)));
ASSERT_THROW(SplineMap::get_spline(make_option(invalid, valid, valid)),
std::runtime_error);
ASSERT_THROW(SplineMap::get_spline(make_option(valid, invalid, valid)),
std::runtime_error);
ASSERT_THROW(SplineMap::get_spline(make_option(valid, valid, invalid)),
std::runtime_error);
}
void interpolation_type_not_recognized() {
auto make_option = [](std::string const &t) {
char const separator = '<';
std::string const filename = "dummy.csv";
std::string const policy = "error";
std::string option = separator + filename + separator + filename +
separator + filename + separator + t + separator +
policy;
return option;
};
std::string const valid = "bicubic";
std::string const not_valid_yet = "bilinear";
std::string const invalid = "bad";
ASSERT_NO_THROW(SplineMap::get_spline(make_option(valid)));
ASSERT_THROW(SplineMap::get_spline(make_option(not_valid_yet)),
std::runtime_error);
ASSERT_THROW(SplineMap::get_spline(make_option(invalid)), std::runtime_error);
}
void policy_not_recognized() {
auto make_option = [](std::string const &p) {
char const separator = '<';
std::string const filename = "dummy.csv";
std::string const interpolation_type = "bicubic";
std::string option = separator + filename + separator + filename +
separator + filename + separator + interpolation_type +
separator + p;
return option;
};
std::string const valid = "error";
std::string const not_valid_yet = "extrapolate";
std::string const invalid = "bad";
ASSERT_NO_THROW(SplineMap::get_spline(make_option(valid)));
ASSERT_THROW(SplineMap::get_spline(make_option(not_valid_yet)),
std::runtime_error);
ASSERT_THROW(SplineMap::get_spline(make_option(invalid)), std::runtime_error);
}
void invalid_number_of_options() {
std::string const valid = "dummy.csv";
char const separator = '<';
std::string const interpolation_type = "bicubic";
std::string const policy = "error";
ASSERT_NO_THROW(SplineMap::get_spline(
separator + valid + separator + valid + separator + valid + separator +
interpolation_type + separator + policy));
ASSERT_THROW(SplineMap::get_spline(separator + valid + separator + valid +
separator + interpolation_type +
separator),
std::runtime_error);
ASSERT_THROW(SplineMap::get_spline(separator + valid + separator + valid +
separator + valid + separator + separator +
interpolation_type + separator + policy +
separator + "whatever"),
std::runtime_error);
}
void control_map_growth() {
SplineMap::clear();
assert(SplineMap::size() == 0);
SplineMap::get_spline(
":dummy.csv: :dummy.csv: :dummy.csv: :bicubic: :error:");
SplineMap::get_spline("|dummy.csv |dummy.csv |dummy.csv |bicubic |error");
SplineMap::get_spline(
"? dummy.csv? ? ? ?dummy.csv???dummy.csv ?bicubic ?error");
SplineMap::get_spline(" <dummy.csv <dummy.csv< dummy.csv < bicubic < error");
assert(SplineMap::size() == 1);
SplineMap::get_spline(
"<./dummy.csv <dummy.csv< dummy.csv << bicubic < error");
assert(SplineMap::size() == 2); // FIXME
}
int main() {
file_not_found();
interpolation_type_not_recognized();
policy_not_recognized();
invalid_number_of_options();
control_map_growth();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment