Skip to content

Commit

Permalink
clang-tidy to test/
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Dec 29, 2024
1 parent df00a0b commit ce1aa26
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 11 deletions.
2 changes: 2 additions & 0 deletions test/testautophrasedict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "libime/table/autophrasedict.h"
#include <fcitx-utils/log.h>
#include <sstream>
#include <string>
#include <string_view>
#include <unordered_set>

using namespace libime;
Expand Down
12 changes: 10 additions & 2 deletions test/testdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "libime/core/decoder.h"
#include "libime/core/languagemodel.h"
#include "libime/core/lattice.h"
#include "libime/core/segmentgraph.h"
#include "libime/pinyin/pinyindecoder.h"
#include "libime/pinyin/pinyindictionary.h"
#include "libime/pinyin/pinyinencoder.h"
#include "testdir.h"
#include "testutils.h"
#include <cstddef>
#include <fcitx-utils/log.h>
#include <iostream>
#include <limits>
#include <memory>
#include <ostream>

using namespace libime;

void testTime(PinyinDictionary &, Decoder &decoder, const char *pinyin,
PinyinFuzzyFlags flags, int nbest = 1) {
void testTime(PinyinDictionary & /*unused*/, Decoder &decoder,
const char *pinyin, PinyinFuzzyFlags flags, int nbest = 1) {
auto printTime = [](int t) {
std::cout << "Time: " << t / 1000000.0 << " ms" << std::endl;
};
Expand Down
12 changes: 9 additions & 3 deletions test/testhistorybigram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
#include "libime/core/historybigram.h"
#include <boost/range/irange.hpp>
#include <cmath>
#include <exception>
#include <fcitx-utils/log.h>
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_set>

void testBasic() {
using namespace libime;
HistoryBigram history;
history.setUnknownPenalty(std::log10(1.0f / 8192));
history.setUnknownPenalty(std::log10(1.0F / 8192));
history.add({"", "", "一个", "好人"});
history.add({"", "", "一个", "坏人"});
history.add({""});
Expand Down Expand Up @@ -113,7 +117,8 @@ void testOverflow() {
}
std::stringstream dump;
history.dump(dump);
int i, expect = total - 1;
int i;
int expect = total - 1;
while (dump >> i) {
FCITX_ASSERT(i == expect);
--expect;
Expand Down Expand Up @@ -183,7 +188,8 @@ void testSaveAndLoadText() {
}
std::stringstream dump;
history.dump(dump);
int i, expect = total - 1;
int i;
int expect = total - 1;
while (dump >> i) {
FCITX_ASSERT(i == expect);
--expect;
Expand Down
2 changes: 2 additions & 0 deletions test/testinputbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "libime/core/inputbuffer.h"
#include <fcitx-utils/inputbuffer.h>
#include <fcitx-utils/log.h>
#include <stdexcept>

void test_basic(bool ascii) {
using namespace libime;
Expand Down
7 changes: 5 additions & 2 deletions test/testmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
#include "libime/core/lattice.h"
#include "testdir.h"
#include <cmath>
#include <iostream>
#include <string>

int main() {
using namespace libime;
LanguageModel model(LIBIME_BINARY_DIR "/data/sc.lm");
State state(model.nullState()), out_state = model.nullState();
State state(model.nullState());
State out_state = model.nullState();
std::string word;
float sum = 0.0f;
float sum = 0.0F;
while (std::cin >> word) {
float s;
WordNode w(word, model.index(word));
Expand Down
4 changes: 4 additions & 0 deletions test/testpinyincontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
#include "libime/pinyin/pinyinime.h"
#include "testdir.h"
#include <array>
#include <cstddef>
#include <fcitx-utils/log.h>
#include <iostream>
#include <memory>
#include <ostream>
#include <sstream>
#include <string_view>

Expand Down
4 changes: 4 additions & 0 deletions test/testpinyindictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
#include "libime/pinyin/pinyindictionary.h"
#include "libime/pinyin/pinyinencoder.h"
#include "testdir.h"
#include <cstddef>
#include <fcitx-utils/log.h>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string_view>

using namespace libime;

Expand Down
4 changes: 4 additions & 0 deletions test/testpinyinencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
*/

#include "libime/core/segmentgraph.h"
#include "libime/pinyin/pinyincorrectionprofile.h"
#include "libime/pinyin/pinyinencoder.h"
#include "libime/pinyin/shuangpinprofile.h"
#include <cstddef>
#include <fcitx-utils/log.h>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>

using namespace libime;
Expand Down
9 changes: 8 additions & 1 deletion test/testpinyinime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@
#include "testutils.h"
#include <boost/iostreams/device/null.hpp>
#include <boost/iostreams/stream.hpp>
#include <cstddef>
#include <cstdint>
#include <fcitx-utils/log.h>
#include <fstream>
#include <functional>
#include <ios>
#include <iostream>
#include <memory>
#include <ostream>
#include <string>

using namespace libime;

Expand All @@ -45,7 +52,7 @@ int main(int argc, char *argv[]) {
}
ime.setFuzzyFlags({PinyinFuzzyFlag::Inner, PinyinFuzzyFlag::CommonTypo,
PinyinFuzzyFlag::AdvancedTypo});
ime.setScoreFilter(1.0f);
ime.setScoreFilter(1.0F);
ime.setShuangpinProfile(
std::make_shared<ShuangpinProfile>(ShuangpinBuiltinProfile::Xiaohe));
PinyinContext c(&ime);
Expand Down
3 changes: 2 additions & 1 deletion test/testpinyinime_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "libime/pinyin/pinyinime.h"
#include "libime/pinyin/shuangpinprofile.h"
#include "testdir.h"
#include <algorithm>
#include <fcitx-utils/log.h>
#include <iterator>
#include <memory>
Expand All @@ -29,7 +30,7 @@ int main() {
PinyinDictFormat::Binary);
PinyinFuzzyFlags flags = PinyinFuzzyFlag::Inner;
ime.setFuzzyFlags(flags);
ime.setScoreFilter(1.0f);
ime.setScoreFilter(1.0F);
ime.setShuangpinProfile(
std::make_shared<ShuangpinProfile>(ShuangpinBuiltinProfile::Xiaohe));
PinyinContext c(&ime);
Expand Down
3 changes: 3 additions & 0 deletions test/testprediction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

#include "libime/core/historybigram.h"
#include "libime/core/prediction.h"
#include "libime/core/userlanguagemodel.h"
#include "testdir.h"
#include <fcitx-utils/log.h>
#include <string>
#include <vector>

using namespace libime;

Expand Down
9 changes: 9 additions & 0 deletions test/testshuangpinprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "libime/core/segmentgraph.h"
#include "libime/pinyin/pinyindata.h"
#include "libime/pinyin/pinyinencoder.h"
#include "libime/pinyin/shuangpinprofile.h"
#include <algorithm>
#include <cstddef>
#include <fcitx-utils/log.h>
#include <iostream>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace libime;

void checkProfile(const ShuangpinProfile &profile, bool hasSemicolon) {
Expand Down
9 changes: 9 additions & 0 deletions test/testtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
*/

#include "libime/core/segmentgraph.h"
#include "libime/table/tablebaseddictionary.h"
#include "libime/table/tabledecoder.h"
#include "libime/table/tableoptions.h"
#include "libime/table/tablerule.h"
#include "testdir.h"
#include <cstddef>
#include <cstdint>
#include <fcitx-utils/log.h>
#include <ios>
#include <iostream>
#include <optional>
#include <ostream>
#include <set>
#include <sstream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <unistd.h>
#include <vector>

using namespace libime;

Expand Down
6 changes: 6 additions & 0 deletions test/testtableime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
*/

#include "libime/core/languagemodel.h"
#include "libime/core/userlanguagemodel.h"
#include "libime/table/tablebaseddictionary.h"
#include "libime/table/tablecontext.h"
#include "libime/table/tabledecoder.h"
#include "libime/table/tableoptions.h"
#include "testdir.h"
#include "testutils.h"
#include <cstddef>
#include <fcitx-utils/log.h>
#include <iostream>
#include <ostream>
#include <string>
#include <string_view>

using namespace libime;

Expand Down
3 changes: 3 additions & 0 deletions test/testtableime_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
*/

#include "libime/core/languagemodel.h"
#include "libime/core/userlanguagemodel.h"
#include "libime/table/tablebaseddictionary.h"
#include "libime/table/tablecontext.h"
#include "libime/table/tableoptions.h"
#include "testdir.h"
#include <fcitx-utils/log.h>
#include <string>
#include <string_view>

using namespace libime;

Expand Down
2 changes: 2 additions & 0 deletions test/testtrie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ int main() {
auto nan1 = DATrie<float>::noValue();
auto nan2 = DATrie<float>::noPath();
// NaN != NaN, we must use memcmp to do this.
// NOLINTBEGIN(bugprone-suspicious-memory-comparison)
FCITX_ASSERT(memcmp(&nan1, &result, sizeof(float)) == 0);
FCITX_ASSERT(trie.isNoValue(result));
result = trie.traverse("aaae", pos);
FCITX_ASSERT(memcmp(&nan2, &result, sizeof(float)) == 0);
// NOLINTEND(bugprone-suspicious-memory-comparison)
FCITX_ASSERT(trie.isNoPath(result));
trie.erase(pos);
FCITX_ASSERT(trie.size() == 4);
Expand Down
10 changes: 8 additions & 2 deletions test/testusermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
*/

#include "libime/core/historybigram.h"
#include "libime/core/languagemodel.h"
#include "libime/core/lattice.h"
#include "libime/core/userlanguagemodel.h"
#include "testdir.h"
#include <cmath>
#include <fstream>
#include <ios>
#include <iostream>
#include <list>
#include <ostream>
#include <string>

int main(int argc, char *argv[]) {
using namespace libime;
Expand All @@ -19,9 +24,10 @@ int main(int argc, char *argv[]) {
std::fstream fin(argv[1], std::ios::in | std::ios::binary);
model.history().load(fin);
}
State state(model.nullState()), out_state = model.nullState();
State state(model.nullState());
State out_state = model.nullState();
std::string word;
float sum = 0.0f;
float sum = 0.0F;
std::list<WordNode> nodes;
while (std::cin >> word) {
float s;
Expand Down
3 changes: 3 additions & 0 deletions test/testutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#define _TEST_TESTUTILS_H_

#include <chrono>
#include <cstdint>
#include <functional>
#include <utility>

struct ScopedNanoTimer {
std::chrono::high_resolution_clock::time_point t0;
Expand Down
4 changes: 4 additions & 0 deletions test/triebench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "libime/core/datrie.h"
#include <cstddef>
#include <cstdint>
#include <fcitx-utils/log.h>
#include <iostream>
#include <string>
#include <unistd.h>
#include <unordered_map>
#include <vector>

using namespace libime;

Expand Down

0 comments on commit ce1aa26

Please sign in to comment.