未验证 提交 f9de540b 编写于 作者: N Nicky Chan 提交者: GitHub

add sdk unit test for audio api (#349)

上级 39a95f5c
......@@ -80,7 +80,7 @@ TEST(Image, test) {
for (int j = 0; j < 3 * 5 * 5; j++) {
data.push_back(float(rand()) / RAND_MAX);
}
int index = image.IsSampleTaken();
int index = image.IndexOfSampleTaken();
if (index != -1) {
image.SetSample(index, shape, data);
}
......@@ -166,6 +166,75 @@ TEST(Image, add_sample_test) {
CHECK_EQ(image2read.num_records(), num_steps);
}
TEST(Audio, test) {
const auto dir = "./tmp/sdk_test.audio";
LogWriter writer__(dir, 4);
auto writer = writer__.AsMode("train");
auto tablet = writer.AddTablet("audio0");
components::Audio audio(tablet, 3, 1);
const int num_steps = 10;
LOG(INFO) << "write audio";
audio.SetCaption("this is an audio");
for (int step = 0; step < num_steps; step++) {
audio.StartSampling();
for (int i = 0; i < 7; i++) {
vector<int64_t> shape({5, 5, 3});
vector<float> data;
for (int j = 0; j < 3 * 5 * 5; j++) {
data.push_back(float(rand()) / RAND_MAX);
}
int index = audio.IndexOfSampleTaken();
if (index != -1) {
audio.SetSample(index, 16000, data);
}
}
audio.FinishSampling();
}
LOG(INFO) << "read audio";
// read it
LogReader reader__(dir);
auto reader = reader__.AsMode("train");
auto tablet2read = reader.tablet("audio0");
components::AudioReader audio2read("train", tablet2read);
CHECK_EQ(audio2read.caption(), "this is an audio");
CHECK_EQ(audio2read.num_records(), num_steps);
}
TEST(Audio, add_sample_test) {
const auto dir = "./tmp/sdk_test.audio";
LogWriter writer__(dir, 4);
auto writer = writer__.AsMode("train");
auto tablet = writer.AddTablet("audio0");
components::Audio audio(tablet, 3, 1);
const int num_steps = 10;
LOG(INFO) << "write audio";
audio.SetCaption("this is an audio");
for (int step = 0; step < num_steps; step++) {
audio.StartSampling();
for (int i = 0; i < 7; i++) {
vector<float> data;
for (int j = 0; j < 3 * 5 * 5; j++) {
data.push_back(float(rand()) / RAND_MAX);
}
}
audio.FinishSampling();
}
LOG(INFO) << "read audio";
// read it
LogReader reader__(dir);
auto reader = reader__.AsMode("train");
auto tablet2read = reader.tablet("audio0");
components::AudioReader audio2read("train", tablet2read);
CHECK_EQ(audio2read.caption(), "this is an audio");
CHECK_EQ(audio2read.num_records(), num_steps);
}
TEST(Histogram, AddRecord) {
const auto dir = "./tmp/sdk_test.histogram";
LogWriter writer__(dir, 1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册