<commit_before>package astava.java.gen;

import astava.CommonTest;
import astava.core.Tuple;
import astava.java.Descriptor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import sun.security.krb5.internal.crypto.Des;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;

import static astava.java.Factory.*;
import static astava.java.Factory.accessVar;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

@RunWith(Parameterized.class)
public class ExpressionBlockTest {
    private ExpressionBlockProvider provider;

    public ExpressionBlockTest(ExpressionBlockProvider provider) {
        this.provider = provider;
    }

    @Parameterized.Parameters
    public static Collection values() {
        // * indicates expression in block
        return Arrays.asList(
            // {Declare, assign, *access} as expression should succeed
            new ExpressionBlockProvider(7, Descriptor.INT, false) {
                @Override
                public Tuple createExpression() {
                    return block(Arrays.asList(
                        declareVar(Descriptor.INT, "myVar"),
                        assignVar("myVar", literal(7)),
                        accessVar("myVar")
                    ));
                }
            },
            // {Declare,assign} as expression should fail
            new ExpressionBlockProvider(null, Descriptor.INT, true) {
                @Override
                public Tuple createExpression() {
                    return block(Arrays.asList(
                        declareVar(Descriptor.INT, "myVar"),
                        assignVar("myVar", literal(7))
                    ));
                }
            },
            // {Declare, assign, *access, *access} as expression should fail
            new ExpressionBlockProvider(null, Descriptor.INT, true) {
                @Override
                public Tuple createExpression() {
                    return block(Arrays.asList(
                        declareVar(Descriptor.INT, "myVar"),
                        assignVar("myVar", literal(7)),
                        accessVar("myVar"),
                        accessVar("myVar")
                    ));
                }
            },
            // {Declare, assign, *access, inc} should succeed
            // Corresponds to myVar++
            new ExpressionBlockProvider(7, Descriptor.INT, false) {
                @Override
                public Tuple createExpression() {
                    return block(Arrays.asList(
                        declareVar(Descriptor.INT, "myVar"),
                        assignVar("myVar", literal(7)),
                        accessVar("myVar"),
                        intIncVar("myVar", 1)
                    ));
                }
            },
            // {Declare, assign, inc, *access} should succeed
            // Corresponds to ++myVar
            new ExpressionBlockProvider(8, Descriptor.INT, false) {
                @Override
                public Tuple createExpression() {
                    return block(Arrays.asList(
                        declareVar(Descriptor.INT, "myVar"),
                        assignVar("myVar", literal(7)),
                        intIncVar("myVar", 1),
                        accessVar("myVar")
                    ));
                }
            }
        ).stream().map(x -> new Object[]{x}).collect(Collectors.toList());
    }

    @Test
    public void testExpressionBlock()
        throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        Object expectedValue = provider.expectedValue();
        String type = provider.resultType();

        Tuple expressionBlock = provider.createExpression();
<commit_msg>Extended expression block test to include test of simulated ternary-expressions.<commit_after>package astava.java.gen;

import astava.CommonTest;
import astava.core.Tuple;
import astava.java.Descriptor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import sun.security.krb5.internal.crypto.Des;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;

import static astava.java.Factory.*;
import static astava.java.Factory.accessVar;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

@RunWith(Parameterized.class)
public class ExpressionBlockTest {
    private ExpressionBlockProvider provider;

    public ExpressionBlockTest(ExpressionBlockProvider provider) {
        this.provider = provider;
    }

    @Parameterized.Parameters
    public static Collection values() {
        // * indicates expression in block
        return Arrays.asList(
            // {Declare, assign, *access} as expression should succeed
            new ExpressionBlockProvider(7, Descriptor.INT, false) {
                @Override
                public Tuple createExpression() {
                    return block(Arrays.asList(
                        declareVar(Descriptor.INT, "myVar"),
                        assignVar("myVar", literal(7)),
                        accessVar("myVar")
                    ));
                }
            },
            // {Declare,assign} as expression should fail
            new ExpressionBlockProvider(null, Descriptor.INT, true) {
                @Override
                public Tuple createExpression() {
                    return block(Arrays.asList(
                        declareVar(Descriptor.INT, "myVar"),
                        assignVar("myVar", literal(7))
                    ));
                }
            },
            // {Declare, assign, *access, *access} as expression should fail
            new ExpressionBlockProvider(null, Descriptor.INT, true) {
                @Override
                public Tuple createExpression() {
                    return block(Arrays.asList(
                        declareVar(Descriptor.INT, "myVar"),
                        assignVar("myVar", literal(7)),
                        accessVar("myVar"),
                        accessVar("myVar")
                    ));
                }
            },
            // {Declare, assign, *access, inc} should succeed
            // Corresponds to myVar++
            new ExpressionBlockProvider(7, Descriptor.INT, false) {
                @Override
                public Tuple createExpression() {
                    return block(Arrays.asList(
                        declareVar(Descriptor.INT, "myVar"),
                        assignVar("myVar", literal(7)),
                        accessVar("myVar"),
                        intIncVar("myVar", 1)
                    ));
                }
            },
            // {Declare, assign, inc, *access} should succeed
            // Corresponds to {++myVar}
            new ExpressionBlockProvider(8, Descriptor.INT, false) {
                @Override
                public Tuple createExpression() {
                    return block(Arrays.asList(
                        declareVar(Descriptor.INT, "myVar"),
                        assignVar("myVar", literal(7)),
                        intIncVar("myVar", 1),
                        accessVar("myVar")
                    ));
                }
            },
            // {*ifElse(true, {*true}, {*false})} should succeed
            // Corresponds to {true ? true : false}
            new ExpressionBlockProvider(true, Descriptor.BOOLEAN, false) {
                @Override
                public Tuple createExpression() {
                    return block(Arrays.asList(
                        ifElse(literal(true),
                            block(Arrays.asList(literal(true))),
                            block(Arrays.asList(literal(false)))
                        )
                    ));
                }
            },
            // {*ifElse(false, {*true}, {*false})} should succeed
            // Corresponds to {false ? true : false}
            new ExpressionBlockProvider(false, Descriptor.BOOLEAN, false) {
                @Override
                public Tuple createExpression() {
                    return block(Arrays.asList(
                        ifElse(literal(false),
                            block(Arrays.asList(literal(true))),
                            block(Arrays.asList(literal(false)))
                        )
                    ));
                }
            }
        ).stream().map(x -> new Object[]{x}).collect(Collectors.toList());
    }

    @Test
    public void testExpressionBlock()
        throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        Object expectedValue = provider.expectedValue();
        String type = provider.resultType();

        Tuple expressionBlock = provider.createExpression();

{'fraction_non_alphanumeric': 0.09651355838406198, 'fraction_numerical': 0.0024349750968456004, 'mean_word_length': 1.5525423728813559, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2277818', 'n_tokens_mistral': 2155, 'n_tokens_neox': 2045, 'n_words': 449}