6 #ifndef FST_TEST_FST_TEST_H_ 7 #define FST_TEST_FST_TEST_H_ 29 typedef typename F::Arc
Arc;
32 typedef typename Arc::Label
Label;
37 testfst_ =
new F(vfst);
40 explicit FstTester(F *testfst) : testfst_(testfst) {}
54 for (; !siter.
Done(); siter.
Next()) {
57 StateId s = siter.
Value();
59 CHECK_EQ(fst.Final(s), NthWeight(s));
62 for (; !aiter.
Done(); aiter.
Next()) {
66 const Arc &arc = aiter.
Value();
79 CHECK_EQ(fst.NumInputEpsilons(s), 0);
80 CHECK_EQ(fst.NumOutputEpsilons(s), s);
110 StateId s = siter.Value();
112 size_t ni = fst->NumInputEpsilons(s);
114 for (; !aiter.
Done(); aiter.
Next()) {
118 Arc arc = aiter.
Value();
123 CHECK_EQ(fst->NumInputEpsilons(s), ni + 1);
126 CHECK_EQ(fst->NumInputEpsilons(s), ni);
130 G *cfst1 = fst->Copy();
131 cfst1->DeleteStates();
135 G *cfst2 = fst->Copy();
137 StateId s = siter.Value();
138 cfst2->DeleteArcs(s);
140 CHECK_EQ(cfst2->NumInputEpsilons(s), 0);
141 CHECK_EQ(cfst2->NumOutputEpsilons(s), 0);
158 afst2 = *
static_cast<const Fst<Arc> *
>(fst);
162 afst2.operator=(afst2);
176 const G c2fst(
static_cast<const Fst<Arc> &
>(fst));
180 const G *c3fst = fst.Copy();
190 const string filename = FLAGS_tmpdir +
"/test.fst";
191 const string aligned = FLAGS_tmpdir +
"/aligned.fst";
194 CHECK(fst.Write(filename));
195 G *ffst = G::Read(filename);
205 G *dfst =
static_cast<G *
>(gfst);
220 std::ofstream ostr(aligned);
224 CHECK(fst.Write(ostr, opts));
226 std::ifstream istr(aligned);
230 G *gfst = G::Read(istr, opts);
239 std::ofstream ostr(aligned);
243 CHECK(fst.Write(ostr, opts));
245 std::ifstream istr(aligned);
249 G *gfst = G::Read(istr, opts);
265 if (fst.Properties(
kMutable,
false)) {
294 for (StateId s = 0; s < nstates; ++s) {
297 for (
size_t i = 1; i <= s; ++i) {
298 Arc arc(i, 0, NthWeight(i), s);
307 Weight NthWeight(
int n)
const {
308 Weight w = Weight::Zero();
309 for (
int i = 0; i < n; ++i) w =
Plus(w, Weight::One());
318 #endif // FST_TEST_FST_TEST_H_ void TestExpanded(const G &fst) const
MatchType Type(bool test) const
void TestAssign(G *fst) const
void TestIO(const G &fst) const
virtual void AddArc(StateId, const Arc &arc)=0
virtual bool Write(std::ostream &strm, const FstWriteOptions &opts) const
virtual void SetStart(StateId)=0
void SetValue(const Arc &arc)
constexpr uint64 kExpanded
const Arc & Value() const
static Fst< Arc > * Read(std::istream &strm, const FstReadOptions &opts)
const Arc & Value() const
void TestCopy(const G &fst) const
virtual void SetFinal(StateId, Weight)=0
static FileReadMode ReadMode(const string &mode)
void TestExpanded() const
ExpectationWeight< X1, X2 > Plus(const ExpectationWeight< X1, X2 > &w1, const ExpectationWeight< X1, X2 > &w2)
static ExpandedFst< Arc > * Read(std::istream &strm, const FstReadOptions &opts)
bool Verify(const Fst< Arc > &fst, bool allow_negative_labels=false)
constexpr uint64 kNotAcceptor
void TestMutable(G *fst) const
virtual StateId AddState()=0
bool Equal(const Fst< Arc > &fst1, const Fst< Arc > &fst2, WeightEqual weight_equal, uint32 etype=kEqualFsts)
virtual void DeleteStates(const std::vector< StateId > &)=0
const Arc & Value() const
static MutableFst< Arc > * Read(std::istream &strm, const FstReadOptions &opts)
void TestBase(const G &fst) const
constexpr uint64 kMutable
constexpr uint64 kOEpsilons