File: test_I_ash.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 (36 lines) | stat: -rw-r--r-- 1,026 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
27
28
29
30
31
32
33
34
35
36
#include "test_I.h"

int test_I_ash (int iterations)
{
	int error = 0;
	int i;
	// Check against "*" and floor1.
	for (i = iterations; i > 0; i--) {
		cl_I a = testrandom_I();
		uintL b = random32() % 1024;
		cl_I pow2 = 1;
		for (uintL j = 0; j < b; j++)
			pow2 = pow2+pow2;
		ASSERT1(ash(1,(sintL)b) == pow2, b);
		ASSERT1(ash(1,(cl_I)b) == pow2, b);
		ASSERT2(ash(a,(sintL)b) == a*pow2, a,b);
		ASSERT2(ash(a,-(sintL)b) == floor1(a,pow2), a,b);
	}
	// Check homomorphism w.r.t. second argument.
	for (i = iterations; i > 0; i--) {
		cl_I a = testrandom_I();
		sintL b = random32() % 1024;
		sintL c = random32() % 1024;
		ASSERT3(ash(ash(a,b),c) == ash(a,b+c), a,b,c);
		ASSERT3(ash(ash(a,b),-c) == ash(a,b-c), a,b,c);
		ASSERT3(ash(ash(a,-b),-c) == ash(a,-b-c), a,b,c);
	}
	// Check against each other.
	for (i = iterations; i > 0; i--) {
		cl_I a = testrandom_I();
		uintL b = random32() % 1024;
		ASSERT2(ash(a,(cl_I)b) == ash(a,(sintL)b), a,b);
		ASSERT2(ash(a,-(cl_I)b) == ash(a,-(sintL)b), a,b);
	}
	return error;
}