MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/Imath / testGenerator

Function testGenerator

src/ImathTest/testRandom.cpp:103–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101
102template <class Rand>
103void
104testGenerator ()
105{
106 //
107 // Test if the values, and the differences between
108 // successive values, are evenly distributed.
109 //
110
111 const int N = 10;
112 const int M = 100000;
113
114 int values[N + 1];
115 int diffs[2 * N + 3];
116 int* v = &values[0];
117 int* d = &diffs[N + 2];
118
119 for (int i = 0; i <= N; ++i)
120 v[i] = 0;
121
122 for (int i = -N; i <= N; ++i)
123 d[i] = 0;
124
125 Rand rand (0);
126 float previous = 0;
127
128 for (int i = 0; i < M * N; ++i)
129 {
130 float r = float(rand.nextf (0.0, 1.0));
131 float diff = r - previous;
132 previous = r;
133
134 v[int (r * N)] += 1;
135 d[IMATH_INTERNAL_NAMESPACE::floor (diff * N + 0.5)] += 1;
136 }
137
138 cout << " values" << endl;
139
140 for (int i = 0; i < N; ++i)
141 {
142 // cout << setw (4) << i << ' ' << setw(6) << v[i] << ' ';
143 assert (abs (v[i] - M) < 0.01 * M);
144
145 // for (int j = 0; j < v[i] * 60 / M; ++j)
146 // cout << '*';
147
148 // cout << endl;
149 }
150
151 assert (v[N] == 0);
152
153 cout << " differences between successive values" << endl;
154
155 for (int i = -N; i <= N; ++i)
156 {
157 // cout << setw (4) << i << ' ' << setw (6) << d[i] << ' ';
158 assert (abs ((N - abs (i)) * M / N - d[i]) < 0.05 * M);
159
160 // for (int j = 0; j < d[i] * 60 / M; ++j)

Callers

nothing calls this directly

Calls 3

floorFunction · 0.85
nextfMethod · 0.60
absFunction · 0.50

Tested by

no test coverage detected