← source index

test/HelperTest.cpp

57 lines  ·  1.3 K  ·  cpp
#include <iostream>
#include <fstream>
#include <catch_amalgamated.hpp>
#include <boost/algorithm/string.hpp>

#include "../src/Helper.h"

TEST_CASE("Helper.h -> timestamp parser")
{
    std::string line;
    std::ifstream file("test_data/HelperTest-ts.testdata");

    REQUIRE(file.good() == true);

    while (getline (file, line))
    {
        std::vector<std::string> strs;
        boost::split(strs, line, boost::is_any_of(" "));
        std::string ts = strs[0];
        int64_t ns = std::stoll(strs[1]);
        int64_t testNs1 = Helper::parseTsNs(ts);
        int64_t testNs2 = Helper::parseTsNs(ts, 1000LL);
        CHECK(testNs1 == ns);
        CHECK(testNs2 == ns);
        char buf[32];
        Helper::parseNsTs(ns, buf);
        CHECK(ts == buf);
    }

    file.close();
}

TEST_CASE("Helper.h -> price parser")
{
    std::string line;
    std::ifstream file("test_data/HelperTest-px.testdata");

    REQUIRE(file.good() == true);

    while (getline (file, line))
    {
        std::vector<std::string> strs;
        boost::split(strs, line, boost::is_any_of(" "));
        std::string rawPx = strs[0];
        int64_t px = std::stoll(strs[1]);

        int64_t parsePx = Helper::parseToPx(rawPx);
        CHECK(parsePx == px);

        char buf[32];
        Helper::parseFromPx(px, buf);
        CHECK(rawPx == buf);
    }

    file.close();
}