Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
alg_test.cpp
Go to the documentation of this file.
1
29// expand _TEST_EXPORT macros
30#define _RWSTD_TEST_SRC
31
32#include <stdlib.h> // for rand()
33
34#include <rw_alg_test.h>
35
36
37// generate a unique sequential number starting from 0
39{
40 static int val;
41
42 return ++val;
43}
44
45
46// generate numbers in the sequence 0, 0, 1, 1, 2, 2, 3, 3, etc...
48{
49 static int vals [2];
50
51 return vals [0] += ++vals [1] % 2;
52}
53
54
55// generate a sequence of subsequences (i.e., 0, 1, 2, 3, 4, 0, 1, 2, etc...)
57{
58 static int val;
59
60 return val++ % 5;
61}
62
63
64// wrapper around a (possibly) extern "C" int rand()
65// extern "C++"
67{
68 return rand ();
69}
70
71
72_TEST_EXPORT unsigned
73ilog2 (size_t n)
74{
75 unsigned result = 0;
76
77 while (n >>= 1)
78 ++result;
79
80 return result;
81}
82
83
84_TEST_EXPORT unsigned
85ilog10 (size_t n)
86{
87 unsigned result = 0;
88
89 while (n /= 10)
90 ++result;
91
92 return result;
93}
#define n
Definition 17.names.cpp:130
#define val
Definition 17.names.cpp:570
volatile int result
_TEST_EXPORT unsigned ilog2(size_t n)
Definition alg_test.cpp:73
_TEST_EXPORT int gen_seq()
Definition alg_test.cpp:38
_TEST_EXPORT unsigned ilog10(size_t n)
Definition alg_test.cpp:85
_TEST_EXPORT int gen_rnd()
Definition alg_test.cpp:66
_TEST_EXPORT int gen_seq_2lists()
Definition alg_test.cpp:47
_TEST_EXPORT int gen_subseq()
Definition alg_test.cpp:56
#define _TEST_EXPORT
Definition rw_testdefs.h:55