Skip to content

Commit 4145e17

Browse files
committed
fix tests and address comments
1 parent ed29e16 commit 4145e17

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

src/util/kaldi-table-test.cc

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ void UnitTestTableSequentialInt32(bool binary) {
351351
k2.push_back(sbr.Key());
352352
v2.push_back(sbr.Value());
353353
}
354-
KALDI_ASSERT(sbr.Close());
354+
ans = sbr.Close();
355+
KALDI_ASSERT(ans);
355356
KALDI_ASSERT(k2 == k);
356357
KALDI_ASSERT(v2 == v);
357358
}
@@ -384,7 +385,8 @@ void UnitTestTableSequentialBool(bool binary) {
384385
k2.push_back(sbr.Key());
385386
v2.push_back(sbr.Value());
386387
}
387-
KALDI_ASSERT(sbr.Close());
388+
ans = sbr.Close();
389+
KALDI_ASSERT(ans);
388390
KALDI_ASSERT(k2 == k);
389391
KALDI_ASSERT(v2 == v);
390392
}
@@ -418,7 +420,8 @@ void UnitTestTableSequentialDouble(bool binary) {
418420
k2.push_back(sbr.Key());
419421
v2.push_back(sbr.Value());
420422
}
421-
KALDI_ASSERT(sbr.Close());
423+
ans = sbr.Close();
424+
KALDI_ASSERT(ans);
422425
KALDI_ASSERT(k2 == k);
423426
if (binary) {
424427
KALDI_ASSERT(v2 == v);
@@ -462,7 +465,8 @@ void UnitTestTableSequentialDoubleBoth(bool binary, bool read_scp) {
462465
k2.push_back(sbr.Key());
463466
v2.push_back(sbr.Value());
464467
}
465-
KALDI_ASSERT(sbr.Close());
468+
ans = sbr.Close();
469+
KALDI_ASSERT(ans);
466470
KALDI_ASSERT(k2 == k);
467471
if (binary) {
468472
KALDI_ASSERT(v2 == v);
@@ -511,7 +515,8 @@ void UnitTestTableSequentialInt32VectorBoth(bool binary, bool read_scp) {
511515
k2.push_back(sbr.Key());
512516
v2.push_back(sbr.Value());
513517
}
514-
KALDI_ASSERT(sbr.Close());
518+
ans = sbr.Close();
519+
KALDI_ASSERT(ans);
515520
KALDI_ASSERT(k2 == k);
516521
KALDI_ASSERT(v2 == v);
517522
}
@@ -551,7 +556,8 @@ void UnitTestTableSequentialInt32PairVectorBoth(bool binary, bool read_scp) {
551556
k2.push_back(sbr.Key());
552557
v2.push_back(sbr.Value());
553558
}
554-
KALDI_ASSERT(sbr.Close());
559+
ans = sbr.Close();
560+
KALDI_ASSERT(ans);
555561
KALDI_ASSERT(k2 == k);
556562
KALDI_ASSERT(v2 == v);
557563
}
@@ -594,7 +600,8 @@ void UnitTestTableSequentialInt32VectorVectorBoth(bool binary, bool read_scp) {
594600
k2.push_back(sbr.Key());
595601
v2.push_back(sbr.Value());
596602
}
597-
KALDI_ASSERT(sbr.Close());
603+
ans = sbr.Close();
604+
KALDI_ASSERT(ans);
598605
KALDI_ASSERT(k2 == k);
599606
KALDI_ASSERT(v2 == v);
600607
}
@@ -641,7 +648,8 @@ void UnitTestTableSequentialInt32Script(bool binary) {
641648
k2.push_back(sbr.Key());
642649
v2.push_back(sbr.Value());
643650
}
644-
KALDI_ASSERT(sbr.Close());
651+
ans = sbr.Close();
652+
KALDI_ASSERT(ans);
645653

646654
unlink("tmp.scp");
647655
for (size_t i = 0; i < script.size(); i++) {
@@ -684,7 +692,8 @@ void UnitTestTableSequentialDoubleMatrixBoth(bool binary, bool read_scp) {
684692
k2.push_back(sbr.Key());
685693
v2.push_back(new Matrix<double>(sbr.Value()));
686694
}
687-
KALDI_ASSERT(sbr.Close());
695+
ans = sbr.Close();
696+
KALDI_ASSERT(ans);
688697
KALDI_ASSERT(k2 == k);
689698
if (binary) {
690699
for (size_t i = 0; i < v2.size(); i++)
@@ -738,7 +747,8 @@ void UnitTestTableSequentialBaseFloatVectorBoth(bool binary, bool read_scp) {
738747
k2.push_back(sbr.Key());
739748
v2.push_back(new Vector<BaseFloat>(sbr.Value()));
740749
}
741-
KALDI_ASSERT(sbr.Close());
750+
ans = sbr.Close();
751+
KALDI_ASSERT(ans);
742752
KALDI_ASSERT(k2 == k);
743753
if (binary) {
744754
for (size_t i = 0; i < v2.size(); i++)
@@ -831,10 +841,11 @@ void UnitTestTableRandomBothDouble(bool binary, bool read_scp,
831841
bool ans = sbr.HasKey(cur_key);
832842
KALDI_ASSERT(ans == true);
833843
}
844+
auto v2 = sbr.Value(cur_key);
834845
if (binary) {
835-
KALDI_ASSERT(value == sbr.Value(cur_key));
846+
KALDI_ASSERT(value == v2);
836847
} else {
837-
KALDI_ASSERT(ApproxEqual(value, sbr.Value(cur_key)));
848+
KALDI_ASSERT(ApproxEqual(value, v2));
838849
}
839850
}
840851
}
@@ -1039,10 +1050,11 @@ void UnitTestTableRandomBothDoubleMatrix(bool binary, bool read_scp,
10391050
bool ans = sbr.HasKey(cur_key);
10401051
KALDI_ASSERT(ans == true);
10411052
}
1053+
auto v2 = sbr.Value(cur_key);
10421054
if (binary) {
1043-
KALDI_ASSERT(value_ptr->ApproxEqual(sbr.Value(cur_key), 1.0e-10));
1055+
KALDI_ASSERT(value_ptr->ApproxEqual(v2, 1.0e-10));
10441056
} else {
1045-
KALDI_ASSERT(value_ptr->ApproxEqual(sbr.Value(cur_key), 0.01));
1057+
KALDI_ASSERT(value_ptr->ApproxEqual(v2, 0.01));
10461058
}
10471059
}
10481060
}

src/util/parse-options-test.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void UnitTestParseOptions() {
120120
po4.Register("option", &val, "My boolean");
121121
po4.Read(argc4, argv4);
122122
assert(false); // Should not reach this part of code.
123-
} catch(std::exception &e) {
123+
} catch(const std::exception &e) {
124124
KALDI_LOG << "Failed to read option (this is expected).";
125125
}
126126

@@ -144,7 +144,7 @@ void UnitTestParseOptions() {
144144
po4.Register("option", &val, "My string");
145145
po4.Read(argc4, argv4);
146146
assert(false); // Should not reach this part of code.
147-
} catch(std::exception &e) {
147+
} catch(const std::exception &e) {
148148
KALDI_LOG << "Failed to read option (this is expected).";
149149
}
150150

@@ -195,7 +195,7 @@ void UnitTestParseOptions() {
195195
po4.Register("option", &val, "My float");
196196
po4.Read(argc4, argv4);
197197
assert(false); // Should not reach this part of code.
198-
} catch(std::exception &e) {
198+
} catch(const std::exception &e) {
199199
KALDI_LOG << "Failed to read option (this is expected).";
200200
}
201201

@@ -208,7 +208,7 @@ void UnitTestParseOptions() {
208208
po4.Register("option", &val, "My int");
209209
po4.Read(argc4, argv4);
210210
assert(false); // Should not reach this part of code.
211-
} catch(std::exception &e) {
211+
} catch(const std::exception &e) {
212212
KALDI_LOG << "Failed to read option (this is expected).";
213213
}
214214

@@ -220,7 +220,7 @@ void UnitTestParseOptions() {
220220
po4.Register("option", &val, "My int");
221221
po4.Read(argc4, argv4);
222222
assert(false); // Should not reach this part of code.
223-
} catch(std::exception &e) {
223+
} catch(const std::exception &e) {
224224
KALDI_LOG << "Failed to read option (this is expected).";
225225
}
226226

@@ -232,7 +232,7 @@ void UnitTestParseOptions() {
232232
po4.Register("option", &val, "My int");
233233
po4.Read(argc4, argv4);
234234
assert(false); // Should not reach this part of code.
235-
} catch(std::exception &e) {
235+
} catch(const std::exception &e) {
236236
KALDI_LOG << "Failed to read option (this is expected)xxx.";
237237
}
238238

@@ -244,7 +244,7 @@ void UnitTestParseOptions() {
244244
po4.Register("option", &val, "My bool");
245245
po4.Read(argc4, argv4);
246246
assert(false); // Should not reach this part of code.
247-
} catch(std::exception &e) {
247+
} catch(const std::exception &e) {
248248
KALDI_LOG << "Failed to read option (this is expected).";
249249
}
250250

@@ -258,7 +258,7 @@ void UnitTestParseOptions() {
258258
po4.Register("num", &num, "My int32 variable");
259259
po4.Read(argc4, argv4);
260260
KALDI_ASSERT(num == 0);
261-
} catch(std::exception &e) {
261+
} catch(const std::exception &e) {
262262
KALDI_LOG << "Failed to read option (this is expected).";
263263
}
264264

src/util/stl-utils-test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ void TestCopyMapValuesToVector() {
148148
CopyMapValuesToVector(mp, &v);
149149
KALDI_ASSERT(mp.size() == v.size());
150150
int i = 0;
151-
for (std::map<int, int>::iterator iter = mp.begin(); iter != mp.end();
152-
iter++) {
153-
KALDI_ASSERT(v[i++] == iter->second);
151+
for (auto iter = mp.begin(); iter != mp.end();
152+
iter++, i++) {
153+
KALDI_ASSERT(v[i] == iter->second);
154154
}
155155
}
156156
}

0 commit comments

Comments
 (0)