package test.blog.distrib;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import blog.common.Util;
import blog.common.numerical.JamaMatrixLib;
import blog.common.numerical.MatrixLib;
import blog.distrib.Laplace;
import blog.model.BuiltInTypes;

/**
 * A test class to verify the Laplace distribution 
 * 
 * @author awong
 */
public class LaplaceTest {
	
	private static final double MEAN = 0.0;
	
	private static final double DIVERSITY = 1.0;
	//private static final double MAX_DIFF_DOUBLE = 1e-10;
	
	private Laplace distrib;
	private static final int NUM_OF_SAMPLES = 1000;
	
	@Before
	public void createLaplace() {
		distrib = new Laplace(MEAN, DIVERSITY);

	}
	
	
	@Test
	public void testSampleVal() {
		Util.initRandom(true);
		double sample, sample_mean = 0, sample_variance = 0;
		System.out.println("Number of samples: " + NUM_OF_SAMPLES);
		System.out.print("Samples: ");
		for(int i = 0; i < NUM_OF_SAMPLES; i++) {
			sample = distrib.sampleVal();
			System.out.print(sample + "\t");
			sample_mean += sample;
			sample_variance += sample * sample;
		}
		sample_mean /= NUM_OF_SAMPLES;
		sample_variance = (sample_variance - NUM_OF_SAMPLES * sample_mean * sample_mean) / (NUM_OF_SAMPLES - 1);
		System.out.println();
		System.out.println("Sample mean: " + sample_mean + ", true mean: " + distrib.getMean());
		System.out.println("Sample variance: " + sample_variance + ", true variance: " + distrib.getVariance());
	}
	
	@Test
	public void testToString() {
		System.out.println(distrib.toString());
	}
}

@@ -32,316 +32,102 @@
 ort 
-static org.junit.Assert.assertEquals;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport blog.common.Util;%0Aimport blog.common.numerical.JamaMatrixLib;%0Aimport blog.common.numerical.MatrixLib;%0Aimport blog.distrib.Laplace;%0Aimport blog.model.BuiltInTypes
+org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport blog.common.Util;%0Aimport blog.distrib.Laplace
 ;%0A%0A/
@@ -179,17 +179,16 @@
 ribution
- 
 %0A * %0A * 
@@ -199,11 +199,13 @@
 hor 
-awo
+Da Ta
 ng%0A 
@@ -234,19 +234,19 @@
 eTest %7B%0A
-%09%0A%09
+%0A  
 private 
@@ -277,19 +277,19 @@
  = 0.0;%0A
-%09%0A%09
+%0A  
 private 
@@ -329,11 +329,13 @@
 .0;%0A
-%09
+  
 //
+ 
 priv
@@ -383,19 +383,19 @@
  1e-10;%0A
-%09%0A%09
+%0A  
 private 
@@ -411,17 +411,18 @@
 istrib;%0A
-%09
+  
 private 
@@ -465,19 +465,19 @@
 00;%0A
-%09%0A%09
+%0A  
 @Before%0A
 %09pub
@@ -472,17 +472,18 @@
 @Before%0A
-%09
+  
 public v
@@ -504,18 +504,20 @@
 ace() %7B%0A
-%09%09
+    
 distrib 
@@ -553,23 +553,23 @@
 );%0A%0A
-%09%7D%0A%09%0A%09%0A%09
+  %7D%0A%0A  
 @Test%0A
-%09
+  
 publ
@@ -594,18 +594,20 @@
 Val() %7B%0A
-%09%09
+    
 Util.ini
@@ -621,18 +621,20 @@
 (true);%0A
-%09%09
+    
 double s
@@ -678,18 +678,20 @@
 ce = 0;%0A
-%09%09
+    
 System.o
@@ -742,18 +742,20 @@
 MPLES);%0A
-%09%09
+    
 System.o
@@ -781,13 +781,16 @@
 %22);%0A
-%09%09
+    
 for
+ 
 (int
@@ -824,19 +824,22 @@
  i++) %7B%0A
-%09%09%09
+      
 sample =
@@ -860,19 +860,22 @@
 eVal();%0A
-%09%09%09
+      
 System.o
@@ -899,19 +899,22 @@
  %22%5Ct%22);%0A
-%09%09%09
+      
 sample_m
@@ -932,11 +932,14 @@
 le;%0A
-%09%09%09
+      
 samp
@@ -974,14 +974,18 @@
 le;%0A
-%09%09%7D%0A%09%09
+    %7D%0A    
 samp
@@ -1011,18 +1011,20 @@
 AMPLES;%0A
-%09%09
+    
 sample_v
@@ -1080,16 +1080,24 @@
 ple_mean
+%0A       
  * sampl
@@ -1103,16 +1103,24 @@
 le_mean)
+%0A       
  / (NUM_
@@ -1136,18 +1136,20 @@
 S - 1);%0A
-%09%09
+    
 System.o
@@ -1162,18 +1162,20 @@
 ntln();%0A
-%09%09
+    
 System.o
@@ -1232,16 +1232,24 @@
  mean: %22
+%0A       
  + distr
@@ -1263,18 +1263,20 @@
 ean());%0A
-%09%09
+    
 System.o
@@ -1323,16 +1323,24 @@
 variance
+%0A       
  + %22, tr
@@ -1384,21 +1384,23 @@
 ));%0A
-%09%7D%0A%09%0A%09
+  %7D%0A%0A  
 @Test%0A
-%09
+  
 publ
@@ -1428,10 +1428,12 @@
 ) %7B%0A
-%09%09
+    
 Syst
@@ -1472,9 +1472,10 @@
 ));%0A
-%09
+  
 %7D%0A%7D%0A

fix formating