package com.cluttered.cryptocurrency.ann;

import ch.obermuhlner.math.big.BigFloat;
import com.cluttered.cryptocurrency.ann.activation.Activation;
import com.cluttered.cryptocurrency.ann.neuron.Neuron;
import mockit.Expectations;
import mockit.Injectable;
import mockit.Mocked;
import mockit.Tested;
import mockit.integration.junit4.JMockit;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Arrays;
import java.util.List;

import static com.cluttered.cryptocurrency.ann.MathConstants.BIG_FLOAT_CONTEXT_100_HALF_UP;
import static mockit.Deencapsulation.setField;
import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author cluttered.code@gmail.com
 */
@RunWith(JMockit.class)
public class LayerTest {

    @Tested
    @SuppressWarnings("unused")
    private Layer layer;

    @Injectable
    @SuppressWarnings("unused")
    private List<Neuron> neurons;

    @Test
    public void testFire() {
        final List<BigFloat> inputs = Arrays.asList(
                BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(42)
        );
        final List<Neuron> neurons = Arrays.asList(
                Neuron.builder().build(),
                Neuron.builder().weights(BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(0.5)).build(),
                Neuron.builder().bias(BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(30)).build(),
                Neuron.builder().activation(Activation.TAN_H).build()
        );
        setField(layer, "neurons", neurons);

        final List<BigFloat> result = layer.fire(inputs);

        assertThat(result).containsExactly(
                BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(42),
                BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(21.0),
                BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(12),
                BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf("0.9999999999999999999999999999999999993388598746478531403089807148529105038558706553783536798671429480")
        );
    }
}
@@ -81,71 +81,8 @@
 at;%0A
-import com.cluttered.cryptocurrency.ann.activation.Activation;%0A
 impo
@@ -382,100 +382,8 @@
 t;%0A%0A
-import static com.cluttered.cryptocurrency.ann.MathConstants.BIG_FLOAT_CONTEXT_100_HALF_UP;%0A
 impo
@@ -770,12 +770,153 @@
 ire(
+@Mocked final BigFloat input,%0A                         @Mocked final Neuron neuron,%0A                         @Mocked final BigFloat expected
 ) %7B%0A
+%0A
     
@@ -967,355 +967,187 @@
 ist(
-%0A                BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(42)%0A        );%0A        final List%3CNeuron%3E neurons = Arrays.asList(%0A                Neuron.builder().build(),%0A                Neuron.builder().weights(BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(0.5)).build(),%0A                Neuron.builder().bias(BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(30)).build(),
+input, input, input);%0A        final List%3CNeuron%3E neurons = Arrays.asList(neuron, neuron, neuron);%0A        setField(layer, %22neurons%22, neurons);%0A%0A        new Expectations(inputs) %7B%7B
 %0A   
@@ -1159,120 +1159,69 @@
     
-    N
+n
 euron.
-builder().activation(Activation.TAN_H).build()%0A        );%0A        setField(layer, %22neurons%22, neurons)
+fire(inputs); times = 3; result = expected;%0A        %7D%7D
 ;%0A%0A 
@@ -1325,356 +1325,36 @@
 tly(
-%0A                BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(42),%0A                BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(21.0),%0A                BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(12),%0A                BIG_FLOAT_CONTEXT_100_HALF_UP.valueOf(%220.9999999999999999999999999999999999993388598746478531403089807148529105038558706553783536798671429480%22)%0A        
+expected, expected, expected
 );%0A 

fix layer test