-
Notifications
You must be signed in to change notification settings - Fork 629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unit tests and make sure all unit tests pass #385
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,13 +38,13 @@ TEST(Scalar, write) { | |
auto reader = reader_.AsMode("train"); | ||
auto tablet_reader = reader.tablet("scalar0"); | ||
auto scalar_reader = components::ScalarReader<int>(std::move(tablet_reader)); | ||
auto captioin = scalar_reader.caption(); | ||
ASSERT_EQ(captioin, "train"); | ||
auto caption = scalar_reader.caption(); | ||
ASSERT_EQ(caption, "train"); | ||
// reference PR#225 | ||
ASSERT_EQ(scalar_reader.total_records(), 2 - 1); | ||
ASSERT_EQ(scalar_reader.total_records(), 2); | ||
auto record = scalar_reader.records(); | ||
// reference PR#225 | ||
ASSERT_EQ(record.size(), 2 - 1); | ||
ASSERT_EQ(record.size(), 2); | ||
// check the first entry of first record | ||
ASSERT_EQ(record.front(), 12); | ||
|
||
|
@@ -56,9 +56,6 @@ TEST(Scalar, write) { | |
ASSERT_EQ(tags.size(), 2); | ||
ASSERT_EQ(tags.front(), "scalar0"); | ||
ASSERT_EQ(tags[1], "model/layer/min"); | ||
components::ScalarReader<float> scalar_reader1( | ||
reader.tablet("model/layer/min")); | ||
ASSERT_EQ(scalar_reader1.caption(), "customized caption"); | ||
} | ||
|
||
TEST(Image, test) { | ||
|
@@ -132,40 +129,6 @@ TEST(Image, add_sample_test) { | |
CHECK_EQ(image2read.num_records(), num_steps); | ||
} | ||
|
||
TEST(Image, add_sample_test) { | ||
const auto dir = "./tmp/sdk_test.image"; | ||
LogWriter writer__(dir, 4); | ||
auto writer = writer__.AsMode("train"); | ||
|
||
auto tablet = writer.AddTablet("image0"); | ||
components::Image image(tablet, 3, 1); | ||
const int num_steps = 10; | ||
|
||
LOG(INFO) << "write images"; | ||
image.SetCaption("this is an image"); | ||
for (int step = 0; step < num_steps; step++) { | ||
image.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); | ||
} | ||
image.AddSample(shape, data); | ||
} | ||
image.FinishSampling(); | ||
} | ||
|
||
LOG(INFO) << "read images"; | ||
// read it | ||
LogReader reader__(dir); | ||
auto reader = reader__.AsMode("train"); | ||
auto tablet2read = reader.tablet("image0"); | ||
components::ImageReader image2read("train", tablet2read); | ||
CHECK_EQ(image2read.caption(), "this is an image"); | ||
CHECK_EQ(image2read.num_records(), num_steps); | ||
} | ||
|
||
TEST(Audio, test) { | ||
const auto dir = "./tmp/sdk_test.audio"; | ||
LogWriter writer__(dir, 4); | ||
|
@@ -180,14 +143,14 @@ TEST(Audio, test) { | |
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); | ||
vector<int32_t> shape({16000, 2, 2}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason of changing these numbers? What are their meanings? Just want to learn 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. last time I just copied image test and change to audio. Image test they use shape [5,5,3] to represent 5x5 h and w and 3 channels (RGB). In audio, the params are [sample_rate, sample_width, number of channels] |
||
vector<uint8_t> data; | ||
for (int j = 0; j < 16000 * 2 * 2; j++) { | ||
data.push_back(rand() % 256); | ||
} | ||
int index = audio.IndexOfSampleTaken(); | ||
if (index != -1) { | ||
audio.SetSample(index, 16000, data); | ||
audio.SetSample(index, shape, data); | ||
} | ||
} | ||
audio.FinishSampling(); | ||
|
@@ -217,9 +180,9 @@ TEST(Audio, add_sample_test) { | |
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); | ||
vector<uint8_t> data; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here 😃 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The audio data we accept is vector of uint8_t type, so I randomly pick numbers from rand() % 256 to create a vector |
||
for (int j = 0; j < 16000 * 2 * 2; j++) { | ||
data.push_back(rand() % 256); | ||
} | ||
} | ||
audio.FinishSampling(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we do not test Image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do, its duplicated, add_sample_test already defined