Skip to content

Commit

Permalink
Fix backoff reunification test: use BOOST_CHECK instead of throws, us…
Browse files Browse the repository at this point in the history
…e negative log probabilities to evade cap.
  • Loading branch information
kpu committed Mar 14, 2016
1 parent 94fbc88 commit 9cc5ef5
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions lm/interpolate/backoff_reunification_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ struct Grams {

template <>
const Gram<1> Grams<1>::grams[]
= {{{0}, 0.1f, 0.1f}, {{1}, 0.4f, 0.2f}, {{2}, 0.5f, 0.1f}};
= {{{0}, -0.1f, -0.1f}, {{1}, -0.4f, -0.2f}, {{2}, -0.5f, -0.1f}};

template <>
const Gram<2> Grams<2>::grams[] = {{{0, 0}, 0.05f, 0.05f},
{{1, 0}, 0.05f, 0.02f},
{{1, 1}, 0.2f, 0.04f},
{{2, 2}, 0.2f, 0.01f}};
const Gram<2> Grams<2>::grams[] = {{{0, 0}, -0.05f, -0.05f},
{{1, 0}, -0.05f, -0.02f},
{{1, 1}, -0.2f, -0.04f},
{{2, 2}, -0.2f, -0.01f}};

template <>
const Gram<3> Grams<3>::grams[] = {{{0, 0, 0}, 0.001f, 0.005f},
{{1, 0, 0}, 0.001f, 0.002f},
{{2, 0, 0}, 0.001f, 0.003f},
{{0, 1, 0}, 0.1f, 0.008f},
{{1, 1, 0}, 0.1f, 0.09f},
{{1, 1, 1}, 0.2f, 0.08f}};
const Gram<3> Grams<3>::grams[] = {{{0, 0, 0}, -0.001f, -0.005f},
{{1, 0, 0}, -0.001f, -0.002f},
{{2, 0, 0}, -0.001f, -0.003f},
{{0, 1, 0}, -0.1f, -0.008f},
{{1, 1, 0}, -0.1f, -0.09f},
{{1, 1, 1}, -0.2f, -0.08f}};

template <uint8_t N>
class WriteInput {
Expand Down Expand Up @@ -83,25 +83,24 @@ class CheckOutput {
for (WordIndex *idx = stream->begin(); idx != stream->end(); ++idx)
ss << "(" << *idx << ")";

UTIL_THROW_IF2(
!std::equal(stream->begin(), stream->end(), Grams<N>::grams[i].ids),
"Mismatched id in CheckOutput<" << (int)N << ">: " << ss.str());
BOOST_CHECK(std::equal(stream->begin(), stream->end(), Grams<N>::grams[i].ids));
//"Mismatched id in CheckOutput<" << (int)N << ">: " << ss.str();

UTIL_THROW_IF2(stream->Value().prob != Grams<N>::grams[i].prob,
"Mismatched probability in CheckOutput<"
BOOST_CHECK_EQUAL(stream->Value().prob, Grams<N>::grams[i].prob);
/* "Mismatched probability in CheckOutput<"
<< (int)N << ">, got " << stream->Value().prob
<< ", expected " << Grams<N>::grams[i].prob);
<< ", expected " << Grams<N>::grams[i].prob;*/

UTIL_THROW_IF2(stream->Value().backoff != Grams<N>::grams[i].boff,
"Mismatched backoff in CheckOutput<"
BOOST_CHECK_EQUAL(stream->Value().backoff, Grams<N>::grams[i].boff);
/* "Mismatched backoff in CheckOutput<"
<< (int)N << ">, got " << stream->Value().backoff
<< ", expected " << Grams<N>::grams[i].boff);
<< ", expected " << Grams<N>::grams[i].boff);*/
}
UTIL_THROW_IF2(i != sizeof(Grams<N>::grams) / sizeof(Gram<N>),
"Did not get correct number of "
BOOST_CHECK_EQUAL(i , sizeof(Grams<N>::grams) / sizeof(Gram<N>));
/* "Did not get correct number of "
<< (int)N << "-grams: expected "
<< sizeof(Grams<N>::grams) / sizeof(Gram<N>)
<< ", got " << i);
<< ", got " << i;*/
}
};
}
Expand Down

0 comments on commit 9cc5ef5

Please sign in to comment.