// File: /workspace/github_cpp_makefile_star2_O1/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 0x384e(%rip), %r14      # 0x4d78
movq %r14, -0xb8(%rbp)
movl $0x3e8, %ebx            # imm = 0x3E8
movl %ebx, -0xac(%rbp)
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0xa8(%rbp)
movl $0x0, -0xb0(%rbp)
movq %r14, -0xa0(%rbp)
movl %ebx, -0x94(%rbp)
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0x90(%rbp)
movl $0x0, -0x98(%rbp)
movq %r14, -0x88(%rbp)
movl $0x3e8, -0x7c(%rbp)     # imm = 0x3E8
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0x78(%rbp)
movl $0x0, -0x80(%rbp)
movq %r14, -0x70(%rbp)
movl $0x3e8, -0x64(%rbp)     # imm = 0x3E8
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0x60(%rbp)
movl $0x0, -0x68(%rbp)
movq %r14, -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 0x141a
movsd -0x40(%rbp), %xmm0
addsd 0x19f6(%rip), %xmm0     # 0x3008
decl %r14d
jne 0x15f3
cmpl $0x989681, -0xb0(%rbp)  # imm = 0x989681
jne 0x1ac5
movl $0x989680, %r14d        # imm = 0x989680
leaq -0xa0(%rbp), %rbx
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movq %rbx, %rdi
callq 0x141a
addl $-0x1, %r14d
jb 0x1634
cmpl $0x989681, -0x98(%rbp)  # imm = 0x989681
jne 0x1ae4
movl $0x1, %r13d
leaq -0x88(%rbp), %rbx
leaq -0x70(%rbp), %r14
leaq -0x58(%rbp), %r15
cmpl $0x1, %r13d
je 0x16dd
cmpl $0x2, %r13d
jne 0x1734
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 0x141a
incl %r12d
cmpl $0x989681, %r12d        # imm = 0x989681
jne 0x1682
cmpl $0x989681, -0x68(%rbp)  # imm = 0x989681
je 0x1787
jmp 0x1a68
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 0x141a
incl %r12d
cmpl $0x989681, %r12d        # imm = 0x989681
jne 0x16e0
cmpl $0x989681, -0x80(%rbp)  # imm = 0x989681
je 0x1787
jmp 0x1a87
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 0x141a
addl $-0x1, %r12d
jb 0x173a
cmpl $0x989681, -0x50(%rbp)  # imm = 0x989681
jne 0x1aa6
incl %r13d
cmpl $0x4, %r13d
jne 0x166f
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 0x18ea(%rip), %xmm0     # 0x30a8
cvtss2sd %xmm0, %xmm0
leaq -0xb8(%rbp), %rdi
movaps %xmm0, -0x40(%rbp)
callq 0x1474
movsd %xmm0, -0xd8(%rbp)
movq %r14, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x1474
movsd %xmm0, -0xd0(%rbp)
movq %r15, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x1474
movsd %xmm0, -0xc8(%rbp)
movq %r12, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x1474
movsd %xmm0, -0xc0(%rbp)
movq %r13, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x1474
cvttsd2si -0xd8(%rbp), %rax
movapd -0x40(%rbp), %xmm4
movapd %xmm4, %xmm1
addsd 0x17d4(%rip), %xmm1     # 0x3010
movsd 0x17d4(%rip), %xmm3     # 0x3018
mulsd %xmm3, %xmm1
addsd 0x17d0(%rip), %xmm4     # 0x3020
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
ucomisd %xmm1, %xmm2
jb 0x1a49
mulsd %xmm3, %xmm4
ucomisd %xmm2, %xmm4
jb 0x1a49
cvttsd2si -0xd0(%rbp), %rax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
ucomisd %xmm1, %xmm2
jb 0x1a2a
ucomisd %xmm2, %xmm4
jb 0x1a2a
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 0x1a0b
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 0x19ec
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 0x19cd
incl %ebx
cmpl $0x65, %ebx
jne 0x17af
leaq 0x344c(%rip), %rax      # 0x4d78
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x193e
callq 0x1100
leaq 0x3433(%rip), %rax      # 0x4d78
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x1957
callq 0x1100
leaq 0x341a(%rip), %rax      # 0x4d78
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x1973
callq 0x1100
leaq 0x33fe(%rip), %rax      # 0x4d78
movq %rax, -0xa0(%rbp)
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x1992
callq 0x1100
leaq 0x33df(%rip), %rax      # 0x4d78
movq %rax, -0xb8(%rbp)
movq -0xa8(%rbp), %rdi
addq $0xb8, %rsp
testq %rdi, %rdi
je 0x19c2
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 0x17b0(%rip), %rdi      # 0x3184
leaq 0x1714(%rip), %rsi      # 0x30ef
leaq 0x1720(%rip), %rcx      # 0x3102
movl $0xab, %edx
callq 0x1070
leaq 0x1785(%rip), %rdi      # 0x3178
leaq 0x16f5(%rip), %rsi      # 0x30ef
leaq 0x1701(%rip), %rcx      # 0x3102
movl $0xaa, %edx
callq 0x1070
leaq 0x175a(%rip), %rdi      # 0x316c
leaq 0x16d6(%rip), %rsi      # 0x30ef
leaq 0x16e2(%rip), %rcx      # 0x3102
movl $0xa9, %edx
callq 0x1070
leaq 0x172f(%rip), %rdi      # 0x3160
leaq 0x16b7(%rip), %rsi      # 0x30ef
leaq 0x16c3(%rip), %rcx      # 0x3102
movl $0xa8, %edx
callq 0x1070
leaq 0x1704(%rip), %rdi      # 0x3154
leaq 0x1698(%rip), %rsi      # 0x30ef
leaq 0x16a4(%rip), %rcx      # 0x3102
movl $0xa7, %edx
callq 0x1070
leaq 0x16c7(%rip), %rdi      # 0x3136
leaq 0x1679(%rip), %rsi      # 0x30ef
leaq 0x1685(%rip), %rcx      # 0x3102
movl $0x65, %edx
callq 0x1070
leaq 0x1699(%rip), %rdi      # 0x3127
leaq 0x165a(%rip), %rsi      # 0x30ef
leaq 0x1666(%rip), %rcx      # 0x3102
movl $0x54, %edx
callq 0x1070
leaq 0x1698(%rip), %rdi      # 0x3145
leaq 0x163b(%rip), %rsi      # 0x30ef
leaq 0x1647(%rip), %rcx      # 0x3102
movl $0x76, %edx
callq 0x1070
leaq 0x1614(%rip), %rdi      # 0x30e0
leaq 0x161c(%rip), %rsi      # 0x30ef
leaq 0x1628(%rip), %rcx      # 0x3102
movl $0x37, %edx
callq 0x1070
leaq 0x162d(%rip), %rdi      # 0x3118
leaq 0x15fd(%rip), %rsi      # 0x30ef
leaq 0x1609(%rip), %rcx      # 0x3102
movl $0x42, %edx
callq 0x1070
movq %rax, %rbx
jmp 0x1b33
movq %rax, %rbx
jmp 0x1b4c
movq %rax, %rbx
jmp 0x1b68
movq %rax, %rbx
jmp 0x1b87
movq %rax, %rbx
leaq 0x3257(%rip), %rax      # 0x4d78
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x1b33
callq 0x1100
leaq 0x323e(%rip), %rax      # 0x4d78
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x1b4c
callq 0x1100
leaq 0x3225(%rip), %rax      # 0x4d78
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x1b68
callq 0x1100
leaq 0x3209(%rip), %rax      # 0x4d78
movq %rax, -0xa0(%rbp)
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x1b87
callq 0x1100
leaq 0x31ea(%rip), %rax      # 0x4d78
movq %rax, -0xb8(%rbp)
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x1ba6
callq 0x1100
movq %rbx, %rdi
callq 0x1140