File: test_I_logcount.cc

package info (click to toggle)
cln 1.3.4-4
  • links: PTS
  • area: main
  • in suites: buster
  • size: 10,724 kB
  • sloc: cpp: 80,930; sh: 11,982; ansic: 3,278; makefile: 1,313
file content (26 lines) | stat: -rw-r--r-- 671 bytes parent folder | download | duplicates (13)
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
#include "test_I.h"

int test_I_logcount (int iterations)
{
	int error = 0;
	int i;
	// Check additivity.
	for (i = iterations; i > 0; i--) {
		cl_I a = testrandom_I();
		cl_I b = testrandom_I();
		if (a >= 0 && b >= 0)
			ASSERT2(logcount(a) == logcount(logand(a,b)) + logcount(logandc2(a,b)), a,b);
	}
	// Check behaviour on sign change.
	for (i = iterations; i > 0; i--) {
		cl_I a = testrandom_I();
		ASSERT1(logcount(lognot(a)) == logcount(a), a);
	}
	// Check shift invariance.
	for (i = iterations; i > 0; i--) {
		cl_I a = testrandom_I();
		sintL b = random32() % 1024;
		ASSERT2(logcount(ash(a,b)) == logcount(a) + (minusp(a) ? b : 0), a,b);
	}
	return error;
}