package integration;

import com.cluttered.cryptocurrency.ann.Layer;
import com.cluttered.cryptocurrency.ann.NeuralNetwork;
import com.cluttered.cryptocurrency.ann.neuron.Neuron;
import org.junit.Test;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static java.math.BigDecimal.*;
import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author cluttered.code@gmail.com
 */
public class XorTest {

    //private static final Logger LOG = LoggerFactory.getLogger(XorTest.class);

    private static BigDecimal bigDecimal(final String value) {
        return new BigDecimal(value);
    }

    @Test
    public void xorTest() {
        // Hidden Layer
        final Neuron hiddenNeuron1 = Neuron.builder()
                .sigmoid()
                .weights(bigDecimal("60"), bigDecimal("60"))
                .bias(bigDecimal("-90"))
                .build();
        final Neuron hiddenNeuron2 = Neuron.builder()
                .sigmoid()
                .weights(bigDecimal("80"), bigDecimal("80"))
                .bias(bigDecimal("-40"))
                .build();
        final Layer hiddenLayer = new Layer(Arrays.asList(hiddenNeuron1, hiddenNeuron2));

        // Output Layer
        final Neuron outputNeuron = Neuron.builder()
                .sigmoid()
                .weights(bigDecimal("-60"), bigDecimal("60"))
                .bias(bigDecimal("-30"))
                .build();
        final Layer outputLayer = new Layer(Collections.singletonList(outputNeuron));

        final NeuralNetwork neuralNetwork = new NeuralNetwork(2L, Arrays.asList(hiddenLayer, outputLayer));

        // [<INPUTS>] -> [<OUTPUTS>]
        // [0, 0] -> [0]
        final List<BigDecimal> inputs1 = Arrays.asList(ZERO, ZERO);
        final BigDecimal result1 = neuralNetwork.fire(inputs1).get(0).setScale(10, ROUND_HALF_UP);
        //LOG.info("1) {} -> {}", inputs1, result1);
        assertThat(result1).isEqualTo(ZERO.setScale(10));

        // [1, 0] -> [1]
        final List<BigDecimal> inputs2 = Arrays.asList(ONE, ZERO);
        final BigDecimal result2 = neuralNetwork.fire(inputs2).get(0).setScale(10, ROUND_HALF_UP);
        //LOG.info("2) {} -> {}", inputs2, result2);
        assertThat(result2).isEqualTo(ONE.setScale(10));

        // [0, 1] -> [1]
        final List<BigDecimal> inputs3 = Arrays.asList(ZERO, ONE);
        final BigDecimal result3 = neuralNetwork.fire(inputs3).get(0).setScale(10, ROUND_HALF_UP);
        //LOG.info("3) {} -> {}", inputs3, result3);
        assertThat(result3).isEqualTo(ONE.setScale(10));

        // [1, 1] -> [0]
        final List<BigDecimal> inputs4 = Arrays.asList(ONE, ONE);
        final BigDecimal result4 = neuralNetwork.fire(inputs4).get(0).setScale(10, ROUND_HALF_UP);
        //LOG.info("4) {} -> {}", inputs4, result4);
        assertThat(result4).isEqualTo(ZERO.setScale(10));
    }
}
@@ -194,16 +194,73 @@
 it.Test;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -530,18 +530,16 @@
  %7B%0A%0A    
-//
 private 
@@ -717,18 +717,8 @@
  %7D%0A%0A
-    @Test%0A
     
@@ -1932,34 +1932,32 @@
 LF_UP);%0A        
-//
 LOG.info(%221) %7B%7D 
@@ -2233,34 +2233,32 @@
 LF_UP);%0A        
-//
 LOG.info(%222) %7B%7D 
@@ -2533,34 +2533,32 @@
 LF_UP);%0A        
-//
 LOG.info(%223) %7B%7D 
@@ -2840,18 +2840,16 @@
         
-//
 LOG.info
@@ -2946,10 +2946,139 @@
 );%0A    %7D
+%0A%0A    public static void main(final String%5B%5D args) %7B%0A        new XorTest().xorTest();%0A        LOG.info(%22XOR Test PASSED!%22);%0A    %7D
 %0A%7D

make XorTest a runnable entity