// File: /workspace/github_cpp_makefile_star2_O2/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 0x38b6(%rip), %rbx      # 0x4d78
movq %rbx, -0xc0(%rbp)
movl $0x3e8, %r14d           # imm = 0x3E8
movl %r14d, -0xb4(%rbp)
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0xb0(%rbp)
andl $0x0, -0xb8(%rbp)
movq %rbx, -0xa8(%rbp)
movl %r14d, -0x9c(%rbp)
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0x98(%rbp)
andl $0x0, -0xa0(%rbp)
movq %rbx, -0x90(%rbp)
movl $0x3e8, -0x84(%rbp)     # imm = 0x3E8
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0x80(%rbp)
andl $0x0, -0x88(%rbp)
movq %rbx, -0x78(%rbp)
movl $0x3e8, -0x6c(%rbp)     # imm = 0x3E8
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0x68(%rbp)
andl $0x0, -0x70(%rbp)
movq %rbx, -0x60(%rbp)
movl $0x3e8, -0x54(%rbp)     # imm = 0x3E8
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x1030
movq %rax, -0x50(%rbp)
andl $0x0, -0x58(%rbp)
xorpd %xmm0, %xmm0
movl $0x989681, %r14d        # imm = 0x989681
leaq -0xc0(%rbp), %rbx
subl $0x1, %r14d
jb 0x15ac
movq %rbx, %rdi
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0x13e0
movsd -0x40(%rbp), %xmm0
addsd 0x1a5e(%rip), %xmm0     # 0x3008
jmp 0x1585
cmpl $0x989681, -0xb8(%rbp)  # imm = 0x989681
jne 0x19b9
movl $0x989680, %r14d        # imm = 0x989680
leaq -0xa8(%rbp), %rbx
testl %r14d, %r14d
js 0x15e0
cvtsi2sd %r14d, %xmm0
movq %rbx, %rdi
callq 0x13e0
decl %r14d
jmp 0x15c9
cmpl $0x989681, -0xa0(%rbp)  # imm = 0x989681
jne 0x19d5
pushq $0x1
popq %rax
movl $0x989680, %r13d        # imm = 0x989680
leaq -0x90(%rbp), %rbx
leaq -0x78(%rbp), %r14
leaq -0x60(%rbp), %r15
cmpl $0x1, %eax
movl %eax, -0x40(%rbp)
je 0x169d
cmpl $0x2, %eax
je 0x1650
cmpl $0x4, %eax
je 0x16e5
movl $0x989680, %r12d        # imm = 0x989680
cmpl $-0x1, %r12d
je 0x168f
movl %r12d, %edi
callq 0x10c0
callq 0x1040
cltd
idivl %r13d
cvtsi2sd %edx, %xmm0
movq %r15, %rdi
callq 0x13e0
decl %r12d
jmp 0x1628
xorl %r12d, %r12d
cmpl $0x989681, %r12d        # imm = 0x989681
je 0x1681
movl %r12d, %edi
xorl $0x2, %edi
callq 0x10c0
callq 0x1040
cltd
idivl %r13d
cvtsi2sd %edx, %xmm0
movq %r14, %rdi
callq 0x13e0
incl %r12d
jmp 0x1653
cmpl $0x989681, -0x70(%rbp)  # imm = 0x989681
je 0x16db
jmp 0x18e8
cmpl $0x989681, -0x58(%rbp)  # imm = 0x989681
je 0x16db
jmp 0x18cf
xorl %r12d, %r12d
cmpl $0x989681, %r12d        # imm = 0x989681
je 0x16cb
movl %r12d, %edi
callq 0x10c0
callq 0x1040
cltd
idivl %r13d
cvtsi2sd %edx, %xmm0
movq %rbx, %rdi
callq 0x13e0
incl %r12d
jmp 0x16a0
cmpl $0x989681, -0x88(%rbp)  # imm = 0x989681
jne 0x1901
movl -0x40(%rbp), %eax
incl %eax
jmp 0x1608
movss 0x19b3(%rip), %xmm0     # 0x30a0
movss 0x19af(%rip), %xmm1     # 0x30a4
leaq -0xc0(%rbp), %rbx
leaq -0xa8(%rbp), %r14
leaq -0x90(%rbp), %r15
leaq -0x78(%rbp), %r12
leaq -0x60(%rbp), %r13
ucomiss %xmm0, %xmm1
jb 0x1887
movss %xmm0, -0x44(%rbp)
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movq %rbx, %rdi
movaps %xmm0, -0x40(%rbp)
callq 0x143a
movsd %xmm0, -0xe0(%rbp)
movq %r14, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x143a
movsd %xmm0, -0xd8(%rbp)
movq %r15, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x143a
movsd %xmm0, -0xd0(%rbp)
movq %r12, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x143a
movsd %xmm0, -0xc8(%rbp)
movq %r13, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x143a
cvttsd2si -0xe0(%rbp), %rax
movapd -0x40(%rbp), %xmm4
movapd %xmm4, %xmm1
addsd 0x1872(%rip), %xmm1     # 0x3010
movsd 0x1872(%rip), %xmm3     # 0x3018
mulsd %xmm3, %xmm1
addsd 0x186e(%rip), %xmm4     # 0x3020
cvtsi2sd %rax, %xmm2
ucomisd %xmm1, %xmm2
jb 0x191e
mulsd %xmm3, %xmm4
ucomisd %xmm2, %xmm4
jb 0x191e
cvttsd2si -0xd8(%rbp), %rax
cvtsi2sd %rax, %xmm2
ucomisd %xmm1, %xmm2
jb 0x199a
ucomisd %xmm2, %xmm4
jb 0x199a
cvttsd2si -0xd0(%rbp), %rax
cvtsi2sd %rax, %xmm2
movapd %xmm1, %xmm3
cmplepd %xmm2, %xmm3
cmplepd %xmm4, %xmm2
andpd %xmm3, %xmm2
movd %xmm2, %eax
testb $0x1, %al
je 0x197b
cvttsd2si -0xc8(%rbp), %rax
cvtsi2sd %rax, %xmm2
movapd %xmm1, %xmm3
cmplepd %xmm2, %xmm3
cmplepd %xmm4, %xmm2
andpd %xmm3, %xmm2
movd %xmm2, %eax
testb $0x1, %al
je 0x195c
cvttsd2si %xmm0, %rax
cvtsi2sd %rax, %xmm0
cmplepd %xmm0, %xmm1
cmplepd %xmm4, %xmm0
andpd %xmm1, %xmm0
movd %xmm0, %eax
testb $0x1, %al
je 0x193d
movss -0x44(%rbp), %xmm0
addss 0x1826(%rip), %xmm0     # 0x30a0
movss 0x1822(%rip), %xmm1     # 0x30a4
jmp 0x1712
leaq -0x60(%rbp), %rdi
callq 0x13c0
leaq -0x78(%rbp), %rdi
callq 0x13c0
leaq -0x90(%rbp), %rdi
callq 0x13c0
leaq -0xa8(%rbp), %rdi
callq 0x13c0
leaq -0xc0(%rbp), %rdi
callq 0x13c0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x185f(%rip), %rdi      # 0x3135
leaq 0x1802(%rip), %rsi      # 0x30df
leaq 0x180e(%rip), %rcx      # 0x30f2
pushq $0x76
jmp 0x1918
leaq 0x1837(%rip), %rdi      # 0x3126
leaq 0x17e9(%rip), %rsi      # 0x30df
leaq 0x17f5(%rip), %rcx      # 0x30f2
pushq $0x65
jmp 0x1918
leaq 0x180f(%rip), %rdi      # 0x3117
leaq 0x17d0(%rip), %rsi      # 0x30df
leaq 0x17dc(%rip), %rcx      # 0x30f2
pushq $0x54
popq %rdx
callq 0x1070
leaq 0x181f(%rip), %rdi      # 0x3144
leaq 0x17b3(%rip), %rsi      # 0x30df
leaq 0x17bf(%rip), %rcx      # 0x30f2
movl $0xa7, %edx
callq 0x1070
leaq 0x1830(%rip), %rdi      # 0x3174
leaq 0x1794(%rip), %rsi      # 0x30df
leaq 0x17a0(%rip), %rcx      # 0x30f2
movl $0xab, %edx
callq 0x1070
leaq 0x1805(%rip), %rdi      # 0x3168
leaq 0x1775(%rip), %rsi      # 0x30df
leaq 0x1781(%rip), %rcx      # 0x30f2
movl $0xaa, %edx
callq 0x1070
leaq 0x17da(%rip), %rdi      # 0x315c
leaq 0x1756(%rip), %rsi      # 0x30df
leaq 0x1762(%rip), %rcx      # 0x30f2
movl $0xa9, %edx
callq 0x1070
leaq 0x17af(%rip), %rdi      # 0x3150
leaq 0x1737(%rip), %rsi      # 0x30df
leaq 0x1743(%rip), %rcx      # 0x30f2
movl $0xa8, %edx
callq 0x1070
leaq 0x1710(%rip), %rdi      # 0x30d0
leaq 0x1718(%rip), %rsi      # 0x30df
leaq 0x1724(%rip), %rcx      # 0x30f2
pushq $0x37
jmp 0x1918
leaq 0x172c(%rip), %rdi      # 0x3108
leaq 0x16fc(%rip), %rsi      # 0x30df
leaq 0x1708(%rip), %rcx      # 0x30f2
pushq $0x42
jmp 0x1918
movq %rax, %rbx
jmp 0x1a11
movq %rax, %rbx
jmp 0x1a1a
movq %rax, %rbx
jmp 0x1a26
movq %rax, %rbx
jmp 0x1a32
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x13c0
leaq -0x78(%rbp), %rdi
callq 0x13c0
leaq -0x90(%rbp), %rdi
callq 0x13c0
leaq -0xa8(%rbp), %rdi
callq 0x13c0
leaq -0xc0(%rbp), %rdi
callq 0x13c0
movq %rbx, %rdi
callq 0x1120