// File: /workspace/github_cpp_makefile_star2_O3/ashlall[P]StreamStats/Test/Reservoir_test.cpp
// Function: test_reservoir()
void test_reservoir()
{
	int k = 1000; // Reservoir sample size	
	long quantA,quantB,quantC,quantD,quantE,quantF,quantG,quantH;
	bool condA,condB,condC,condD,condE,condF,condG,condH;
	double upper,lower;
	int n=10000000; 
	
	/*	Extrem case when n = 1
	
	int random_fix1 = rand()% RAND_MAX;
    cout << "random_fix1: " << random_fix1 <<endl;
    int random_fix2 = rand()% RAND_MAX;
    //cout << "random_fix2: " << random_fix2 <<endl;
    int random_fix3 = rand()% RAND_MAX;
    //cout << "random_fix2: " << random_fix3 <<endl;
    */
    
	ReservoirSampling a(k); 
	ReservoirSampling b(k);
	ReservoirSampling c(k);
	ReservoirSampling d(k);
	ReservoirSampling e(k);
	
	/*	Extrem case when n = 1
	
	ReservoirSampling f(k);
	ReservoirSampling g(k);
	ReservoirSampling h(k);
  	*/
  	
	for (int i=0;i <= n;i++) //inserting in increasing order
	{
		a.insert(i); 
		
	}
	
	bool condA1;
	int LA = a.get_stream_size(); //test the function get_stream_size()
	condA1= (LA == n+1);
	assert(condA1 == true);

	
	for (int i = n; i >= 0; i--) //inserting in desceding order
    {
  		b.insert(i); 
    }
    
  	bool condB1;
	int LB = b.get_stream_size(); //test the function get_stream_size()
	condB1= (LB == n+1);
	assert(condB1 == true);
  
 	for (int m = 1; m <= 3; m++) //create 3 "random" sequences with certain patterned seed that holds their randomness every time runs the code
  	{
  		 if (m == 1)
  		 {
  		   	 //cout << "sequence 1: " << endl;
  			 for (int i = 0; i <= n; i++)
   			 {
   			 	srand(i);
  				long rand_num=rand()%n;
  				//cout << rand_num << " ";
  				c.insert(rand_num);  //inserting float number from 0 to n
  			 }
  			 //cout << ""<<endl;
  			 bool condC1;
			 int LC = c.get_stream_size(); //test the function get_stream_size()
			 condC1= (LC == n+1);
			 assert(condC1 == true);
  		}
  		
  		else if(m == 2)
  		{
  		 	  //cout << "sequence 2: " << endl;
  			  for (int i = 0; i <= n; i++)
   			 {
   			    srand(i^2);
  				long rand_num=rand()%n;
  				//cout << rand_num << " ";
  				d.insert(rand_num); //inserting float number from 0 to n
  			 }  
  			 //cout << ""<<endl;
  			 bool condD1;
			 int LD = d.get_stream_size(); //test the function get_stream_size()
			 condD1= (LD == n+1);
			 assert(condD1 == true);
  		}	
  		
  		else 
  		{	
  		  	 //cout << "sequence 3: " << endl;
  			  for (int i = 0; i <= n; i++)
   			 {
   			 	srand(n-i);
  				long rand_num=rand()%n;
  				//cout << rand_num << " ";
  				e.insert(rand_num); //inserting float number from 0 to n
  			 }  
  			 //cout <<""<<endl;
  			 bool condE1;
			 int LE = e.get_stream_size(); //test the function get_stream_size()
			 condE1= (LE == n+1);
			 assert(condE1 == true);
  		}
  	} 

	  /*	Extrem case when n = 1
	  	
  	  f.insert(random_fix1); 
  	  g.insert(random_fix2); 
  	  h.insert(random_fix3);  
  	  */ 
  	
	for (float i=1;i<=100;i++)
	{
  	  double interval=i/100; //getting each percentile probabilty interval
  	  
  	  quantA=a.getQuantile(interval); //getting quantile for each probability interval
  	  quantB=b.getQuantile(interval);//getting quantile for each probability interval
  	  quantC=c.getQuantile(interval);//getting quantile for each probability interval
  	  quantD=d.getQuantile(interval);
  	  quantE=e.getQuantile(interval);
  	  
	  /*	Extrem case when n = 1
	  
  	  quantF=f.getQuantile(interval);
  	  quantG=g.getQuantile(interval);
  	  quantH=h.getQuantile(interval);
  	  */
  	  
  	  lower=(interval-0.05)*n;
  	  upper=(interval+0.05)*n;
  	  
  	  condA= ((lower<=quantA) && (upper>=quantA));
  	  //checking if quantile is within error range

  	  condB= ((lower<=quantB) && (upper >=quantB));
  	  //checking if quantile is within error range

  	  condC= ((lower<=quantC) && (upper>=quantC));
  	  condD= ((lower<=quantD) && (upper>=quantD));
  	  condE= ((lower<=quantE) && (upper>=quantE));
  	  //checking if quantile is within error range
  	  
  	  /*	Extrem case when n = 1
  	  
  	  condF= (random_fix1 == quantF);
  	  condG= (random_fix2 == quantG);
  	  condH= (random_fix3 == quantH);
	  */
  	  
  	  assert(condA==true);
  	  assert(condB==true);
  	  assert(condC==true);
  	  assert(condD==true);
  	  assert(condE==true);
  	  
  	  /*	Extrem case when n = 1
  	  assert(condF==true);
  	  assert(condG==true);
  	  assert(condH==true);
  	  */
  }   
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
leaq 0x3854(%rip), %rbx      # 0x4d78
movq %rbx, -0xb8(%rbp)
movl $0x3e8, %r14d           # imm = 0x3E8
movl %r14d, -0xac(%rbp)
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0xa8(%rbp)
movl $0x0, -0xb0(%rbp)
movq %rbx, -0xa0(%rbp)
movl %r14d, -0x94(%rbp)
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0x90(%rbp)
movl $0x0, -0x98(%rbp)
movq %rbx, -0x88(%rbp)
movl $0x3e8, -0x7c(%rbp)     # imm = 0x3E8
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0x78(%rbp)
movl $0x0, -0x80(%rbp)
movq %rbx, -0x70(%rbp)
movl $0x3e8, -0x64(%rbp)     # imm = 0x3E8
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0x60(%rbp)
movl $0x0, -0x68(%rbp)
movq %rbx, -0x58(%rbp)
movl $0x3e8, -0x4c(%rbp)     # imm = 0x3E8
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0x48(%rbp)
movl $0x0, -0x50(%rbp)
xorpd %xmm0, %xmm0
movl $0x989681, %r14d        # imm = 0x989681
leaq -0xb8(%rbp), %rbx
movsd %xmm0, -0x40(%rbp)
movq %rbx, %rdi
movsd -0x40(%rbp), %xmm0
callq 0x1414
movsd -0x40(%rbp), %xmm0
addsd 0x19f9(%rip), %xmm0     # 0x3008
decl %r14d
jne 0x15f0
cmpl $0x989681, -0xb0(%rbp)  # imm = 0x989681
jne 0x1a7e
movl $0x989680, %r14d        # imm = 0x989680
leaq -0xa0(%rbp), %rbx
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movq %rbx, %rdi
callq 0x1414
addl $-0x1, %r14d
jb 0x1631
cmpl $0x989681, -0x98(%rbp)  # imm = 0x989681
jne 0x1a9d
movl $0x1, %r13d
leaq -0x88(%rbp), %rbx
leaq -0x70(%rbp), %r14
leaq -0x58(%rbp), %r15
cmpl $0x1, %r13d
je 0x16da
cmpl $0x2, %r13d
jne 0x1731
xorl %r12d, %r12d
movl %r12d, %edi
xorl $0x2, %edi
callq 0x10d0
callq 0x1050
cltq
imulq $0x6b5fca6b, %rax, %rcx # imm = 0x6B5FCA6B
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x36, %rcx
addl %edx, %ecx
imull $0x989680, %ecx, %ecx   # imm = 0x989680
subl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq %r14, %rdi
callq 0x1414
incl %r12d
cmpl $0x989681, %r12d        # imm = 0x989681
jne 0x167f
cmpl $0x989681, -0x68(%rbp)  # imm = 0x989681
je 0x1784
jmp 0x1a21
xorl %r12d, %r12d
movl %r12d, %edi
callq 0x10d0
callq 0x1050
cltq
imulq $0x6b5fca6b, %rax, %rcx # imm = 0x6B5FCA6B
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x36, %rcx
addl %edx, %ecx
imull $0x989680, %ecx, %ecx   # imm = 0x989680
subl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq %rbx, %rdi
callq 0x1414
incl %r12d
cmpl $0x989681, %r12d        # imm = 0x989681
jne 0x16dd
cmpl $0x989681, -0x80(%rbp)  # imm = 0x989681
je 0x1784
jmp 0x1a40
movl $0x989680, %r12d        # imm = 0x989680
movl %r12d, %edi
callq 0x10d0
callq 0x1050
cltq
imulq $0x6b5fca6b, %rax, %rcx # imm = 0x6B5FCA6B
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x36, %rcx
addl %edx, %ecx
imull $0x989680, %ecx, %ecx   # imm = 0x989680
subl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq %r15, %rdi
callq 0x1414
addl $-0x1, %r12d
jb 0x1737
cmpl $0x989681, -0x50(%rbp)  # imm = 0x989681
jne 0x1a5f
incl %r13d
cmpl $0x4, %r13d
jne 0x166c
movl $0x1, %ebx
leaq -0xa0(%rbp), %r14
leaq -0x88(%rbp), %r15
leaq -0x70(%rbp), %r12
leaq -0x58(%rbp), %r13
xorps %xmm0, %xmm0
cvtsi2ss %ebx, %xmm0
divss 0x18ed(%rip), %xmm0     # 0x30a8
cvtss2sd %xmm0, %xmm0
leaq -0xb8(%rbp), %rdi
movaps %xmm0, -0x40(%rbp)
callq 0x146e
movsd %xmm0, -0xd8(%rbp)
movq %r14, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x146e
movsd %xmm0, -0xd0(%rbp)
movq %r15, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x146e
movsd %xmm0, -0xc8(%rbp)
movq %r12, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x146e
movsd %xmm0, -0xc0(%rbp)
movq %r13, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x146e
cvttsd2si -0xd8(%rbp), %rax
movapd -0x40(%rbp), %xmm4
movapd %xmm4, %xmm1
addsd 0x17d7(%rip), %xmm1     # 0x3010
movsd 0x17d7(%rip), %xmm3     # 0x3018
mulsd %xmm3, %xmm1
addsd 0x17d3(%rip), %xmm4     # 0x3020
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
ucomisd %xmm1, %xmm2
jb 0x1a02
mulsd %xmm3, %xmm4
ucomisd %xmm2, %xmm4
jb 0x1a02
cvttsd2si -0xd0(%rbp), %rax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
ucomisd %xmm1, %xmm2
jb 0x19e3
ucomisd %xmm2, %xmm4
jb 0x19e3
cvttsd2si -0xc8(%rbp), %rax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
movapd %xmm1, %xmm3
cmplepd %xmm2, %xmm3
cmplepd %xmm4, %xmm2
andpd %xmm3, %xmm2
movd %xmm2, %eax
testb $0x1, %al
je 0x19c4
cvttsd2si -0xc0(%rbp), %rax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
movapd %xmm1, %xmm3
cmplepd %xmm2, %xmm3
cmplepd %xmm4, %xmm2
andpd %xmm3, %xmm2
movd %xmm2, %eax
testb $0x1, %al
je 0x19a5
cvttsd2si %xmm0, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
cmplepd %xmm0, %xmm1
cmplepd %xmm4, %xmm0
andpd %xmm1, %xmm0
movd %xmm0, %eax
testb $0x1, %al
je 0x1986
incl %ebx
cmpl $0x65, %ebx
jne 0x17ac
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x192c
callq 0x1100
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x193a
callq 0x1100
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x1948
callq 0x1100
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x1959
callq 0x1100
movq -0xa8(%rbp), %rdi
addq $0xb8, %rsp
testq %rdi, %rdi
je 0x197b
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1100
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17f7(%rip), %rdi      # 0x3184
leaq 0x175b(%rip), %rsi      # 0x30ef
leaq 0x1767(%rip), %rcx      # 0x3102
movl $0xab, %edx
callq 0x1070
leaq 0x17cc(%rip), %rdi      # 0x3178
leaq 0x173c(%rip), %rsi      # 0x30ef
leaq 0x1748(%rip), %rcx      # 0x3102
movl $0xaa, %edx
callq 0x1070
leaq 0x17a1(%rip), %rdi      # 0x316c
leaq 0x171d(%rip), %rsi      # 0x30ef
leaq 0x1729(%rip), %rcx      # 0x3102
movl $0xa9, %edx
callq 0x1070
leaq 0x1776(%rip), %rdi      # 0x3160
leaq 0x16fe(%rip), %rsi      # 0x30ef
leaq 0x170a(%rip), %rcx      # 0x3102
movl $0xa8, %edx
callq 0x1070
leaq 0x174b(%rip), %rdi      # 0x3154
leaq 0x16df(%rip), %rsi      # 0x30ef
leaq 0x16eb(%rip), %rcx      # 0x3102
movl $0xa7, %edx
callq 0x1070
leaq 0x170e(%rip), %rdi      # 0x3136
leaq 0x16c0(%rip), %rsi      # 0x30ef
leaq 0x16cc(%rip), %rcx      # 0x3102
movl $0x65, %edx
callq 0x1070
leaq 0x16e0(%rip), %rdi      # 0x3127
leaq 0x16a1(%rip), %rsi      # 0x30ef
leaq 0x16ad(%rip), %rcx      # 0x3102
movl $0x54, %edx
callq 0x1070
leaq 0x16df(%rip), %rdi      # 0x3145
leaq 0x1682(%rip), %rsi      # 0x30ef
leaq 0x168e(%rip), %rcx      # 0x3102
movl $0x76, %edx
callq 0x1070
leaq 0x165b(%rip), %rdi      # 0x30e0
leaq 0x1663(%rip), %rsi      # 0x30ef
leaq 0x166f(%rip), %rcx      # 0x3102
movl $0x37, %edx
callq 0x1070
leaq 0x1674(%rip), %rdi      # 0x3118
leaq 0x1644(%rip), %rsi      # 0x30ef
leaq 0x1650(%rip), %rcx      # 0x3102
movl $0x42, %edx
callq 0x1070
movq %rax, %rbx
jmp 0x1ae1
movq %rax, %rbx
jmp 0x1aef
movq %rax, %rbx
jmp 0x1afd
movq %rax, %rbx
jmp 0x1b0e
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x1ae1
callq 0x1100
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x1aef
callq 0x1100
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x1afd
callq 0x1100
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x1b0e
callq 0x1100
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x1b1f
callq 0x1100
movq %rbx, %rdi
callq 0x1140