File: test_I_ilength.cc

package info (click to toggle)
cln 1.3.7-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,996 kB
  • sloc: cpp: 80,860; sh: 5,138; ansic: 3,174; makefile: 1,274
file content (32 lines) | stat: -rw-r--r-- 543 bytes parent folder | download | duplicates (8)
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
#include "test_I.h"

int test_I_integer_length (int iterations)
{
	int error = 0;
	int i;
	// Check against ash.
	for (i = iterations; i > 0; i--) {
		cl_I a = testrandom_I();
		uintC l = integer_length(a);
		if (a >= 0) {
			int b = 0;
			if (a < ash(1,l)) {
				if (a == 0)
					b = (l == 0);
				else
					b = (l > 0 && a >= ash(1,l-1));
			}
			ASSERT1(b, a);
		} else {
			int b = 0;
			if (a >= ash(-1,l)) {
				if (a == -1)
					b = (l == 0);
				else
					b = (l > 0 && a < ash(-1,l-1));
			}
			ASSERT1(b, a);
		}
	}
	return error;
}