diff options
author | Ian Hodson <idh@google.com> | 2012-05-30 21:27:06 +0100 |
---|---|---|
committer | Ian Hodson <idh@google.com> | 2012-05-30 22:47:36 +0100 |
commit | f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2 (patch) | |
tree | b131ed907f9b2d5af09c0983b651e9e69bc6aab9 /src/test/fst_test.cc | |
parent | a92766f0a6ba4fac46cd6fd3856ef20c3b204f0d (diff) | |
download | openfst-f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2.tar.gz |
Add openfst to external, as used by GoogleTTSandroid-sdk-support_r11android-cts-4.2_r2android-cts-4.2_r1android-cts-4.1_r4android-cts-4.1_r2android-cts-4.1_r1android-4.2_r1android-4.2.2_r1.2android-4.2.2_r1.1android-4.2.2_r1android-4.2.1_r1.2android-4.2.1_r1.1android-4.2.1_r1android-4.1.2_r2.1android-4.1.2_r2android-4.1.2_r1android-4.1.1_r6.1android-4.1.1_r6android-4.1.1_r5android-4.1.1_r4android-4.1.1_r3android-4.1.1_r2android-4.1.1_r1.1android-4.1.1_r1tools_r22tools_r21jb-releasejb-mr1.1-releasejb-mr1.1-dev-plus-aospjb-mr1.1-devjb-mr1-releasejb-mr1-dev-plus-aospjb-mr1-devjb-mr0-releasejb-dev
Moved from GoogleTTS
Change-Id: I6bc6bdadaa53bd0f810b88443339f6d899502cc8
Diffstat (limited to 'src/test/fst_test.cc')
-rw-r--r-- | src/test/fst_test.cc | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/src/test/fst_test.cc b/src/test/fst_test.cc new file mode 100644 index 0000000..7d8d600 --- /dev/null +++ b/src/test/fst_test.cc @@ -0,0 +1,228 @@ +// fst_test.cc + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Regression test for FST classes. + +#include "./fst_test.h" + +#include <fst/compact-fst.h> +#include <fst/const-fst.h> +#include <fst/edit-fst.h> +#include <fst/matcher-fst.h> + + +namespace fst { + +// A user-defined arc type. +struct CustomArc { + typedef short Label; + typedef ProductWeight<TropicalWeight, LogWeight> Weight; + typedef int64 StateId; + + CustomArc(Label i, Label o, Weight w, StateId s) : + ilabel(i), olabel(o), weight(w), nextstate(s) {} + CustomArc() {} + + static const string &Type() { // Arc type name + static const string type = "my"; + return type; + } + + Label ilabel; // Transition input label + Label olabel; // Transition output label + Weight weight; // Transition weight + StateId nextstate; // Transition destination state +}; + + +// A user-defined compactor for test FST. +template <class A> +class CustomCompactor { + public: + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + typedef pair<Label, Weight> Element; + + Element Compact(StateId s, const A &arc) const { + return make_pair(arc.ilabel, arc.weight); + } + + Arc Expand(StateId s, const Element &p, uint32 f = kArcValueFlags) const { + return p.first == kNoLabel ? + Arc(kNoLabel, kNoLabel, p.second, kNoStateId) : + Arc(p.first, 0, p.second, s); + } + + ssize_t Size() const { return -1;} + + uint64 Properties() const { return 0ULL;} + + bool Compatible(const Fst<A> &fst) const { + return true; + } + + static const string &Type() { + static const string type = "my"; + return type; + } + + bool Write(ostream &strm) const { return true; } + + static CustomCompactor *Read(istream &strm) { + return new CustomCompactor; + } +}; + + +REGISTER_FST(VectorFst, CustomArc); +REGISTER_FST(ConstFst, CustomArc); +static fst::FstRegisterer< + CompactFst<StdArc, CustomCompactor<StdArc> > > +CompactFst_StdArc_CustomCompactor_registerer; +static fst::FstRegisterer< + CompactFst<CustomArc, CustomCompactor<CustomArc> > > +CompactFst_CustomArc_CustomCompactor_registerer; +static fst::FstRegisterer<ConstFst<StdArc, uint16> > +ConstFst_StdArc_uint16_registerer; +static fst::FstRegisterer< + CompactFst<StdArc, CustomCompactor<StdArc>, uint16> > +CompactFst_StdArc_CustomCompactor_uint16_registerer; + +} // namespace fst + + +using fst::FstTester; +using fst::VectorFst; +using fst::ConstFst; +using fst::MatcherFst; +using fst::CompactFst; +using fst::Fst; +using fst::StdArc; +using fst::CustomArc; +using fst::CustomCompactor; +using fst::StdArcLookAheadFst; +using fst::EditFst; + +int main(int argc, char **argv) { + FLAGS_fst_verify_properties = true; + std::set_new_handler(FailedNewHandler); + SetFlags(argv[0], &argc, &argv, true); + + // VectorFst<StdArc> tests + { + FstTester< VectorFst<StdArc> > std_vector_tester; + std_vector_tester.TestBase(); + std_vector_tester.TestExpanded(); + std_vector_tester.TestAssign(); + std_vector_tester.TestCopy(); + std_vector_tester.TestIO(); + std_vector_tester.TestMutable(); + } + + // ConstFst<StdArc> tests + { + FstTester< ConstFst<StdArc> > std_const_tester; + std_const_tester.TestBase(); + std_const_tester.TestExpanded(); + std_const_tester.TestCopy(); + std_const_tester.TestIO(); + } + + // CompactFst<StdArc, CustomCompactor<StdArc> > + { + FstTester< CompactFst<StdArc, CustomCompactor<StdArc> > > + std_compact_tester; + std_compact_tester.TestBase(); + std_compact_tester.TestExpanded(); + std_compact_tester.TestCopy(); + std_compact_tester.TestIO(); + } + + // VectorFst<CustomArc> tests + { + FstTester< VectorFst<CustomArc> > std_vector_tester; + std_vector_tester.TestBase(); + std_vector_tester.TestExpanded(); + std_vector_tester.TestAssign(); + std_vector_tester.TestCopy(); + std_vector_tester.TestIO(); + std_vector_tester.TestMutable(); + } + + // ConstFst<CustomArc> tests + { + FstTester< ConstFst<CustomArc> > std_const_tester; + std_const_tester.TestBase(); + std_const_tester.TestExpanded(); + std_const_tester.TestCopy(); + std_const_tester.TestIO(); + } + + // CompactFst<CustomArc, CustomCompactor<CustomArc> > + { + FstTester< CompactFst<CustomArc, CustomCompactor<CustomArc> > > + std_compact_tester; + std_compact_tester.TestBase(); + std_compact_tester.TestExpanded(); + std_compact_tester.TestCopy(); + std_compact_tester.TestIO(); + } + + // ConstFst<StdArc, uint16> tests + { + FstTester< ConstFst<StdArc, uint16> > std_const_tester; + std_const_tester.TestBase(); + std_const_tester.TestExpanded(); + std_const_tester.TestCopy(); + std_const_tester.TestIO(); + } + + // CompactFst<StdArc, CustomCompactor<StdArc>, uint16> + { + FstTester< CompactFst<StdArc, CustomCompactor<StdArc>, uint16> > + std_compact_tester; + std_compact_tester.TestBase(); + std_compact_tester.TestExpanded(); + std_compact_tester.TestCopy(); + std_compact_tester.TestIO(); + } + + // FstTester<StdArcLookAheadFst> + { + FstTester<StdArcLookAheadFst> std_matcher_tester; + std_matcher_tester.TestBase(); + std_matcher_tester.TestExpanded(); + std_matcher_tester.TestCopy(); + } + + // EditFst<StdArc> tests + { + FstTester< EditFst<StdArc> > std_edit_tester; + std_edit_tester.TestBase(); + std_edit_tester.TestExpanded(); + std_edit_tester.TestAssign(); + std_edit_tester.TestCopy(); + std_edit_tester.TestMutable(); + } + + cout << "PASS" << endl; + + return 0; +} |