tesseract  5.0.0
stats_test.cc
Go to the documentation of this file.
1 // (C) Copyright 2017, Google Inc.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 // http://www.apache.org/licenses/LICENSE-2.0
6 // Unless required by applicable law or agreed to in writing, software
7 // distributed under the License is distributed on an "AS IS" BASIS,
8 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9 // See the License for the specific language governing permissions and
10 // limitations under the License.
11 
12 #include "kdpair.h"
13 #include "statistc.h"
14 
15 #include "include_gunit.h"
16 
17 namespace tesseract {
18 
19 const int kTestData[] = {2, 0, 12, 1, 1, 2, 10, 1, 0, 0, 0, 2, 0, 4, 1, 1};
20 
21 class STATSTest : public testing::Test {
22 public:
23  void SetUp() override {
24  std::locale::global(std::locale(""));
25  stats_.set_range(0, 16);
26  for (size_t i = 0; i < countof(kTestData); ++i) {
27  stats_.add(i, kTestData[i]);
28  }
29  }
30 
31  void TearDown() override {}
32 
34 };
35 
36 // Tests some basic numbers from the stats_.
37 TEST_F(STATSTest, BasicStats) {
38  EXPECT_EQ(37, stats_.get_total());
39  EXPECT_EQ(2, stats_.mode());
40  EXPECT_EQ(12, stats_.pile_count(2));
41 }
42 
43 // Tests the top_n_modes function.
44 TEST_F(STATSTest, TopNModes) {
45  std::vector<tesseract::KDPairInc<float, int> > modes;
46  int num_modes = stats_.top_n_modes(3, modes);
47  EXPECT_EQ(3, num_modes);
48  // Mode0 is 12 1 1 = 14 total count with a mean of 2 3/14.
49  EXPECT_FLOAT_EQ(2.0f + 3.0f / 14, modes[0].key());
50  EXPECT_EQ(14, modes[0].data());
51  // Mode 1 is 2 10 1 = 13 total count with a mean of 5 12/13.
52  EXPECT_FLOAT_EQ(5.0f + 12.0f / 13, modes[1].key());
53  EXPECT_EQ(13, modes[1].data());
54  // Mode 2 is 4 1 1 = 6 total count with a mean of 13.5.
55  EXPECT_FLOAT_EQ(13.5f, modes[2].key());
56  EXPECT_EQ(6, modes[2].data());
57 }
58 
59 } // namespace tesseract
const int kTestData[]
Definition: stats_test.cc:19
constexpr size_t countof(T const (&)[N]) noexcept
Definition: serialis.h:42
TEST_F(EuroText, FastLatinOCR)
void add(int32_t value, int32_t count)
Definition: statistc.cpp:99
bool set_range(int32_t min_bucket_value, int32_t max_bucket_value_plus_1)
Definition: statistc.cpp:59
void TearDown() override
Definition: stats_test.cc:31
void SetUp() override
Definition: stats_test.cc:23