summaryrefslogtreecommitdiff
path: root/tests/CSD_Strategy_Tests/TP_Foo_C/Foo_C_Statistics.cpp
blob: b832e29d9a159b2544de0ce6e9867f8ce1df92a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// $Id$
#include "Foo_C_Statistics.h"
#include "Foo_C_ClientEngine.h"
#include "Foo_C_Custom_ClientEngine.h"

Foo_C_Statistics::Foo_C_Statistics(unsigned num_remote_clients, 
                                   unsigned num_collocated_clients)
: num_remote_clients_ (num_remote_clients),
  num_collocated_clients_ (num_collocated_clients)
{
  for (unsigned i = 0; i < 10; i++)
    {
      this->expected_[i] = 0;
      this->actual_[i] = 0;
    }
}


Foo_C_Statistics::~Foo_C_Statistics()
{
}


void
Foo_C_Statistics::expected(unsigned op_num, unsigned count, bool remote_client)
{
  if (remote_client)
    {
      this->expected_[op_num-1] += count * this->num_remote_clients_;
    }
  else
    {
      this->expected_[op_num-1] += count * this->num_collocated_clients_;
    }
}


void
Foo_C_Statistics::actual(unsigned op_num, unsigned count)
{
  this->actual_[op_num-1] += count;
}


void
Foo_C_Statistics::actual_in_values(unsigned op_num, LongVector lv)
{
  size_t sz = lv.size();
  for (size_t i = 0; i < sz; i++)
    {
      this->actual_in_values_[op_num-1].push_back (lv[i]);
    }
}


bool
Foo_C_Statistics::actual_vs_expected()
{
  // Get the expected statistics for a single remote client.
  Foo_C_Statistics remote_client_stats (1, 0);
  Foo_C_ClientEngine::expected_results (remote_client_stats);
  // Get the expected statistics for a single collocated client.
  Foo_C_Statistics collocated_client_stats (0, 1);
  Foo_C_Custom_ClientEngine::expected_results (collocated_client_stats);

  for (unsigned i = 0; i < 10; i++)
    {
      if (this->expected_[i] != this->actual_[i])
        {
          return false;
        }

      // Verify the "in" values.
      // Skip op1/op5 and cust_op1/cust_op5 since they do not have 
      // any "in" values.
      if (i % 5 == 0 || i % 5 == 4)
        {
          continue;
        }

      unsigned actual_size 
        = this->actual_in_values_[i].size ();
      unsigned expected_size 
        =  this->num_remote_clients_ * remote_client_stats.expected_[i]
           + this->num_collocated_clients_ * collocated_client_stats.expected_[i];
          
      if (actual_size == 0 && expected_size == 0)
        { 
          continue;
        }

      if (actual_size != expected_size)
        {
          return false;
        }

      sort (this->actual_in_values_[i]);

      for (unsigned j = 0; j < actual_size - 1; j++)
        {
          if (this->actual_in_values_[i][j] != this->actual_in_values_[i][j + 1] - 1)
            {
              return false;
            }
        }
    }   
  return true;
}