// File: /workspace/github_cpp_makefile_star2_O2/ashlall[P]StreamStats/Test/QDigest_test.cpp
// Function: test_qdigest()
void test_qdigest()
{
	int n = 100; 
	int k = 5000; //compress factor, make an arbitrarily large k for testing 
					// usually the choose of k ranges from 0.3*stream_length  to 0.5*stream_length  in order to get the best query results
	long quantA,quantB,quantC,quantD,quantE,quantF,quantG,quantH;
	bool condA,condB,condC,condD,condE,condF,condG,condH;
    double upper,lower;
    
    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;

    
	QDigest a(k);
	QDigest b(k);
	QDigest c(k);
	QDigest d(k);
    QDigest e(k);
	QDigest f(k);
	QDigest g(k);
	QDigest h(k);
	
	for (double j = 0; j <= n; j++) //inserting in decreasing order
    {	
  		a.insert(j); 
    }
	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 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);
  		}
  	}
  	
  	  f.insert(random_fix1); //test corner case where n = 1
  	  g.insert(random_fix2); 
  	  h.insert(random_fix3); 
  	  
  	  bool condF1,condG1,condH1;
	  long LF = f.get_stream_size(); //test the function get_stream_size()
	  long LG = g.get_stream_size();
 	  long LH = h.get_stream_size();
      condF1 = (LF == 1);
      condG1 = (LG == 1);
	  condH1 = (LH == 1);
	  assert(condF1 == true);
	  assert(condG1 == true);
	  assert(condH1 == true);
  	
  for (float i=1;i<=100;i++)
  {
  	  double interval=i/100; //getting each 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);
  	  quantF=f.getQuantile(interval);
  	  quantG=g.getQuantile(interval);
  	  quantH=h.getQuantile(interval);
  	  
  	  lower=(interval-0.04)*n;
  	  upper=(interval+0.04)*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
  	  
  	  
  	  condF= (random_fix1 == quantF);
  	  condG= (random_fix2 == quantG);
  	  condH= (random_fix3 == quantH);
  	  //checking if the condition holds in the corner case where stream size = 1

  	  
  	  assert(condA==true);
  	  assert(condB==true);
  	  assert(condC==true);
  	  assert(condD==true);
  	  assert(condE==true);
  	  assert(condF==true);
  	  assert(condG==true);
  	  assert(condH==true);
  } 
	/*
	QDigest a(35000);
	for(int i=1; i<=100000; i++)
	{
		a.insert(i);
	}

	cout << "median:" << a.getQuantile(0.5) << endl;
	cout << "0.1: "<<a.getQuantile(0.1) << endl;
	cout << "0.3: "<<a.getQuantile(0.3) << endl;
	cout << "0.4: "<<a.getQuantile(0.4) << endl;
	cout << "0.8: "<<a.getQuantile(0.8) << endl;
	*/
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
callq 0x2050
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
cltd
idivl %ebx
movl %edx, %r15d
callq 0x2050
cltd
idivl %ebx
movl %edx, %r12d
callq 0x2050
cltd
idivl %ebx
movl %edx, -0x58(%rbp)
leaq 0x5f34(%rip), %rcx      # 0x8d70
leaq -0x3c8(%rbp), %r9
movq %rcx, -0x38(%r9)
movq %r9, -0x30(%r9)
pushq $0x1
popq %rax
movq %rax, -0x28(%r9)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%r9)
movl $0x3f800000, %edx       # imm = 0x3F800000
movl %edx, -0x10(%r9)
movupd %xmm0, -0x8(%r9)
movabsq $0x40b3880000000000, %rdi # imm = 0x40B3880000000000
movq %rdi, 0x28(%r9)
movq %rax, 0x10(%r9)
andq $0x0, 0x8(%r9)
andq $0x0, 0x30(%r9)
movl $0x3b9aca00, %esi       # imm = 0x3B9ACA00
movq %rsi, 0x18(%r9)
movq $-0x3b9aca00, %r8       # imm = 0xC4653600
movq %r8, 0x20(%r9)
leaq -0x358(%rbp), %r10
movq %rcx, -0x38(%r10)
movq %r10, -0x30(%r10)
movq %rax, -0x28(%r10)
movupd %xmm0, -0x20(%r10)
movl %edx, -0x10(%r10)
movupd %xmm0, -0x8(%r10)
movq %rdi, 0x28(%r10)
movq %rax, 0x10(%r10)
andq $0x0, 0x8(%r10)
andq $0x0, 0x30(%r10)
movq %rsi, 0x18(%r10)
leaq -0x2e8(%rbp), %r9
movq %rcx, -0x38(%r9)
movq %r9, -0x30(%r9)
movq %rax, -0x28(%r9)
movupd %xmm0, -0x20(%r9)
movl %edx, -0x10(%r9)
movupd %xmm0, -0x8(%r9)
movq %rdi, 0x28(%r9)
movq %rax, 0x10(%r9)
andq $0x0, 0x8(%r9)
movq %r8, 0x20(%r10)
andq $0x0, 0x30(%r9)
leaq -0x278(%rbp), %r10
movq %rcx, -0x38(%r10)
movq %r10, -0x30(%r10)
movq %rax, -0x28(%r10)
movupd %xmm0, -0x20(%r10)
movl %edx, -0x10(%r10)
movupd %xmm0, -0x8(%r10)
movq %rdi, 0x28(%r10)
movq %rax, 0x10(%r10)
andq $0x0, 0x8(%r10)
movq %rsi, 0x18(%r9)
andq $0x0, 0x30(%r10)
leaq -0x208(%rbp), %r11
movq %rcx, -0x38(%r11)
movq %r11, -0x30(%r11)
movq %rax, -0x28(%r11)
movupd %xmm0, -0x20(%r11)
movl %edx, -0x10(%r11)
movupd %xmm0, -0x8(%r11)
movq %rdi, 0x28(%r11)
movq %rax, 0x10(%r11)
andq $0x0, 0x8(%r11)
movq %r8, 0x20(%r9)
andq $0x0, 0x30(%r11)
movq %rsi, 0x18(%r10)
movq %r8, 0x20(%r10)
movq %rsi, 0x18(%r11)
movq %r8, 0x20(%r11)
leaq -0x198(%rbp), %r9
movq %rcx, -0x38(%r9)
movq %r9, -0x30(%r9)
movq %rax, -0x28(%r9)
movupd %xmm0, -0x20(%r9)
movl %edx, -0x10(%r9)
movupd %xmm0, -0x8(%r9)
movq %rdi, 0x28(%r9)
movq %rax, 0x10(%r9)
andq $0x0, 0x8(%r9)
andq $0x0, 0x30(%r9)
movq %rsi, 0x18(%r9)
leaq -0x128(%rbp), %r10
movq %rcx, -0x38(%r10)
movq %r10, -0x30(%r10)
movq %rax, -0x28(%r10)
movupd %xmm0, -0x20(%r10)
movl %edx, -0x10(%r10)
movupd %xmm0, -0x8(%r10)
movq %rdi, 0x28(%r10)
movq %rax, 0x10(%r10)
andq $0x0, 0x8(%r10)
movq %r8, 0x20(%r9)
andq $0x0, 0x30(%r10)
leaq -0xb8(%rbp), %r9
movq %rcx, -0x38(%r9)
movq %r9, -0x30(%r9)
movq %rax, -0x28(%r9)
movupd %xmm0, -0x20(%r9)
movl %edx, -0x10(%r9)
movupd %xmm0, -0x8(%r9)
movq %rdi, 0x28(%r9)
movq %rax, 0x10(%r9)
andq $0x0, 0x8(%r9)
movq %rsi, 0x18(%r10)
andq $0x0, 0x30(%r9)
movq %r8, 0x20(%r10)
movq %rsi, 0x18(%r9)
movq %r8, 0x20(%r9)
xorpd %xmm1, %xmm1
leaq -0x400(%rbp), %rbx
movsd 0x2fdf(%rip), %xmm0     # 0x6038
ucomisd %xmm1, %xmm0
jb 0x307f
movq %rbx, %rdi
movsd %xmm1, -0x40(%rbp)
movapd %xmm1, %xmm0
callq 0x24ac
movsd -0x40(%rbp), %xmm1
addsd 0x2fc3(%rip), %xmm1     # 0x6040
jmp 0x3051
cmpl $0x65, -0x398(%rbp)
jne 0x35cc
pushq $0x64
popq %r14
leaq -0x390(%rbp), %rbx
testl %r14d, %r14d
js 0x30ae
cvtsi2sd %r14d, %xmm0
movq %rbx, %rdi
callq 0x24ac
decl %r14d
jmp 0x3097
movl %r12d, -0x48(%rbp)
movl %r15d, -0x50(%rbp)
cmpl $0x65, -0x328(%rbp)
jne 0x35e8
pushq $0x1
popq %rax
pushq $0x64
popq %r15
leaq -0x320(%rbp), %r12
leaq -0x2b0(%rbp), %r13
leaq -0x240(%rbp), %rbx
cmpl $0x1, %eax
movl %eax, -0x40(%rbp)
je 0x3152
cmpl $0x2, %eax
je 0x3124
cmpl $0x4, %eax
je 0x31b0
movl %r15d, %r14d
cmpl $-0x1, %r14d
je 0x318b
movl %r14d, %edi
callq 0x2110
callq 0x2050
cltd
idivl %r15d
cvtsi2sd %edx, %xmm0
movq %rbx, %rdi
callq 0x24ac
decl %r14d
jmp 0x30f8
xorl %r14d, %r14d
cmpl $0x65, %r14d
je 0x317d
movl %r14d, %edi
xorl $0x2, %edi
callq 0x2110
callq 0x2050
cltd
idivl %r15d
cvtsi2sd %edx, %xmm0
movq %r13, %rdi
callq 0x24ac
incl %r14d
jmp 0x3127
xorl %r14d, %r14d
cmpl $0x65, %r14d
je 0x3199
movl %r14d, %edi
callq 0x2110
callq 0x2050
cltd
idivl %r15d
cvtsi2sd %edx, %xmm0
movq %r12, %rdi
callq 0x24ac
incl %r14d
jmp 0x3155
cmpl $0x65, -0x248(%rbp)
je 0x31a6
jmp 0x34b7
cmpl $0x65, -0x1d8(%rbp)
je 0x31a6
jmp 0x3485
cmpl $0x65, -0x2b8(%rbp)
jne 0x349e
movl -0x40(%rbp), %eax
incl %eax
jmp 0x30df
movl -0x50(%rbp), %ebx
cvtsi2sd %ebx, %xmm0
leaq -0x1d0(%rbp), %rdi
callq 0x24ac
movl -0x48(%rbp), %r14d
movl -0x58(%rbp), %r15d
cvtsi2sd %r14d, %xmm0
leaq -0x160(%rbp), %rdi
callq 0x24ac
cvtsi2sd %r15d, %xmm0
leaq -0xf0(%rbp), %rdi
callq 0x24ac
cmpq $0x1, -0x168(%rbp)
jne 0x3604
cmpq $0x1, -0xf8(%rbp)
jne 0x3620
cmpq $0x1, -0x88(%rbp)
jne 0x363c
movslq %ebx, %r12
movslq %r14d, %r13
movslq %r15d, %rbx
movss 0x2e30(%rip), %xmm0     # 0x6058
movss 0x2e2c(%rip), %xmm1     # 0x605c
leaq -0x160(%rbp), %r14
leaq -0xf0(%rbp), %r15
ucomiss %xmm0, %xmm1
jb 0x3413
movss %xmm0, -0x5c(%rbp)
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq -0x400(%rbp), %rdi
movaps %xmm0, -0x40(%rbp)
callq 0x2642
movsd %xmm0, -0x58(%rbp)
leaq -0x390(%rbp), %rdi
movaps -0x40(%rbp), %xmm0
callq 0x2642
movsd %xmm0, -0x50(%rbp)
leaq -0x320(%rbp), %rdi
movaps -0x40(%rbp), %xmm0
callq 0x2642
movsd %xmm0, -0x48(%rbp)
leaq -0x2b0(%rbp), %rdi
movaps -0x40(%rbp), %xmm0
callq 0x2642
movsd %xmm0, -0x80(%rbp)
leaq -0x240(%rbp), %rdi
movaps -0x40(%rbp), %xmm0
callq 0x2642
movsd %xmm0, -0x78(%rbp)
leaq -0x1d0(%rbp), %rdi
movaps -0x40(%rbp), %xmm0
callq 0x2642
movsd %xmm0, -0x70(%rbp)
movq %r14, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x2642
movsd %xmm0, -0x68(%rbp)
movq %r15, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x2642
cvttsd2si -0x58(%rbp), %rax
movapd -0x40(%rbp), %xmm4
movapd %xmm4, %xmm1
addsd 0x2d42(%rip), %xmm1     # 0x6048
movsd 0x2d2a(%rip), %xmm3     # 0x6038
mulsd %xmm3, %xmm1
addsd 0x2d36(%rip), %xmm4     # 0x6050
cvtsi2sd %rax, %xmm2
ucomisd %xmm1, %xmm2
jb 0x3531
mulsd %xmm3, %xmm4
ucomisd %xmm2, %xmm4
jb 0x3531
cvttsd2si -0x50(%rbp), %rax
cvtsi2sd %rax, %xmm2
ucomisd %xmm1, %xmm2
jb 0x3512
ucomisd %xmm2, %xmm4
jb 0x3512
cvttsd2si -0x48(%rbp), %rax
cvtsi2sd %rax, %xmm2
movapd %xmm1, %xmm3
cmplepd %xmm2, %xmm3
cmplepd %xmm4, %xmm2
andpd %xmm3, %xmm2
movd %xmm2, %eax
testb $0x1, %al
je 0x34f3
cvttsd2si -0x80(%rbp), %rax
cvtsi2sd %rax, %xmm2
movapd %xmm1, %xmm3
cmplepd %xmm2, %xmm3
cmplepd %xmm4, %xmm2
andpd %xmm3, %xmm2
movd %xmm2, %eax
testb $0x1, %al
je 0x34d4
cvttsd2si -0x78(%rbp), %rax
cvtsi2sd %rax, %xmm2
cmplepd %xmm2, %xmm1
cmplepd %xmm4, %xmm2
andpd %xmm1, %xmm2
movd %xmm2, %eax
testb $0x1, %al
je 0x35ad
cvttsd2si -0x70(%rbp), %rax
cmpq %rax, %r12
movss 0x2c7e(%rip), %xmm1     # 0x605c
jne 0x358e
cvttsd2si -0x68(%rbp), %rax
cmpq %rax, %r13
jne 0x356f
cvttsd2si %xmm0, %rax
cmpq %rax, %rbx
jne 0x3550
movss -0x5c(%rbp), %xmm0
addss 0x2c4a(%rip), %xmm0     # 0x6058
jmp 0x323e
leaq -0xf0(%rbp), %rdi
callq 0x3824
leaq -0x160(%rbp), %rdi
callq 0x3824
leaq -0x1d0(%rbp), %rdi
callq 0x3824
leaq -0x240(%rbp), %rdi
callq 0x3824
leaq -0x2b0(%rbp), %rdi
callq 0x3824
leaq -0x320(%rbp), %rdi
callq 0x3824
leaq -0x390(%rbp), %rdi
callq 0x3824
leaq -0x400(%rbp), %rdi
callq 0x3824
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2c5e(%rip), %rdi      # 0x60ea
leaq 0x2c05(%rip), %rsi      # 0x6098
leaq 0x2c0f(%rip), %rcx      # 0x60a9
pushq $0x68
jmp 0x34ce
leaq 0x2c27(%rip), %rdi      # 0x60cc
leaq 0x2bec(%rip), %rsi      # 0x6098
leaq 0x2bf6(%rip), %rcx      # 0x60a9
pushq $0x46
jmp 0x34ce
leaq 0x2c1d(%rip), %rdi      # 0x60db
leaq 0x2bd3(%rip), %rsi      # 0x6098
leaq 0x2bdd(%rip), %rcx      # 0x60a9
pushq $0x57
popq %rdx
callq 0x20d0
leaq 0x2c6f(%rip), %rdi      # 0x614a
leaq 0x2bb6(%rip), %rsi      # 0x6098
leaq 0x2bc0(%rip), %rcx      # 0x60a9
movl $0xa0, %edx
callq 0x20d0
leaq 0x2c44(%rip), %rdi      # 0x613e
leaq 0x2b97(%rip), %rsi      # 0x6098
leaq 0x2ba1(%rip), %rcx      # 0x60a9
movl $0x9f, %edx
callq 0x20d0
leaq 0x2c19(%rip), %rdi      # 0x6132
leaq 0x2b78(%rip), %rsi      # 0x6098
leaq 0x2b82(%rip), %rcx      # 0x60a9
movl $0x9e, %edx
callq 0x20d0
leaq 0x2bee(%rip), %rdi      # 0x6126
leaq 0x2b59(%rip), %rsi      # 0x6098
leaq 0x2b63(%rip), %rcx      # 0x60a9
movl $0x9d, %edx
callq 0x20d0
leaq 0x2c23(%rip), %rdi      # 0x617a
leaq 0x2b3a(%rip), %rsi      # 0x6098
leaq 0x2b44(%rip), %rcx      # 0x60a9
movl $0xa4, %edx
callq 0x20d0
leaq 0x2bf8(%rip), %rdi      # 0x616e
leaq 0x2b1b(%rip), %rsi      # 0x6098
leaq 0x2b25(%rip), %rcx      # 0x60a9
movl $0xa3, %edx
callq 0x20d0
leaq 0x2bcd(%rip), %rdi      # 0x6162
leaq 0x2afc(%rip), %rsi      # 0x6098
leaq 0x2b06(%rip), %rcx      # 0x60a9
movl $0xa2, %edx
callq 0x20d0
leaq 0x2ba2(%rip), %rdi      # 0x6156
leaq 0x2add(%rip), %rsi      # 0x6098
leaq 0x2ae7(%rip), %rcx      # 0x60a9
movl $0xa1, %edx
callq 0x20d0
leaq 0x2ab6(%rip), %rdi      # 0x6089
leaq 0x2abe(%rip), %rsi      # 0x6098
leaq 0x2ac8(%rip), %rcx      # 0x60a9
pushq $0x2b
jmp 0x34ce
leaq 0x2ace(%rip), %rdi      # 0x60bd
leaq 0x2aa2(%rip), %rsi      # 0x6098
leaq 0x2aac(%rip), %rcx      # 0x60a9
pushq $0x34
jmp 0x34ce
leaq 0x2aee(%rip), %rdi      # 0x60f9
leaq 0x2a86(%rip), %rsi      # 0x6098
leaq 0x2a90(%rip), %rcx      # 0x60a9
pushq $0x77
jmp 0x34ce
leaq 0x2ae1(%rip), %rdi      # 0x6108
leaq 0x2a6a(%rip), %rsi      # 0x6098
leaq 0x2a74(%rip), %rcx      # 0x60a9
pushq $0x78
jmp 0x34ce
leaq 0x2ad4(%rip), %rdi      # 0x6117
leaq 0x2a4e(%rip), %rsi      # 0x6098
leaq 0x2a58(%rip), %rcx      # 0x60a9
pushq $0x79
jmp 0x34ce
jmp 0x3664
jmp 0x3664
jmp 0x3664
jmp 0x3664
jmp 0x3664
jmp 0x3664
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0x3824
leaq -0x160(%rbp), %rdi
callq 0x3824
leaq -0x1d0(%rbp), %rdi
callq 0x3824
leaq -0x240(%rbp), %rdi
callq 0x3824
leaq -0x2b0(%rbp), %rdi
callq 0x3824
leaq -0x320(%rbp), %rdi
callq 0x3824
leaq -0x390(%rbp), %rdi
callq 0x3824
leaq -0x400(%rbp), %rdi
callq 0x3824
movq %rbx, %rdi
callq 0x21e0