<commit_before>package org.neuralnetwork.neuron;

import static org.junit.Assert.*;

import org.junit.Test;
import org.neuralnetwork.functions.AbstractActivationFunction;
import org.neuralnetwork.functions.HeavisideFunction;
import org.neuralnetwork.functions.SigmoidFunction;
import org.neuralnetwork.synapse.AbstractWeightProductSynapse;
import org.neuralnetwork.synapse.AbstractWeightedSynapse;

public class DefaultNeuronTest {

	@Test
	public void testBiasSynapse() {
		DefaultNeuron neuron = new DefaultNeuron(0.0);
		AbstractWeightProductSynapse<Double> biasSynapse = neuron
				.getBiasSynapse();
		assertEquals(0, biasSynapse.getWeight(), 0);
		biasSynapse.setWeight(1.0);
		assertEquals(-1, biasSynapse.getValue(), 0);
	}

	@Test
	public void testSetGetActivationFunction() {
		DefaultNeuron neuron = new DefaultNeuron(0.0);
		AbstractActivationFunction<Double, Double> function = neuron
				.getActivationFunction();
		assertTrue(function instanceof SigmoidFunction);
		assertEquals(1, ((SigmoidFunction) function).getLambda(), 0);

		function = new HeavisideFunction();
		neuron.setActivationFunction(function);
		assertEquals(function, neuron.getActivationFunction());

		function = new AbstractActivationFunction<Double, Double>() {
			@Override
			public Double compute(Double input) {
				return input;
			}
		};
		neuron.setActivationFunction(function);
		assertEquals(function, neuron.getActivationFunction());
	}

	@Test
	public void testHeavisideActivationFunctionValue() {
		DefaultNeuron neuron = new DefaultNeuron(0.0);
		neuron.setActivationFunction(new HeavisideFunction());
		InputTest input = new InputTest();
		neuron.addSynapse(new AbstractWeightedSynapse<InputTest, Double, Double>(
				input, 1.0) {
			@Override
			protected Double readValueFrom(InputTest input, Double weight) {
				return input.value;
			}
		});

		input.value = 0;
		neuron.computeValue();
		assertEquals(1, neuron.getValue(), 0);

		input.value = -1;
		neuron.computeValue();
		assertEquals(0, neuron.getValue(), 0);

		input.value = +1;
		neuron.computeValue();
		assertEquals(1, neuron.getValue(), 0);
	}

	@Test
	public void testSigmoidActivationFunctionValue() {
		DefaultNeuron neuron = new DefaultNeuron(0.0);
		neuron.setActivationFunction(new AbstractActivationFunction<Double, Double>() {
			@Override
			public Double compute(Double input) {
				return input > 1.0 && input < 2.0 ? 1.0 : 0.0;
			}
		});
		InputTest input = new InputTest();
		neuron.addSynapse(new AbstractWeightProductSynapse<InputTest>(input, 2.0) {
			@Override
			protected Double getValueFromInput(InputTest input) {
				return input.value;
			}
		});

		input.value = -50;
		neuron.computeValue();
		assertEquals(0, neuron.getValue(), 0);

		input.value = 0;
		neuron.computeValue();
		assertEquals(0, neuron.getValue(), 0);

		input.value = 0.4;
		neuron.computeValue();
		assertEquals(0, neuron.getValue(), 0);

		input.value = 0.5;
		neuron.computeValue();
		assertEquals(0, neuron.getValue(), 0);

		input.value = 0.6;
		neuron.computeValue();
		assertEquals(1, neuron.getValue(), 0);

		input.value = 0.9;
		neuron.computeValue();
		assertEquals(1, neuron.getValue(), 0);
<commit_msg>Remove specific activation functions test (Heaviside) and fix custom activation function test name.<commit_after>package org.neuralnetwork.neuron;

import static org.junit.Assert.*;

import org.junit.Test;
import org.neuralnetwork.functions.AbstractActivationFunction;
import org.neuralnetwork.functions.HeavisideFunction;
import org.neuralnetwork.functions.SigmoidFunction;
import org.neuralnetwork.synapse.AbstractWeightProductSynapse;

public class DefaultNeuronTest {

	@Test
	public void testBiasSynapse() {
		DefaultNeuron neuron = new DefaultNeuron(0.0);
		AbstractWeightProductSynapse<Double> biasSynapse = neuron
				.getBiasSynapse();
		assertEquals(0, biasSynapse.getWeight(), 0);
		biasSynapse.setWeight(1.0);
		assertEquals(-1, biasSynapse.getValue(), 0);
	}

	@Test
	public void testSetGetActivationFunction() {
		DefaultNeuron neuron = new DefaultNeuron(0.0);
		AbstractActivationFunction<Double, Double> function = neuron
				.getActivationFunction();
		assertTrue(function instanceof SigmoidFunction);
		assertEquals(1, ((SigmoidFunction) function).getLambda(), 0);

		function = new HeavisideFunction();
		neuron.setActivationFunction(function);
		assertEquals(function, neuron.getActivationFunction());

		function = new AbstractActivationFunction<Double, Double>() {
			@Override
			public Double compute(Double input) {
				return input;
			}
		};
		neuron.setActivationFunction(function);
		assertEquals(function, neuron.getActivationFunction());
	}

	@Test
	public void testActivationFunctionValue() {
		DefaultNeuron neuron = new DefaultNeuron(0.0);
		neuron.setActivationFunction(new AbstractActivationFunction<Double, Double>() {
			@Override
			public Double compute(Double input) {
				return input > 1.0 && input < 2.0 ? 1.0 : 0.0;
			}
		});
		InputTest input = new InputTest();
		neuron.addSynapse(new AbstractWeightProductSynapse<InputTest>(input,
				2.0) {
			@Override
			protected Double getValueFromInput(InputTest input) {
				return input.value;
			}
		});

		input.value = -50;
		neuron.computeValue();
		assertEquals(0, neuron.getValue(), 0);

		input.value = 0;
		neuron.computeValue();
		assertEquals(0, neuron.getValue(), 0);

		input.value = 0.4;
		neuron.computeValue();
		assertEquals(0, neuron.getValue(), 0);

		input.value = 0.5;
		neuron.computeValue();
		assertEquals(0, neuron.getValue(), 0);

		input.value = 0.6;
		neuron.computeValue();
		assertEquals(1, neuron.getValue(), 0);

		input.value = 0.9;
		neuron.computeValue();
		assertEquals(1, neuron.getValue(), 0);

{'fraction_non_alphanumeric': 0.12146743900298403, 'fraction_numerical': 0.018781814990345796, 'mean_word_length': 4.997894736842105, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '536996', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1724, 'n_words': 361}