Skip to content

Commit

Permalink
fix braindamage
Browse files Browse the repository at this point in the history
  • Loading branch information
CppPhil committed Oct 7, 2020
1 parent af27e94 commit 17eebfe
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 12 deletions.
2 changes: 1 addition & 1 deletion compare_segmentation.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

catch_errors() {
printf "\nfix_csvs.sh failed!\n" >&2
printf "\ncompare_segmentation.sh failed!\n" >&2
exit 1
}

Expand Down
2 changes: 1 addition & 1 deletion compare_segmentation/src/log_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ cl::Expected<LogInfo> LogInfo::create(cl::fs::Path logFilePath) noexcept

constexpr std::size_t filterIndex{6}; // Only used by the new ones.

static const std::regex regularExpression{regularExpressionString};
const std::regex regularExpression{regularExpressionString};

std::cmatch cmatch{};

Expand Down
36 changes: 29 additions & 7 deletions compare_segmentation/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <fmt/ostream.h>

#include "log_files.hpp"
#include "log_info.hpp"
#include "paths.hpp"

int main()
Expand Down Expand Up @@ -36,16 +37,37 @@ int main()

const std::vector<cl::fs::Path>& oldLogs{*expectedOldLogs};

// TODO: HERE: this will change BEGIN
fmt::print("logs:\n");
for (const cl::fs::Path& preprocessedPath : logs) {
const cl::Expected<cs::LogInfo> expectedLogInfo{
cs::LogInfo::create(preprocessedPath)};

for (const cl::fs::Path& path : logs) { fmt::print("{}\n", path); }
if (!expectedLogInfo.has_value()) {
fmt::print(
stderr,
"Couldn't fetch LogInfo for preprocessedPath: {}\n",
expectedLogInfo.error());
return EXIT_FAILURE;
}

fmt::print("\n");
fmt::print("old logs:\n");
// TODO: HERE
[[maybe_unused]] const cs::LogInfo& logInfo{*expectedLogInfo};
}

for (const cl::fs::Path& oldPath : oldLogs) {
const cl::Expected<cs::LogInfo> expectedLogInfo{
cs::LogInfo::create(oldPath)};

for (const cl::fs::Path& path : oldLogs) { fmt::print("{}\n", path); }
// TODO: HERE: this will change END
if (!expectedLogInfo.has_value()) {
fmt::print(
stderr,
"Couldn't fetch LogInfo for oldPath: {}\n",
expectedLogInfo.error());
return EXIT_FAILURE;
}

// TODO: HERE
[[maybe_unused]] const cs::LogInfo& logInfo{*expectedLogInfo};
}

return EXIT_SUCCESS;
}
26 changes: 26 additions & 0 deletions compare_segmentation/test/log_info_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,32 @@ TEST(LogInfo, shouldWorkWithOldPath)
EXPECT_EQ(cs::FilterKind::MovingAverage, logInfo.filterKind());
}

TEST(LogInfo, shouldWorkWithOldPath2)
{
using namespace pl::literals::integer_literals;

const std::string path{
"segmentation_comparison/logs/old/"
"skip_window-false_delete_too_close-false_delete_low_variance-false_sensor-"
"769_kind-both_window-101.log"};

const cl::Expected<cs::LogInfo> expected{cs::LogInfo::create(path)};

ASSERT_TRUE(expected.has_value());

const cs::LogInfo& logInfo{*expected};

EXPECT_EQ(path, logInfo.logFilePath());
EXPECT_FALSE(logInfo.skipWindow());
EXPECT_FALSE(logInfo.deleteTooClose());
EXPECT_FALSE(logInfo.deleteLowVariance());
EXPECT_EQ(UINT64_C(769), logInfo.sensor());
EXPECT_EQ(cs::SegmentationKind::Both, logInfo.segmentationKind());
EXPECT_EQ(101_zu, logInfo.windowSize());

EXPECT_EQ(cs::FilterKind::MovingAverage, logInfo.filterKind());
}

TEST(logInfo, shouldResultInErrorIfLogFilePathIsTooShort)
{
const cl::Expected<cs::LogInfo> expected{cs::LogInfo::create(
Expand Down
7 changes: 6 additions & 1 deletion csv_lib/src/cl/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ inline pl::string_view kind_to_string(Error::Kind kind)
std::ostream& operator<<(std::ostream& os, const Error& error)
{
return os << fmt::format(
R"(Error{{"kind": "{}", "file": "{}", "function": "{}", "line": {}, "message": "{}"}})",
R"(Error{{
"kind": "{}",
"file": "{}",
"function": "{}",
"line": {},
"message": "{}"}})",
kind_to_string(error.kind()),
error.file(),
error.function(),
Expand Down
7 changes: 6 additions & 1 deletion csv_lib/test/error_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ TEST(error, shouldPrint)
std::ostringstream oss{};
oss << error;
const std::string expected{
R"(Error{"kind": "Filesystem", "file": "test_file.cpp", "function": "bad_function", "line": 48, "message": "Couldn't initialize the flux capacitor."})"};
R"(Error{
"kind": "Filesystem",
"file": "test_file.cpp",
"function": "bad_function",
"line": 48,
"message": "Couldn't initialize the flux capacitor."})"};
const std::string actual{oss.str()};
EXPECT_EQ(expected, actual);
}
Expand Down
7 changes: 6 additions & 1 deletion csv_lib/test/to_string_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ TEST(to_string, test)
R"(DataPoint{"fileName": "test.csv", time": 50.5, "sensor": "LeftArm", "channel": "AccelerometerZ", "value": 25.1123})",
cl::to_string(dataPoint));
EXPECT_EQ(
R"(Error{"kind": "Filesystem", "file": "test_file.cpp", "function": "a_function", "line": 5, "message": "Error message."})",
R"(Error{
"kind": "Filesystem",
"file": "test_file.cpp",
"function": "a_function",
"line": 5,
"message": "Error message."})",
cl::to_string(error));
EXPECT_EQ("RightArm", cl::to_string(sensor));
}

0 comments on commit 17eebfe

Please sign in to comment.