package com.rush.rainyhills.performance;

import com.rush.rainyhills.TestItemUtil;
import com.rush.rainyhills.core.TwoWayLoopCalculator;
import com.rush.rainyhills.core.OneWayLoopCalculator;
import com.rush.rainyhills.middleware.WaterCalculator;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.util.*;

/**
 * Created by Ruslan Khalikov
 * Date: 17.06.2016
 * Time: 19:48
 */
public class VolumeCalculatorPerformanceTest {
    private WaterCalculator waterCalculator;
    private TestItemUtil.TestItem item;
    private int hillCount = 2000;
    private int maxInt = 100;

    @Before
    public void init() {
        Random random = new Random();

        hillCount = hillCount * 2;
        int[] hills = new int[hillCount];
        for (int n = 0; n < hills.length; n++) {
            hills[n] = random.nextInt(maxInt);
        }

        item = new TestItemUtil.TestItem(hills, hills, 0);

        waterCalculator = new WaterCalculator();
    }

    @Ignore
    @Test
    public void twoWayLoopPerformanceTest() {
        waterCalculator.setVolumeCalculator(new TwoWayLoopCalculator());
        long startTime = System.currentTimeMillis();
        waterCalculator.calculate(item.getHills());
        System.out.println("TwoWayLoop calculator stream for " + item.getHills().length
                + " item(s) -> " + (System.currentTimeMillis() - startTime) + " ms");
    }

    @Ignore
    @Test
    public void oneWayLoopPerformanceTest() {
        waterCalculator.setVolumeCalculator(new OneWayLoopCalculator());
        long startTime = System.currentTimeMillis();
        waterCalculator.calculate(item.getHills());
        System.out.println("OneWayLoop calculator stream for " + item.getHills().length
                + " item(s) -> " + (System.currentTimeMillis() - startTime) + " ms");
    }

    @Test
    public void fullPerformanceTest() {
        System.out.println("Preparing...");
        for (int i = 0; i < 10; i++) {
            init();
            twoWayLoopPerformanceTest();
            oneWayLoopPerformanceTest();
        }
        System.out.println("Done!");
    }
}

@@ -39,49 +39,8 @@
 e;%0A%0A
-import com.rush.rainyhills.TestItemUtil;%0A
 impo
@@ -81,32 +81,32 @@
 LoopCalculator;%0A
+
 import com.rush.
@@ -474,36 +474,22 @@
 ate 
-TestItemUtil.TestItem item
+int%5B%5D hills
 ;%0A
+%0A
     
@@ -667,22 +667,16 @@
 %0A       
- int%5B%5D
  hills =
@@ -807,68 +807,8 @@
  %7D%0A%0A
-        item = new TestItemUtil.TestItem(hills, hills, 0);%0A%0A
     
@@ -1083,39 +1083,29 @@
 r.calculate(
-item.getH
+h
 ills
-()
 );%0A        S
@@ -1156,39 +1156,29 @@
 eam for %22 + 
-item.getH
+h
 ills
-()
 .length%0A    
@@ -1494,31 +1494,21 @@
 lculate(
-item.getH
+h
 ills
-()
 );%0A     
@@ -1571,23 +1571,13 @@
 %22 + 
-item.getH
+h
 ills
-()
 .len

remove unused variable