// File: /workspace/github_cpp_makefile_star2_O3/ashlall[P]StreamStats/Test/Chi_Square_test.cpp
// Function: test_chi_square_1st()
void test_chi_square_1st() //One-sample test
{
 	int sketch_method = 1;
	cout << "Enter the number 1-4 to choose sketch method that you want to use: "<<endl;
	cout << "1. Greenwald sketch/default." <<endl;
	cout << "2. Q-Digest sketch." <<endl;
	cout << "3. Reservoir Sampling sketch." <<endl;
	cout << "4. Count-Min Sketch." <<endl;
	cin >> sketch_method;

 	int stream_size;
 	cout << "Enter the stream size: "<<endl;
	cin >> stream_size;

	int sample_size;
	cout << "Enter the memory capacity for the sample size: "<<endl;
 	cin >> sample_size;
  
	int k;
 	cout << "Enter the number of bins you want to use: " <<endl;
 	cin >> k;

	double mean, SD;
	cout << "Enter the mean of the normal distribution you want to compare against: "<<endl;
	cin >> mean;
	cout << "Enter the standard deviation of the normal distribution you want to compare against: "<<endl;
	cin >> SD;

	ChiSquareContinuous b(sample_size, sketch_method); //ChiSquare b(memory, sketch method);
	ChiSquareContinuous b1(sample_size, sketch_method);
	ChiSquareContinuous b2(sample_size, sketch_method);

 	double item;
	double chiEstimated;
  
	double N=0;
	double *items=new double[stream_size];
	default_random_engine generator(5);
	normal_distribution<double> distribution(mean,SD);
	for (int i=0; i<stream_size; i++) 
	{
    		item = distribution(generator);
    		N++;
    		items[i]=item;
  		b.insert(item);
  		b1.insert(item);
  		b2.insert(item);
    	}
    	chiEstimated = b.calculate_statistic_ifNormal(k,mean,SD);
    
    
    	double *Upper=b.get_upper();
    	double *Lower=b.get_lower();
    	double E=N/k;
    	double chiActual=0, chiActual2 = 0;
    /*timeval timeBefore, timeAfter;
    long diffSeconds, diffUSeconds;
    gettimeofday(&timeBefore, NULL);*/
    	for (int i=1;i<=k;i++)
   	{		
      		double O=0;
      		for(int j=0;j<stream_size;j++)
    		{
    	    	 	if(( items[j]<=Upper[i]) && (items[j]>=Lower[i]))
		        	O++;
    	    	}
      	    	double lambda= fabs(O-E);
    	    	chiActual=chiActual+((lambda*lambda)/E);
    	}

    /*gettimeofday(&timeAfter, NULL);
    diffSeconds = timeAfter.tv_sec - timeBefore.tv_sec;
    diffUSeconds = timeAfter.tv_usec - timeBefore.tv_usec;
    cout << "1st way: " << diffSeconds + diffUSeconds/1000000.0 << endl;

    gettimeofday(&timeBefore, NULL);
    int *frequencies = get_frequencies(Upper, Lower, items, k, stream_size);
    for (int i = 1; i <= k; i++)
      { 
	chiActual2 += (frequencies[i] - E) * (frequencies[i] - E)/E;
	}*/
    /*gettimeofday(&timeAfter, NULL);
    diffSeconds= timeAfter.tv_sec - timeBefore.tv_sec;
    diffUSeconds = timeAfter.tv_usec - timeBefore.tv_usec;
    cout << "2nd way: "<< diffSeconds + diffUSeconds/1000000.0<<" seconds\n";*/

   	cout << "chiActual: "<< chiActual << endl;
   	
  	cout << "chiEstimated: " << chiEstimated << endl;
  	

  	cout << "Estimated p-value by calling calculate_pvalue_ifNormal(num_bins, mean, SD): " << b1.calculate_pvalue_ifNormal(k, mean, SD) <<endl;

  	cout << "Estimated final decision by calling final_decision_ifNormal(num_bins, mean, SD, com_p	): "<<b2.final_decision_ifNormal(k, mean, SD, 0.05) <<endl;

  	delete []items;
	//delete [] frequencies;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
leaq -0x60(%rbp), %rbx
movl $0x1, (%rbx)
movq 0x73e5(%rip), %r14      # 0xbfc8
leaq 0x3692(%rip), %rsi      # 0x827c
movl $0x43, %edx
movq %r14, %rdi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq 0x369b(%rip), %rsi      # 0x82c0
movl $0x1c, %edx
movq %r14, %rdi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq 0x367d(%rip), %rsi      # 0x82dd
movl $0x13, %edx
movq %r14, %rdi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq 0x3656(%rip), %rsi      # 0x82f1
movl $0x1d, %edx
movq %r14, %rdi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq 0x3639(%rip), %rsi      # 0x830f
movl $0x14, %edx
movq %r14, %rdi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movq 0x72c7(%rip), %r15      # 0xbfd8
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2110
leaq 0x3601(%rip), %rsi      # 0x8324
movl $0x17, %edx
movq %r14, %rdi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq -0x3c(%rbp), %rsi
movq %r15, %rdi
callq 0x2110
leaq 0x35d2(%rip), %rsi      # 0x833c
movl $0x2f, %edx
movq %r14, %rdi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq -0x5c(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x2110
leaq 0x35b8(%rip), %rsi      # 0x836c
movl $0x2a, %edx
movq %r14, %rdi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq -0x2c(%rbp), %rsi
movq %r15, %rdi
callq 0x2110
leaq 0x359c(%rip), %rsi      # 0x8397
movl $0x47, %edx
movq %r14, %rdi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq -0x58(%rbp), %rsi
movq %r15, %rdi
callq 0x2120
leaq 0x359d(%rip), %rsi      # 0x83df
movl $0x55, %edx
movq %r14, %rdi
callq 0x21c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq -0x50(%rbp), %rsi
movq %r15, %rdi
callq 0x2120
cvtsi2sdl (%r12), %xmm0
movl (%rbx), %esi
leaq -0xe8(%rbp), %rdi
callq 0x4028
xorps %xmm0, %xmm0
cvtsi2sdl (%r12), %xmm0
movl (%rbx), %esi
leaq -0xc0(%rbp), %rdi
callq 0x4028
xorps %xmm0, %xmm0
cvtsi2sdl -0x5c(%rbp), %xmm0
movl -0x60(%rbp), %esi
leaq -0x98(%rbp), %rdi
callq 0x4028
movslq -0x3c(%rbp), %r14
leaq (,%r14,8), %rax
testq %r14, %r14
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x2030
movq %rax, %rbx
movq $0x5, -0x70(%rbp)
movsd -0x58(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
movsd %xmm0, -0x108(%rbp)
movsd %xmm1, -0x100(%rbp)
movq $0x0, -0xf8(%rbp)
movb $0x0, -0xf0(%rbp)
testl %r14d, %r14d
jle 0x4fb4
movq -0xc8(%rbp), %r14
movq -0xa0(%rbp), %r15
xorpd %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x78(%rbp), %r12
xorl %r13d, %r13d
leaq -0x108(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movq %rdi, %rdx
callq 0x766c
movapd %xmm0, %xmm1
movsd -0x48(%rbp), %xmm0
addsd 0x30ab(%rip), %xmm0     # 0x8010
movsd %xmm0, -0x48(%rbp)
movsd %xmm1, (%rbx,%r13,8)
movq (%r14), %rax
movq %r14, %rdi
movapd %xmm1, %xmm0
movsd %xmm1, -0x38(%rbp)
callq *(%rax)
movsd -0x38(%rbp), %xmm0
movq (%r15), %rax
movq %r15, %rdi
callq *(%rax)
movsd -0x38(%rbp), %xmm0
movq (%r12), %rax
movq %r12, %rdi
callq *(%rax)
incq %r13
movslq -0x3c(%rbp), %rax
cmpq %rax, %r13
jl 0x4f41
movsd -0x58(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
jmp 0x4fbd
xorpd %xmm2, %xmm2
movsd %xmm2, -0x48(%rbp)
movl -0x2c(%rbp), %esi
leaq -0xe8(%rbp), %rdi
callq 0x4202
movsd %xmm0, -0x68(%rbp)
movq -0xd8(%rbp), %r15
movq -0xd0(%rbp), %r14
movl -0x2c(%rbp), %eax
testl %eax, %eax
jle 0x5073
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd -0x48(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, -0x48(%rbp)
movl -0x3c(%rbp), %ecx
incq %rax
xorpd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl $0x1, %edx
movsd 0x2ff5(%rip), %xmm0     # 0x8010
xorpd %xmm1, %xmm1
testl %ecx, %ecx
jle 0x504a
movsd (%r15,%rdx,8), %xmm2
xorl %esi, %esi
movsd (%rbx,%rsi,8), %xmm3
ucomisd %xmm3, %xmm2
jb 0x5042
ucomisd (%r14,%rdx,8), %xmm3
jb 0x5042
addsd %xmm0, %xmm1
incq %rsi
cmpq %rsi, %rcx
jne 0x502b
movsd -0x48(%rbp), %xmm2
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm1
divsd %xmm2, %xmm1
movsd -0x38(%rbp), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, -0x38(%rbp)
incq %rdx
cmpq %rax, %rdx
jne 0x501b
jmp 0x507c
xorpd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq 0x6f45(%rip), %rdi      # 0xbfc8
leaq 0x33ab(%rip), %rsi      # 0x8435
movl $0xb, %edx
callq 0x21c0
movq 0x6f2d(%rip), %rdi      # 0xbfc8
movsd -0x38(%rbp), %xmm0
callq 0x2220
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movq 0x6ef2(%rip), %rdi      # 0xbfc8
leaq 0x3364(%rip), %rsi      # 0x8441
movl $0xe, %edx
callq 0x21c0
movq 0x6eda(%rip), %rdi      # 0xbfc8
movsd -0x68(%rbp), %xmm0
callq 0x2220
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movq 0x6e9f(%rip), %rdi      # 0xbfc8
leaq 0x3320(%rip), %rsi      # 0x8450
movl $0x4c, %edx
callq 0x21c0
movl -0x2c(%rbp), %r12d
movsd -0x58(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
leaq -0xc0(%rbp), %rdi
movl %r12d, %esi
callq 0x4202
decl %r12d
movl %r12d, %edi
callq 0x3ba1
movq 0x6e5f(%rip), %rdi      # 0xbfc8
callq 0x2220
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movq 0x6e29(%rip), %rdi      # 0xbfc8
leaq 0x32f7(%rip), %rsi      # 0x849d
movl $0x59, %edx
callq 0x21c0
movl -0x2c(%rbp), %r12d
movsd -0x58(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
leaq -0x98(%rbp), %rdi
movl %r12d, %esi
callq 0x4202
decl %r12d
movl %r12d, %edi
callq 0x3ba1
movsd 0x2f88(%rip), %xmm1     # 0x8168
xorl %esi, %esi
ucomisd %xmm0, %xmm1
seta %sil
movq 0x6dd7(%rip), %rdi      # 0xbfc8
callq 0x2260
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movq %rbx, %rdi
callq 0x21e0
movq -0x78(%rbp), %rdi
callq 0x2190
movq -0x88(%rbp), %rdi
callq 0x2190
movq -0x80(%rbp), %rdi
callq 0x2190
movq -0xa0(%rbp), %rdi
callq 0x2190
movq -0xb0(%rbp), %rdi
callq 0x2190
movq -0xa8(%rbp), %rdi
callq 0x2190
movq -0xc8(%rbp), %rdi
callq 0x2190
movq %r15, %rdi
callq 0x2190
movq %r14, %rdi
callq 0x2190
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x52a8
jmp 0x52a8
movq %rax, %rbx
jmp 0x52b7
movq %rax, %rbx
jmp 0x52c3
jmp 0x52a8
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x41c6
leaq -0xc0(%rbp), %rdi
callq 0x41c6
leaq -0xe8(%rbp), %rdi
callq 0x41c6
movq %rbx, %rdi
callq 0x22b0