<commit_before>/*
*   Copyright 2016 jshook
*   Licensed under the Apache License, Version 2.0 (the "License");
*   you may not use this file except in compliance with the License.
*   You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*   Unless required by applicable law or agreed to in writing, software
*   distributed under the License is distributed on an "AS IS" BASIS,
*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*   See the License for the specific language governing permissions and
*   limitations under the License.
*/

package io.virtdata;

import io.virtdata.core.AllDataMapperLibraries;
import io.virtdata.core.Bindings;
import io.virtdata.core.BindingsTemplate;
import org.testng.annotations.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class ComposerLibraryTest {

//    @Test
//    public void testTypeConversionChain() {
//        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
//        bt.addFieldBinding("mod_to_string", "compose Mod(3) ; Suffix('0000000000') -> String");
//        Bindings bindings = bt.resolveBindings();
//        Object[] all = bindings.getAll(5);
//        assertThat(all).isNotNull();
//        assertThat(all.length).isEqualTo(1);
//        Object o = all[0];
//        assertThat(o.getClass()).isEqualTo(String.class);
//        assertThat((String) o).isEqualTo("20000000000");
//        // RandomToByteBuffer(1048576) ; ToString()
//    }
//


    @Test(enabled=true)
    public void testArgumentMatchingViaMainLib() {
        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
        bt.addFieldBinding("param","RandomLineToString(data/variable_words.txt)");
        Bindings bindings = bt.resolveBindings();
        Object[] all = bindings.getAll(5);
        assertThat(all).isNotNull();
        assertThat(all.length).isEqualTo(1);
        Object o = all[0];
        assertThat(o.getClass()).isEqualTo(String.class);
    }

    @Test(enabled=false)
    public void testTypeCoercionWhenNeeded() {
        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
        bt.addFieldBinding("mod_to_string", "compose Mod(3) ; Suffix('0000000000') -> String");
        Bindings bindings = bt.resolveBindings();
        Object[] all = bindings.getAll(5);
        assertThat(all).isNotNull();
        assertThat(all.length).isEqualTo(1);
        Object o = all[0];
        assertThat(o.getClass()).isEqualTo(String.class);
        assertThat((String) o).isEqualTo("20000000000");
    }

    @Test(enabled=true)
    public void testChainedTypeResolutionForLong() {
        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
        bt.addFieldBinding("longchain", "compose CycleRange(123456789) ; Div(3); Mod(7) -> long");
        Bindings bindings = bt.resolveBindings();
    }

    @Test(enabled=true)
    public void testChainedTypeResolutionForWithInternalLong() {
        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
        bt.addFieldBinding("longchain", "compose HashRange(1234,6789) -> long; Mod(3) -> int;");
        Bindings bindings = bt.resolveBindings();
        Object n1 = bindings.getAll(123)[0];
        assertThat(n1).isOfAnyClassIn(Integer.class);
    }

    @Test(enabled=true)
    public void testChainedTypeResolutionForInt() {
        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
        bt.addFieldBinding("intchain", "compose ToInt() ; CycleRange(123456789) ; Div(3) ; Mod(7) -> int");
        Bindings bindings = bt.resolveBindings();
    }
}<commit_msg>Added test coverage for parser nuisance<commit_after>/*
*   Copyright 2016 jshook
*   Licensed under the Apache License, Version 2.0 (the "License");
*   you may not use this file except in compliance with the License.
*   You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*   Unless required by applicable law or agreed to in writing, software
*   distributed under the License is distributed on an "AS IS" BASIS,
*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*   See the License for the specific language governing permissions and
*   limitations under the License.
*/

package io.virtdata;

import io.virtdata.core.AllDataMapperLibraries;
import io.virtdata.core.Bindings;
import io.virtdata.core.BindingsTemplate;
import org.testng.annotations.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class ComposerLibraryTest {

//    @Test
//    public void testTypeConversionChain() {
//        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
//        bt.addFieldBinding("mod_to_string", "compose Mod(3) ; Suffix('0000000000') -> String");
//        Bindings bindings = bt.resolveBindings();
//        Object[] all = bindings.getAll(5);
//        assertThat(all).isNotNull();
//        assertThat(all.length).isEqualTo(1);
//        Object o = all[0];
//        assertThat(o.getClass()).isEqualTo(String.class);
//        assertThat((String) o).isEqualTo("20000000000");
//        // RandomToByteBuffer(1048576) ; ToString()
//    }
//


    @Test(enabled=true)
    public void testArgumentMatchingViaMainLib() {
        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
        bt.addFieldBinding("param","RandomLineToString(data/variable_words.txt)");
        Bindings bindings = bt.resolveBindings();
        Object[] all = bindings.getAll(5);
        assertThat(all).isNotNull();
        assertThat(all.length).isEqualTo(1);
        Object o = all[0];
        assertThat(o.getClass()).isEqualTo(String.class);
    }

    @Test(enabled=true)
    public void testChainedTypeResolutionForLong() {
        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
        bt.addFieldBinding("longchain", "compose CycleRange(123456789) ; Div(3); Mod(7) -> long");
        Bindings bindings = bt.resolveBindings();
    }

    @Test(enabled=true)
    public void testChainedTypeResolutionForWithInternalLong() {
        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
        bt.addFieldBinding("longchain", "compose HashRange(1234,6789) -> long; Mod(3) -> int;");
        Bindings bindings = bt.resolveBindings();
        Object n1 = bindings.getAll(123)[0];
        assertThat(n1).isOfAnyClassIn(Integer.class);
    }

    @Test(enabled=true)
    public void testChainedTypeResolutionForInt() {
        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
        bt.addFieldBinding("intchain", "compose ToInt() ; CycleRange(123456789) ; Div(3) ; Mod(7) -> int");
        Bindings bindings = bt.resolveBindings();
    }

    @Test
    public void testStringConversion() {
        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
        bt.addFieldBinding("phone","compose HashRange(1000000000,9999999999); ToString() -> String");
        Bindings bindings = bt.resolveBindings();
    }

    // TODO: Fix this test
    @Test(enabled=false)
    public void testTypeCoercionWhenNeeded() {
        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
        bt.addFieldBinding("mod_to_string", "compose Mod(3) ; Suffix('0000000000') -> String");
        Bindings bindings = bt.resolveBindings();
        Object[] all = bindings.getAll(5);
        assertThat(all).isNotNull();
        assertThat(all.length).isEqualTo(1);
        Object o = all[0];
        assertThat(o.getClass()).isEqualTo(String.class);
        assertThat((String) o).isEqualTo("20000000000");
    }

    // TODO: Fix this test
    @Test(enabled=false)
    public void testBasicRange() {
        BindingsTemplate bt = new BindingsTemplate(AllDataMapperLibraries.get());
        bt.addFieldBinding("phone","HashRange(1000000000, 9999999999)");
        Bindings bindings = bt.resolveBindings();
    }
}
{'fraction_non_alphanumeric': 0.12565575818136399, 'fraction_numerical': 0.031226580064951288, 'mean_word_length': 3.503374578177728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 12, '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': '679052', 'n_tokens_mistral': 2501, 'n_tokens_neox': 2328, 'n_words': 503}