From 3dcf637b37d8c821cd1ec0d537059ee18af53cf2 Mon Sep 17 00:00:00 2001 From: Superjom Date: Sat, 16 Dec 2017 19:45:44 +0800 Subject: [PATCH] add sdk test --- visualdl/logic/sdk_test.cc | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 visualdl/logic/sdk_test.cc diff --git a/visualdl/logic/sdk_test.cc b/visualdl/logic/sdk_test.cc new file mode 100644 index 00000000..5f204095 --- /dev/null +++ b/visualdl/logic/sdk_test.cc @@ -0,0 +1,78 @@ +#include "visualdl/logic/sdk.h" + +#include + +namespace visualdl { + +struct ScalarTestHelper { + ImHelper rim; + ImHelper wim; + const std::string dir = "./tmp/1.test"; + + void operator()(std::function read, std::function write) { + wim.StartWriteSerice(dir, 200); + write(); + + rim.StartReadService(dir, 200); + std::this_thread::sleep_for(std::chrono::milliseconds(600)); + read(); + } +}; + +TEST(Scalar, set_caption) { + ScalarTestHelper helper; + + const std::vector captions({"train", "test"}); + + auto write = [&] { + auto tablet = helper.wim.AddTablet("tag0", -1); + components::ScalarHelper scalar(tablet, &helper.wim.handler()); + + scalar.SetCaptions(captions); + }; + + auto read = [&] { + auto mytablet = helper.rim.tablet("tag0"); + components::ScalarHelper myscalar(mytablet, &helper.rim.handler()); + auto mycaptions = myscalar.GetCaptions(); + + ASSERT_EQ(captions, mycaptions); + }; + + helper(read, write); +} + +TEST(Scalar, add_records) { + ScalarTestHelper helper; + + const std::vector captions({"train", "test"}); + + const size_t nsteps = 100; + + auto write = [&] { + auto tablet = helper.wim.AddTablet("tag0", -1); + components::ScalarHelper scalar(tablet, &helper.wim.handler()); + + scalar.SetCaptions(captions); + + for (int i = 0; i < nsteps; i++) { + scalar.AddRecord(i * 10, std::vector({(float)i, (float)i + 1})); + } + }; + + auto read = [&] { + auto mytablet = helper.rim.tablet("tag0"); + components::ScalarHelper myscalar(mytablet, &helper.rim.handler()); + + auto records = myscalar.GetRecords(); + ASSERT_EQ(records.size(), nsteps); + + for (int i = 0; i < nsteps; i++) { + ASSERT_EQ(records[i], std::vector({(float)i, (float)i + 1})); + } + }; + + helper(read, write); +} + +} // namespace visualdl -- GitLab