sdk_test.cc 878 字节
Newer Older
S
Superjom 已提交
1 2 3 4 5 6
#include "visualdl/logic/sdk.h"

#include <gtest/gtest.h>

namespace visualdl {

S
superjom 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
TEST(Scalar, write) {
  const auto dir = "./tmp/sdk_test";
  Storage storage;
  // write disk every time
  storage.meta.cycle = 1;
  storage.SetDir(dir);
  auto tablet = storage.AddTablet("scalar0");
  components::Scalar<int> scalar(tablet);
  scalar.SetCaption("train");
  scalar.AddRecord(0, std::vector<int>({12}));

  // read from disk
  StorageReader reader(dir);
  auto scalar_reader = reader.tablet("scalar0");
  auto captioins = scalar_reader.captions();
  ASSERT_EQ(captioins.size(), 1);
  ASSERT_EQ(captioins.front(), "train");
  ASSERT_EQ(scalar_reader.total_records(), 1);
  auto record = scalar_reader.record(0);
  // check the first entry of first record
  auto vs = record.data<int>(0).GetMulti();
  ASSERT_EQ(vs.size(), 1);
  ASSERT_EQ(vs.front(), 12);
S
superjom 已提交
30 31
}

S
Superjom 已提交
32
}  // namespace visualdl