simple-options-test.cc
Go to the documentation of this file.
1 // util/simple-options-test.cc
2 
3 // Copyright 2013 Tanel Alumae, Tallinn University of Technology
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 
11 // http://www.apache.org/licenses/LICENSE-2.0
12 
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 #include "util/simple-options.h"
20 
21 namespace kaldi {
22 
23 
25  std::string str="default_for_str";
26  int32 num = 1;
27  uint32 unum = 2;
28  float realnum = 0.1;
29  bool flag = false;
30  bool rval;
31  SimpleOptions so;
32 
33  so.Register("num", &num, "Description of num");
34  so.Register("unum", &unum, "Description of unum");
35  so.Register("str", &str, "Description of str");
36  so.Register("flag", &flag, "Description of flag");
37  so.Register("realnum", &realnum, "Description of realnum");
38 
39  rval = so.SetOption("num", 42);
40  KALDI_ASSERT(rval);
41  so.SetOption("unum", static_cast<uint32>(43));
42  KALDI_ASSERT(rval);
43  rval = so.SetOption("str", (std::string)"foo");
44  KALDI_ASSERT(rval);
45  rval = so.SetOption("flag", false);
46  KALDI_ASSERT(rval);
47 
48  KALDI_ASSERT(num == 42);
49  KALDI_ASSERT(unum == 43);
50  KALDI_ASSERT(str == "foo");
51  KALDI_ASSERT(flag == false);
52 
53  rval = so.SetOption("str", "foo2");
54  KALDI_ASSERT(rval);
55  KALDI_ASSERT(str == "foo2");
56 
57  // test automatic conversion between int and uint
58  rval = so.SetOption("unum", 44);
59  KALDI_ASSERT(rval);
60  KALDI_ASSERT(unum == 44);
61 
62  // test automatic conversion between float and double
63  rval = so.SetOption("realnum", static_cast<float>(0.2));
64  KALDI_ASSERT(rval);
65  KALDI_ASSERT(realnum - 0.2 < 0.000001);
66  rval = so.SetOption("realnum", static_cast<double>(0.3));
67  KALDI_ASSERT(rval);
68  KALDI_ASSERT(realnum - 0.3 < 0.000001);
69 
71  rval = so.GetOptionType("num", &type);
72  KALDI_ASSERT(rval);
74 
75  rval = so.GetOptionType("xxxx", &type);
76  KALDI_ASSERT(rval == false);
77 }
78 
79 
80 } // end namespace kaldi.
81 
82 int main() {
83  using namespace kaldi;
85  return 0;
86 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
The class SimpleOptions is an implementation of OptionsItf that allows setting and getting option val...
kaldi::int32 int32
bool GetOptionType(const std::string &key, OptionType *type)
void Register(const std::string &name, bool *ptr, const std::string &doc)
void UnitTestSimpleOptions()
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
bool SetOption(const std::string &key, const bool &value)
int main()