tesseract  5.0.0-alpha-619-ge9db
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 
13 #include "kdpair.h"
14 #include "statistc.h"
15 
16 #include "include_gunit.h"
17 
18 namespace {
19 
20 const int kTestData[] = {2, 0, 12, 1, 1, 2, 10, 1, 0, 0, 0, 2, 0, 4, 1, 1};
21 
22 class STATSTest : public testing::Test {
23  public:
24  void SetUp() {
25  std::locale::global(std::locale(""));
26  stats_.set_range(0, 16);
27  for (size_t i = 0; i < ARRAYSIZE(kTestData); ++i)
28  stats_.add(i, kTestData[i]);
29  }
30 
31  void TearDown() {}
32 
33  STATS stats_;
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) {
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.
ARRAYSIZE
#define ARRAYSIZE(arr)
Definition: include_gunit.h:53
include_gunit.h
tesseract::TEST_F
TEST_F(EquationFinderTest, IdentifySpecialText)
Definition: equationdetect_test.cc:181
statistc.h
genericvector.h
kdpair.h
STATS
Definition: statistc.h:30
GenericVector
Definition: baseapi.h:40