<commit_before>package com.github.ruediste1.lambdaPegParser;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class PlusMinusTest {

	/**
	 * A simple parser recognizing:
	 * 
	 * <pre>
	 * input = sum EOI
	 * sum = number ('+' number | '-' number)*
	 * number = digit +
	 * </pre>
	 */
	public static class PlusMinusParser extends DefaultParser {

		public PlusMinusParser(DefaultParsingContext ctx) {
			super(ctx);
		}

		int input() {
			int result = sum();
			EOI();
			return result;
		}

		int sum() {
			int result = number();
			return ZeroOrMore(() -> FirstOf(() -> {
				String("+");
				return number();
			}, () -> {
				String("-");
				return -number();
			})).stream().reduce(result, (a, b) -> a + b);
		}

		int number() {
			return Integer
					.parseInt(OneOrMoreChars(Character::isDigit, "number"));
		}
	}

	@Test
	public void singleNumber() {
		assertEquals(123, ParserFactory.create(PlusMinusParser.class, "123")
				.input());
	}

	@Test
	public void addition() {
		DefaultParsingContext ctx = new DefaultParsingContext("1+2");
		PlusMinusParser parser = ParserFactory.create(PlusMinusParser.class,
				ctx);
		int result = parser.input();

		assertEquals(3, result);
	}

	@Test
	public void subtraction() {
		assertEquals(7, ParserFactory.create(PlusMinusParser.class, "12-5")
				.input());
	}

	@Test
	public void complex() {
		assertEquals(9, ParserFactory.create(PlusMinusParser.class, "12-5+2")
				.input());
	}
}<commit_msg>formatting<commit_after>package com.github.ruediste1.lambdaPegParser;

import static org.junit.Assert.assertEquals;

import java.util.function.Supplier;

import org.junit.Test;

public class PlusMinusTest {

    /**
     * A simple parser recognizing:
     * 
     * <pre>
     * input = sum EOI
     * sum = number ('+' number | '-' number)*
     * number = digit +
     * </pre>
     */
    public static class PlusMinusParser extends DefaultParser {

        public PlusMinusParser(DefaultParsingContext ctx) {
            super(ctx);
        }

        int input() {
            int result = sum();
            EOI();
            return result;
        }

        int sum() {
            int result = number();
            return ZeroOrMore((Supplier<Integer>) () -> FirstOf(() -> {
                String("+");
                return number();
            } , () -> {
                String("-");
                return -number();
            })).stream().reduce(result, (a, b) -> a + b);
        }

        int number() {
            return Integer
                    .parseInt(OneOrMoreChars(Character::isDigit, "number"));
        }
    }

    @Test
    public void singleNumber() {
        assertEquals(123,
                ParserFactory.create(PlusMinusParser.class, "123").input());
    }

    @Test
    public void addition() {
        DefaultParsingContext ctx = new DefaultParsingContext("1+2");
        PlusMinusParser parser = ParserFactory.create(PlusMinusParser.class,
                ctx);
        int result = parser.input();

        assertEquals(3, result);
    }

    @Test
    public void subtraction() {
        assertEquals(7,
                ParserFactory.create(PlusMinusParser.class, "12-5").input());
    }

    @Test
    public void complex() {
        assertEquals(9,
                ParserFactory.create(PlusMinusParser.class, "12-5+2").input());
    }
}
{'fraction_non_alphanumeric': 0.1411206640972428, 'fraction_numerical': 0.011265935369107619, 'mean_word_length': 2.30460333006856, 'pattern_counts': {'":': 0, '<': 8, '<?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': '3957461', 'n_tokens_mistral': 1117, 'n_tokens_neox': 999, 'n_words': 217}