package com.google.research.bleth.simulator;

import static com.google.common.truth.Truth.assertThat;

import com.google.appengine.api.datastore.dev.LocalDatastoreService;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class TracingSimulationIT {

    private final LocalServiceTestHelper helper =
            new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()
                    .setAutoIdAllocationPolicy(LocalDatastoreService.AutoIdAllocationPolicy.SCATTERED));

    private static final IMovementStrategy MOVE_UP = new UpMovementStrategy();
    private static final IMovementStrategy STATIONARY = new StationaryMovementStrategy();

    private static final int BOARD_DIMENSION_EQUALS_TWO = 2;
    private static final int MAX_ROUNDS_EQUALS_TWO = 2;
    private static final int NUMBER_OF_BEACONS_EQUALS_ONE = 1;
    private static final int NUMBER_OF_OBSERVERS_EQUALS_ONE = 1;
    private static final double TRANSMISSION_THRESHOLD_RADIUS_EQUALS_ONE = 1.0;
    private static final int AWAKENESS_CYCLE_EQUALS_TWO = 2;
    private static final int AWAKENESS_DURATION_EQUALS_ONE = 1;
    private static final AwakenessStrategyFactory.Type FIXES_AWAKENESS_STRATEGY_TYPE = AwakenessStrategyFactory.Type.FIXED;

    @Before
    public void setUp() {
        helper.setUp();
    }

    @Test
    public void runSimulationSingleRoundVerifyAgentsLocations() {
        // Create new simulation.
        AbstractSimulation simulation = new TracingSimulation.Builder()
                .setMaxNumberOfRounds(MAX_ROUNDS_EQUALS_TWO)
                .setRowNum(BOARD_DIMENSION_EQUALS_TWO)
                .setColNum(BOARD_DIMENSION_EQUALS_TWO)
                .setBeaconsNum(NUMBER_OF_BEACONS_EQUALS_ONE)
                .setObserversNum(NUMBER_OF_OBSERVERS_EQUALS_ONE)
                .setTransmissionThresholdRadius(TRANSMISSION_THRESHOLD_RADIUS_EQUALS_ONE)
                .setBeaconMovementStrategy(MOVE_UP)
                .setObserverMovementStrategy(STATIONARY)
                .setAwakenessCycle(AWAKENESS_CYCLE_EQUALS_TWO)
                .setAwakenessDuration(AWAKENESS_DURATION_EQUALS_ONE)
                .setAwakenessStrategyType(FIXES_AWAKENESS_STRATEGY_TYPE)
                .build();

        // Find agents and calculate their expected location after a single round.
        Location beaconInitialLocation = simulation.beacons.get(0).getLocation();
        Location observerInitialLocation = simulation.observers.get(0).getLocation();
        Location beaconExpectedLocation = predictLocationAfterMoveUp(beaconInitialLocation, 1);
        Location observerExpectedLocation = observerInitialLocation;

        // Run single-rounded simulation and find agents again.
        simulation.run();
        Location beaconActualLocation = simulation.beacons.get(0).getLocation();
        Location observerActualLocation = simulation.observers.get(0).getLocation();

        assertThat(beaconActualLocation).isEqualTo(beaconExpectedLocation);
        assertThat(observerActualLocation).isEqualTo(observerExpectedLocation);
    }

    private Location predictLocationAfterMoveUp(Location location, int numberOfRounds) {
        return Location.create(Math.max(0, location.row() - numberOfRounds), location.col());
    }
}

@@ -107,1080 +107,343 @@
 ort 
-com.google.appengine.api.datastore.dev.LocalDatastoreService;%0Aimport com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;%0Aimport com.google.appengine.tools.development.testing.LocalServiceTestHelper;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.junit.MockitoJUnitRunner;%0A%0A@RunWith(MockitoJUnitRunner.class)%0Apublic class TracingSimulationIT %7B%0A%0A    private final LocalServiceTestHelper helper =%0A            new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()%0A                    .setAutoIdAllocationPolicy(LocalDatastoreService.AutoIdAllocationPolicy.SCATTERED));%0A%0A    private static final IMovementStrategy MOVE_UP = new UpMovementStrategy();%0A    private static final IMovementStrategy STATIONARY = new StationaryMovementStrategy();%0A%0A    private static final int BOARD_DIMENSION_EQUALS_TWO = 2;%0A    private static final int MAX_ROUNDS_EQUALS_TWO = 2;%0A    private static final int NUMBER_OF_BEACONS_EQUALS_ONE = 1;%0A    private static final int NUMBER_OF_OBSERVERS_EQUALS_ONE = 1;
+org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.junit.MockitoJUnitRunner;%0A%0A@RunWith(MockitoJUnitRunner.class)%0Apublic class TracingSimulationIT %7B%0A%0A    private static final IMovementStrategy MOVE_UP = new UpMovementStrategy();%0A    private static final IMovementStrategy STATIONARY = new StationaryMovementStrategy();%0A
 %0A   
@@ -773,77 +773,8 @@
 D;%0A%0A
-    @Before%0A    public void setUp() %7B%0A        helper.setUp();%0A    %7D%0A%0A
     
@@ -841,24 +841,160 @@
 cations() %7B%0A
+        int roundsNum = 2;%0A        int rowsNum = 2;%0A        int colsNum = 2;%0A        int beaconsNum = 1;%0A        int observersNum = 1;%0A%0A
         // C
@@ -1129,29 +1129,17 @@
 nds(
-MAX_ROUNDS_EQUALS_TWO
+roundsNum
 )%0A  
@@ -1167,34 +1167,15 @@
 Num(
-BOARD_DIMENSION_EQUALS_TWO
+rowsNum
 )%0A  
@@ -1203,34 +1203,15 @@
 Num(
-BOARD_DIMENSION_EQUALS_TWO
+colsNum
 )%0A  
@@ -1243,36 +1243,18 @@
 Num(
-NUMBER_OF_BEACONS_EQUALS_ONE
+beaconsNum
 )%0A  
@@ -1288,38 +1288,20 @@
 Num(
-NUMBER_OF_OBSERVERS_EQUALS_ONE
+observersNum
 )%0A  

Move the non-constant variables to the test itself.