Tests: Broke up helper/data tests

This commit is contained in:
Paul Beckingham 2016-04-28 20:59:28 -04:00
parent ee5985471b
commit 627cda219e
4 changed files with 81 additions and 40 deletions

1
test/.gitignore vendored
View file

@ -1,5 +1,6 @@
all.log all.log
*.pyc *.pyc
data.t
exclusion.t exclusion.t
helper.t helper.t
interval.t interval.t

View file

@ -14,7 +14,7 @@ include_directories (${CMAKE_SOURCE_DIR}
include_directories (${CMAKE_INSTALL_PREFIX}/include) include_directories (${CMAKE_INSTALL_PREFIX}/include)
link_directories(${CMAKE_INSTALL_PREFIX}/lib) link_directories(${CMAKE_INSTALL_PREFIX}/lib)
set (test_SRCS exclusion.t helper.t interval.t lexer.t palette.t range.t rules.t util.t) set (test_SRCS data.t exclusion.t helper.t interval.t lexer.t palette.t range.t rules.t util.t)
add_custom_target (test ./run_all --verbose add_custom_target (test ./run_all --verbose
DEPENDS ${test_SRCS} DEPENDS ${test_SRCS}

78
test/data.t.cpp Normal file
View file

@ -0,0 +1,78 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2015 - 2016, Paul Beckingham, Federico Hernandez.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// http://www.opensource.org/licenses/mit-license.php
//
////////////////////////////////////////////////////////////////////////////////
#include <cmake.h>
#include <timew.h>
#include <test.h>
////////////////////////////////////////////////////////////////////////////////
int main (int, char**)
{
UnitTest t (15);
// std::vector <Interval> splitInterval (const Interval&, std::vector <Range>&);
Interval i1;
i1.range = Range (Datetime ("20160427T000000Z"), Datetime ("20160428T000000Z"));
i1.tag ("foo");
std::vector <Range> exclusions = {Range (Datetime ("20160427T000000Z"), Datetime ("20160427T080000Z")),
Range (Datetime ("20160427T120000Z"), Datetime ("20160427T130000Z")),
Range (Datetime ("20160427T173000Z"), Datetime ("20160428T000000Z"))};
auto results = collapse (i1, exclusions);
t.ok (results.size () == 2, "splitInterval --> 2 fragments");
t.is (results[0].range.start.toISO (), "20160427T080000Z", "splitInterval --> results[0].range.start 20160427T080000Z");
t.is (results[0].range.end.toISO (), "20160427T120000Z", "splitInterval --> results[0].range.end 20160427T120000Z");
t.is (results[1].range.start.toISO (), "20160427T130000Z", "splitInterval --> results[1].range.start 20160427T130000Z");
t.is (results[1].range.end.toISO (), "20160427T173000Z", "splitInterval --> results[1].range.end 20160427T173000Z");
Interval i2;
i2.range = Range (Datetime ("20160427T115500Z"), Datetime ("20160427T130500Z"));
i2.tag ("foo");
results = collapse (i2, exclusions);
t.ok (results.size () == 2, "splitInterval --> 2 fragments");
t.is (results[0].range.start.toISO (), "20160427T115500Z", "splitInterval --> results[0].range.start 20160427T115500Z");
t.is (results[0].range.end.toISO (), "20160427T120000Z", "splitInterval --> results[0].range.end 20160427T120000Z");
t.is (results[1].range.start.toISO (), "20160427T130000Z", "splitInterval --> results[1].range.start 20160427T130000Z");
t.is (results[1].range.end.toISO (), "20160427T130500Z", "splitInterval --> results[1].range.end 20160427T130500Z");
Interval i3;
i3.range = Range (Datetime ("20160427T160000Z"), Datetime (0));
i3.tag ("foo");
t.ok (i3.range.started (), "i3 range started");
t.notok (i3.range.ended (), "i3 range not ended");
results = collapse (i3, exclusions);
t.ok (results.size () == 2, "splitInterval --> 2 fragments");
t.is (results[0].range.start.toISO (), "20160427T160000Z", "splitInterval --> results[0].range.start 20160427T160000Z");
t.is (results[0].range.end.toISO (), "20160427T173000Z", "splitInterval --> results[0].range.end 20160427T173000Z");
return 0;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -31,7 +31,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int, char**) int main (int, char**)
{ {
UnitTest t (76); UnitTest t (61);
// int quantizeTo15Minutes (const int); // int quantizeTo15Minutes (const int);
t.is (quantizeTo15Minutes (0), 0, "quantizeTo15Minutes 0 --> 0"); t.is (quantizeTo15Minutes (0), 0, "quantizeTo15Minutes 0 --> 0");
@ -96,44 +96,6 @@ int main (int, char**)
t.is (quantizeTo15Minutes (59), 60, "quantizeTo15Minutes 59 --> 60"); t.is (quantizeTo15Minutes (59), 60, "quantizeTo15Minutes 59 --> 60");
t.is (quantizeTo15Minutes (60), 60, "quantizeTo15Minutes 60 --> 60"); t.is (quantizeTo15Minutes (60), 60, "quantizeTo15Minutes 60 --> 60");
// std::vector <Interval> splitInterval (const Interval&, std::vector <Range>&);
Interval i1;
i1.range = Range (Datetime ("20160427T000000Z"), Datetime ("20160428T000000Z"));
i1.tag ("foo");
std::vector <Range> exclusions = {Range (Datetime ("20160427T000000Z"), Datetime ("20160427T080000Z")),
Range (Datetime ("20160427T120000Z"), Datetime ("20160427T130000Z")),
Range (Datetime ("20160427T173000Z"), Datetime ("20160428T000000Z"))};
auto results = splitInterval (i1, exclusions);
t.ok (results.size () == 2, "splitInterval --> 2 fragments");
t.is (results[0].range.start.toISO (), "20160427T080000Z", "splitInterval --> results[0].range.start 20160427T080000Z");
t.is (results[0].range.end.toISO (), "20160427T120000Z", "splitInterval --> results[0].range.end 20160427T120000Z");
t.is (results[1].range.start.toISO (), "20160427T130000Z", "splitInterval --> results[1].range.start 20160427T130000Z");
t.is (results[1].range.end.toISO (), "20160427T173000Z", "splitInterval --> results[1].range.end 20160427T173000Z");
Interval i2;
i2.range = Range (Datetime ("20160427T115500Z"), Datetime ("20160427T130500Z"));
i2.tag ("foo");
results = splitInterval (i2, exclusions);
t.ok (results.size () == 2, "splitInterval --> 2 fragments");
t.is (results[0].range.start.toISO (), "20160427T115500Z", "splitInterval --> results[0].range.start 20160427T115500Z");
t.is (results[0].range.end.toISO (), "20160427T120000Z", "splitInterval --> results[0].range.end 20160427T120000Z");
t.is (results[1].range.start.toISO (), "20160427T130000Z", "splitInterval --> results[1].range.start 20160427T130000Z");
t.is (results[1].range.end.toISO (), "20160427T130500Z", "splitInterval --> results[1].range.end 20160427T130500Z");
Interval i3;
i3.range = Range (Datetime ("20160427T160000Z"), Datetime (0));
i3.tag ("foo");
t.ok (i3.range.started (), "i3 range started");
t.notok (i3.range.ended (), "i3 range not ended");
results = splitInterval (i3, exclusions);
t.ok (results.size () == 2, "splitInterval --> 2 fragments");
t.is (results[0].range.start.toISO (), "20160427T160000Z", "splitInterval --> results[0].range.start 20160427T160000Z");
t.is (results[0].range.end.toISO (), "20160427T173000Z", "splitInterval --> results[0].range.end 20160427T173000Z");
return 0; return 0;
} }