// File: /workspace/github_cpp_makefile_star2_O2/ashlall[P]StreamStats/Test/QDigest_test_Double.cpp
// Function: test_qdigetDouble()
void test_qdigetDouble()
{
	int n = 50;
	int k = 5000; //make an arbitrarily large k for testing 	
				//Compress factor: usually the choice of k ranges from 0.3*stream_length to 0.5stream_length  in order to get the best query results

					
	double quantA,quantB,quantC,quantD,quantE,quantF,quantG,quantH;
	bool condA,condB,condC,condD,condE,condF,condG,condH;
    double upper,lower;
    
    double random_fix1 = rand()% RAND_MAX + 0.12345; //used to test corner case where n = 1
    double random_fix2 = rand()% RAND_MAX + 0.12345;
    double random_fix3 = rand()% RAND_MAX + 0.12345;

	QDigestDouble a(k);
	QDigestDouble b(k);
	QDigestDouble c(k);
	QDigestDouble d(k);
    QDigestDouble e(k);
	QDigestDouble f(k);
	QDigestDouble g(k);
	QDigestDouble h(k);
		
	for (double i = 0; i <= n; i = i + 0.1) //inserting in increasing order
    {	
  		a.insert(i); 
    }
	bool condA1;
	long LA = a.get_stream_size(); //test the function get_stream_size()
	condA1= (LA == n/0.1);
	assert(condA1 == true);
	   
	   
	for (double j = n; j >= 0; j = j - 0.1) //inserting in decreasing order
    {	
  		b.insert(j); 
    }
    bool condB1;
	long LB = b.get_stream_size(); //test the function get_stream_size()
	condB1= (LB == n/0.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);
  				double rand_num=rand()%n + 0.5;
  				//cout << rand_num << " ";
  				c.insert(rand_num); //inserting float number from 0 to n
  			 }
  			 //cout << ""<<endl;
  			 bool condC1;
			 long 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);
  				double rand_num=rand()%n + 0.5;
  				//cout << rand_num << " ";
  				d.insert(rand_num); //inserting float number from 0 to n
  			 }  
  			 //cout << ""<<endl;
  			 bool condD1;
			 long 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);
  				double rand_num=rand()%n + 0.5;
  				//cout << rand_num << " ";
  				e.insert(rand_num); //inserting float number from 0 to n
  			 }  
  			 //cout <<""<<endl;
  			 bool condE1;
			 long 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);
	//random floating number from MIN ~ MAX are needed !!!!!
	

    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.06)*n;
  	  upper=(interval+0.06)*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= ((quantF <= 1.0001*random_fix1) && (quantF >= 0.9999*random_fix1));
  	  condG= ((quantG <= 1.0001*random_fix2) && (quantG >= 0.9999*random_fix2));
  	  condH= ((quantH <= 1.0001*random_fix3) && (quantH >= 0.9999*random_fix3));
  	  
  	  
  	  //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);
  } 

	/*  
		QDigestDouble a(500);
		for(double i=1; i<=1000; i = i + 0.5)
		{
			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;
		cout << "hi" <<endl; 
   */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4e8, %rsp            # imm = 0x4E8
callq 0x2050
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
cltd
idivl %r15d
movl %edx, %ebx
callq 0x2050
cltd
idivl %r15d
movl %edx, %r14d
callq 0x2050
cltd
idivl %r15d
movl %edx, %r15d
leaq -0x510(%rbp), %rdi
movsd 0x31b9(%rip), %xmm0     # 0x6050
callq 0x3936
leaq -0x490(%rbp), %rdi
movsd 0x31a5(%rip), %xmm0     # 0x6050
callq 0x3936
leaq -0x410(%rbp), %rdi
movsd 0x3191(%rip), %xmm0     # 0x6050
callq 0x3936
leaq -0x390(%rbp), %rdi
movsd 0x317d(%rip), %xmm0     # 0x6050
callq 0x3936
leaq -0x310(%rbp), %rdi
movsd 0x3169(%rip), %xmm0     # 0x6050
callq 0x3936
leaq -0x290(%rbp), %rdi
movsd 0x3155(%rip), %xmm0     # 0x6050
callq 0x3936
leaq -0x210(%rbp), %rdi
movsd 0x3141(%rip), %xmm0     # 0x6050
callq 0x3936
leaq -0x190(%rbp), %rdi
movsd 0x312d(%rip), %xmm0     # 0x6050
callq 0x3936
cvtsi2sd %ebx, %xmm1
movsd 0x3114(%rip), %xmm0     # 0x6048
addsd %xmm0, %xmm1
movapd %xmm1, -0x80(%rbp)
cvtsi2sd %r14d, %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, -0x70(%rbp)
cvtsi2sd %r15d, %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, -0x60(%rbp)
xorpd %xmm1, %xmm1
leaq -0x510(%rbp), %rbx
movsd 0x30ec(%rip), %xmm0     # 0x6058
ucomisd %xmm1, %xmm0
jb 0x2f92
movq %rbx, %rdi
movsd %xmm1, -0x40(%rbp)
movapd %xmm1, %xmm0
callq 0x3972
movsd -0x40(%rbp), %xmm1
addsd 0x30d0(%rip), %xmm1     # 0x6060
jmp 0x2f64
cmpq $0x1f4, -0x4a8(%rbp) # imm = 0x1F4
jne 0x35b7
leaq -0x490(%rbp), %rbx
movsd 0x30a6(%rip), %xmm0     # 0x6058
ucomisd 0x30de(%rip), %xmm0     # 0x6098
jb 0x2fd8
movq %rbx, %rdi
movsd %xmm0, -0x40(%rbp)
callq 0x3972
movsd -0x40(%rbp), %xmm0
addsd 0x3092(%rip), %xmm0     # 0x6068
jmp 0x2fb2
cmpq $0x1f4, -0x428(%rbp) # imm = 0x1F4
jne 0x35d3
pushq $0x1
popq %rax
pushq $0x32
popq %r13
leaq -0x410(%rbp), %rbx
leaq -0x390(%rbp), %r14
leaq -0x310(%rbp), %r15
cmpl $0x1, %eax
movl %eax, -0x40(%rbp)
je 0x3088
cmpl $0x2, %eax
je 0x3052
cmpl $0x4, %eax
je 0x30f1
movl %r13d, %r12d
cmpl $-0x1, %r12d
je 0x30ca
movl %r12d, %edi
callq 0x2150
callq 0x2050
cltd
idivl %r13d
cvtsi2sd %edx, %xmm0
addsd 0x302b(%rip), %xmm0     # 0x6070
movq %r15, %rdi
callq 0x3972
decl %r12d
jmp 0x301e
xorl %r12d, %r12d
cmpl $0x33, %r12d
je 0x30bb
movl %r12d, %edi
xorl $0x2, %edi
callq 0x2150
callq 0x2050
cltd
idivl %r13d
cvtsi2sd %edx, %xmm0
addsd 0x2ff5(%rip), %xmm0     # 0x6070
movq %r14, %rdi
callq 0x3972
incl %r12d
jmp 0x3055
xorl %r12d, %r12d
cmpl $0x33, %r12d
je 0x30d9
movl %r12d, %edi
callq 0x2150
callq 0x2050
cltd
idivl %r13d
cvtsi2sd %edx, %xmm0
addsd 0x2fc2(%rip), %xmm0     # 0x6070
movq %rbx, %rdi
callq 0x3972
incl %r12d
jmp 0x308b
cmpq $0x33, -0x328(%rbp)
je 0x30e7
jmp 0x34a2
cmpq $0x33, -0x2a8(%rbp)
je 0x30e7
jmp 0x3470
cmpq $0x33, -0x3a8(%rbp)
jne 0x3489
movl -0x40(%rbp), %eax
incl %eax
jmp 0x3005
leaq -0x290(%rbp), %rdi
movapd -0x80(%rbp), %xmm0
callq 0x3972
leaq -0x210(%rbp), %rdi
movapd -0x70(%rbp), %xmm0
callq 0x3972
leaq -0x190(%rbp), %rdi
movapd -0x60(%rbp), %xmm0
callq 0x3972
cmpq $0x1, -0x228(%rbp)
jne 0x35ef
cmpq $0x1, -0x1a8(%rbp)
jne 0x360b
cmpq $0x1, -0x128(%rbp)
jne 0x3627
movsd 0x2f22(%rip), %xmm2     # 0x6078
movapd -0x80(%rbp), %xmm1
movapd %xmm1, %xmm0
mulsd %xmm2, %xmm0
movapd %xmm0, -0xc0(%rbp)
movsd 0x2f0d(%rip), %xmm0     # 0x6080
mulsd %xmm0, %xmm1
movapd %xmm1, -0x80(%rbp)
movapd -0x70(%rbp), %xmm1
movapd %xmm1, %xmm3
mulsd %xmm2, %xmm3
movapd %xmm3, -0xb0(%rbp)
mulsd %xmm0, %xmm1
movapd %xmm1, -0x70(%rbp)
movapd -0x60(%rbp), %xmm1
mulsd %xmm1, %xmm2
movapd %xmm2, -0xa0(%rbp)
mulsd %xmm0, %xmm1
movapd %xmm1, -0x60(%rbp)
movss 0x2f0c(%rip), %xmm0     # 0x60c8
movss 0x2f08(%rip), %xmm1     # 0x60cc
leaq -0x390(%rbp), %r12
leaq -0x310(%rbp), %r13
leaq -0x290(%rbp), %rbx
leaq -0x210(%rbp), %r14
leaq -0x190(%rbp), %r15
ucomiss %xmm0, %xmm1
jb 0x33fe
movss %xmm0, -0x44(%rbp)
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq -0x510(%rbp), %rdi
movaps %xmm0, -0x40(%rbp)
callq 0x39dc
movsd %xmm0, -0x90(%rbp)
leaq -0x490(%rbp), %rdi
movaps -0x40(%rbp), %xmm0
callq 0x39dc
movsd %xmm0, -0x88(%rbp)
leaq -0x410(%rbp), %rdi
movaps -0x40(%rbp), %xmm0
callq 0x39dc
movaps %xmm0, -0x110(%rbp)
movq %r12, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x39dc
movaps %xmm0, -0x100(%rbp)
movq %r13, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x39dc
movaps %xmm0, -0xf0(%rbp)
movq %rbx, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x39dc
movaps %xmm0, -0xe0(%rbp)
movq %r14, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x39dc
movaps %xmm0, -0xd0(%rbp)
movq %r15, %rdi
movaps -0x40(%rbp), %xmm0
callq 0x39dc
movapd -0x40(%rbp), %xmm3
movapd %xmm3, %xmm1
addsd 0x2ddb(%rip), %xmm1     # 0x6088
movsd 0x2da3(%rip), %xmm2     # 0x6058
mulsd %xmm2, %xmm1
addsd 0x2dcf(%rip), %xmm3     # 0x6090
movsd -0x90(%rbp), %xmm4
ucomisd %xmm1, %xmm4
jb 0x351c
mulsd %xmm2, %xmm3
ucomisd %xmm4, %xmm3
jb 0x351c
movsd -0x88(%rbp), %xmm2
ucomisd %xmm1, %xmm2
jb 0x34fd
ucomisd %xmm2, %xmm3
jb 0x34fd
movapd %xmm1, %xmm2
movapd -0x110(%rbp), %xmm4
cmplepd %xmm4, %xmm2
cmplepd %xmm3, %xmm4
andpd %xmm2, %xmm4
movd %xmm4, %eax
testb $0x1, %al
je 0x34de
movapd %xmm1, %xmm2
movapd -0x100(%rbp), %xmm4
cmplepd %xmm4, %xmm2
cmplepd %xmm3, %xmm4
andpd %xmm2, %xmm4
movd %xmm4, %eax
testb $0x1, %al
je 0x34bf
movapd -0xf0(%rbp), %xmm2
cmplepd %xmm2, %xmm1
cmplepd %xmm3, %xmm2
andpd %xmm1, %xmm2
movd %xmm2, %eax
testb $0x1, %al
je 0x3598
movapd -0x80(%rbp), %xmm1
movapd -0xe0(%rbp), %xmm2
cmplepd %xmm2, %xmm1
cmplepd -0xc0(%rbp), %xmm2
andpd %xmm1, %xmm2
movd %xmm2, %eax
testb $0x1, %al
je 0x3579
movapd -0x70(%rbp), %xmm1
movapd -0xd0(%rbp), %xmm2
cmplepd %xmm2, %xmm1
cmplepd -0xb0(%rbp), %xmm2
andpd %xmm1, %xmm2
movd %xmm2, %eax
testb $0x1, %al
je 0x355a
movapd -0x60(%rbp), %xmm1
cmplepd %xmm0, %xmm1
cmplepd -0xa0(%rbp), %xmm0
andpd %xmm1, %xmm0
movd %xmm0, %eax
testb $0x1, %al
je 0x353b
movss -0x44(%rbp), %xmm0
addss 0x2cd7(%rip), %xmm0     # 0x60c8
movss 0x2cd3(%rip), %xmm1     # 0x60cc
jmp 0x31e7
leaq -0x190(%rbp), %rdi
callq 0x3a12
leaq -0x210(%rbp), %rdi
callq 0x3a12
leaq -0x290(%rbp), %rdi
callq 0x3a12
leaq -0x310(%rbp), %rdi
callq 0x3a12
leaq -0x390(%rbp), %rdi
callq 0x3a12
leaq -0x410(%rbp), %rdi
callq 0x3a12
leaq -0x490(%rbp), %rdi
callq 0x3a12
leaq -0x510(%rbp), %rdi
callq 0x3a12
addq $0x4e8, %rsp            # imm = 0x4E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2cf7(%rip), %rdi      # 0x616e
leaq 0x2c92(%rip), %rsi      # 0x6110
leaq 0x2ca3(%rip), %rcx      # 0x6128
pushq $0x69
jmp 0x34b9
leaq 0x2cc0(%rip), %rdi      # 0x6150
leaq 0x2c79(%rip), %rsi      # 0x6110
leaq 0x2c8a(%rip), %rcx      # 0x6128
pushq $0x47
jmp 0x34b9
leaq 0x2cb6(%rip), %rdi      # 0x615f
leaq 0x2c60(%rip), %rsi      # 0x6110
leaq 0x2c71(%rip), %rcx      # 0x6128
pushq $0x58
popq %rdx
callq 0x20e0
leaq 0x2d08(%rip), %rdi      # 0x61ce
leaq 0x2c43(%rip), %rsi      # 0x6110
leaq 0x2c54(%rip), %rcx      # 0x6128
movl $0xa5, %edx
callq 0x20e0
leaq 0x2cdd(%rip), %rdi      # 0x61c2
leaq 0x2c24(%rip), %rsi      # 0x6110
leaq 0x2c35(%rip), %rcx      # 0x6128
movl $0xa4, %edx
callq 0x20e0
leaq 0x2cb2(%rip), %rdi      # 0x61b6
leaq 0x2c05(%rip), %rsi      # 0x6110
leaq 0x2c16(%rip), %rcx      # 0x6128
movl $0xa3, %edx
callq 0x20e0
leaq 0x2c87(%rip), %rdi      # 0x61aa
leaq 0x2be6(%rip), %rsi      # 0x6110
leaq 0x2bf7(%rip), %rcx      # 0x6128
movl $0xa2, %edx
callq 0x20e0
leaq 0x2cbc(%rip), %rdi      # 0x61fe
leaq 0x2bc7(%rip), %rsi      # 0x6110
leaq 0x2bd8(%rip), %rcx      # 0x6128
movl $0xa9, %edx
callq 0x20e0
leaq 0x2c91(%rip), %rdi      # 0x61f2
leaq 0x2ba8(%rip), %rsi      # 0x6110
leaq 0x2bb9(%rip), %rcx      # 0x6128
movl $0xa8, %edx
callq 0x20e0
leaq 0x2c66(%rip), %rdi      # 0x61e6
leaq 0x2b89(%rip), %rsi      # 0x6110
leaq 0x2b9a(%rip), %rcx      # 0x6128
movl $0xa7, %edx
callq 0x20e0
leaq 0x2c3b(%rip), %rdi      # 0x61da
leaq 0x2b6a(%rip), %rsi      # 0x6110
leaq 0x2b7b(%rip), %rcx      # 0x6128
movl $0xa6, %edx
callq 0x20e0
leaq 0x2b43(%rip), %rdi      # 0x6101
leaq 0x2b4b(%rip), %rsi      # 0x6110
leaq 0x2b5c(%rip), %rcx      # 0x6128
pushq $0x2a
jmp 0x34b9
leaq 0x2b67(%rip), %rdi      # 0x6141
leaq 0x2b2f(%rip), %rsi      # 0x6110
leaq 0x2b40(%rip), %rcx      # 0x6128
pushq $0x34
jmp 0x34b9
leaq 0x2b87(%rip), %rdi      # 0x617d
leaq 0x2b13(%rip), %rsi      # 0x6110
leaq 0x2b24(%rip), %rcx      # 0x6128
pushq $0x79
jmp 0x34b9
leaq 0x2b7a(%rip), %rdi      # 0x618c
leaq 0x2af7(%rip), %rsi      # 0x6110
leaq 0x2b08(%rip), %rcx      # 0x6128
pushq $0x7a
jmp 0x34b9
leaq 0x2b6d(%rip), %rdi      # 0x619b
leaq 0x2adb(%rip), %rsi      # 0x6110
leaq 0x2aec(%rip), %rcx      # 0x6128
pushq $0x7b
jmp 0x34b9
movq %rax, %rbx
jmp 0x3681
movq %rax, %rbx
jmp 0x368d
movq %rax, %rbx
jmp 0x3699
movq %rax, %rbx
jmp 0x36a5
movq %rax, %rbx
jmp 0x36b1
movq %rax, %rbx
jmp 0x36bd
movq %rax, %rbx
jmp 0x36c9
jmp 0x3672
jmp 0x3672
jmp 0x3672
jmp 0x3672
jmp 0x3672
jmp 0x3672
movq %rax, %rbx
leaq -0x190(%rbp), %rdi
callq 0x3a12
leaq -0x210(%rbp), %rdi
callq 0x3a12
leaq -0x290(%rbp), %rdi
callq 0x3a12
leaq -0x310(%rbp), %rdi
callq 0x3a12
leaq -0x390(%rbp), %rdi
callq 0x3a12
leaq -0x410(%rbp), %rdi
callq 0x3a12
leaq -0x490(%rbp), %rdi
callq 0x3a12
leaq -0x510(%rbp), %rdi
callq 0x3a12
movq %rbx, %rdi
callq 0x2230