implement utils::current_date() convenience function to reduce replicated code

This commit is contained in:
Axel Kohlmeyer
2021-09-18 09:05:35 -04:00
parent 5a6c1abeed
commit db76edbade
9 changed files with 64 additions and 49 deletions

View File

@ -14,8 +14,11 @@
#include "lmptype.h"
#include "pointers.h"
#include "utils.h"
#include "tokenizer.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cerrno>
#include <cstdio>
#include <string>
@ -875,6 +878,19 @@ TEST(Utils, date2num)
ASSERT_EQ(utils::date2num("31December100"), 1001231);
}
TEST(Utils, current_date)
{
auto vals = ValueTokenizer(utils::current_date(),"-");
int year = vals.next_int();
int month = vals.next_int();
int day = vals.next_int();
ASSERT_GT(year,2020);
ASSERT_GE(month,1);
ASSERT_GE(day,1);
ASSERT_LE(month,12);
ASSERT_LE(day,31);
}
TEST(Utils, binary_search)
{
double data[] = {-2.0, -1.8, -1.0, -1.0, -1.0, -0.5, -0.2, 0.0, 0.1, 0.1,