package org.roi.itlab.cassandra;

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

import org.apache.commons.math3.stat.Frequency;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.roi.itlab.cassandra.random_attributes.*;
/**
 * author Anush
 */
public class TestRA {
    List<Person> list = new ArrayList<>();
    int mean_mean = 0;
    Frequency f = new Frequency();
    List<Comparable<?>> mode;

    @Before
    public  void init()
    {
        PersonDirector personDirector = new PersonDirector();
        PersonBuilder personBuilderImpl = new PersonBuilderImpl();
        personDirector.setPersonBuilder(personBuilderImpl);


        long mean =0;

        for(int j = 0 ; j < 1000000;++j) {
            personDirector.constructPerson();
            list.add(personDirector.getPerson());
            f.addValue(list.get(j).getAge());
        }

        for (Person a : list) {
            mean += a.getAge();
        }
        mean_mean = (int)mean / list.size();
       // System.out.println(mean_mean);
        mode = f.getMode();
       /* System.out.println(mode.get(0));

        for(int i = 0 ; i < mode.size();++i)
        {
            System.out.println("Mode " + mode.get(i) + "  freq = " + f.getCount(mode.get(i)));
        }
        for(int i = 18 ; i < 75;++i)
        {
            System.out.println( i+ " freq = " + f.getCount(i));
        }
        System.out.println(list.get(0).getAge()+ " "+ list.get(0).getExperience() + " "+ list.get(0).getWorkStart() +
        " " + list.get(0).getWorkDuration() + " "+ list.get(0).getWorkEnd());
        */
    }

    @Test
    public void TestBuilder() throws Exception {
        Assert.assertEquals(mean_mean, 35, 20);
        Assert.assertEquals(mode.get(0).toString(), "30");
    }
}

@@ -841,29 +841,41 @@
     
-f.addValue(list.get(j
+mean += personDirector.getPerson(
 ).ge
@@ -880,17 +880,16 @@
 getAge()
-)
 ;%0A      
@@ -894,64 +894,34 @@
     
-%7D%0A%0A        for (Person a : list) %7B%0A            mean += a
+    f.addValue(list.get(j)
 .get
@@ -917,32 +917,33 @@
 .get(j).getAge()
+)
 ;%0A        %7D%0A    
@@ -930,32 +930,34 @@
 e());%0A        %7D%0A
+%0A%0A
         mean_mea
@@ -996,10 +996,8 @@
     
-//
  Sys
@@ -1048,24 +1048,25 @@
 .getMode();%0A
+%0A
        /* Sy
@@ -1066,50 +1066,8 @@
   /*
- System.out.println(mode.get(0));%0A%0A       
  for
@@ -1248,10 +1248,10 @@
 i %3C 
-75
+80
 ;++i
@@ -1535,20 +1535,12 @@
 ());
-%0A        
 */%0A
+%0A
     
@@ -1648,10 +1648,10 @@
 35, 
-20
+15
 );%0A 

fix test