<commit_before>package me.xdrop.jrand

import com.google.common.base.CharMatcher
import me.xdrop.jrand.builders.basics.enums.CHARSET
import org.codehaus.groovy.runtime.MethodClosure

class JRandTest extends GroovyTestCase {

    void testBool() {
        def instance = JRand.bool()
        assertTrue instance.likelihood(100).gen()
        assertFalse instance.likelihood(0).gen()
        likelihoodTest(instance.&likelihood)
    }

    void testChar() {
        assertTrue CharMatcher.JAVA_UPPER_CASE.matchesAllOf(JRand.character().include(CHARSET.CHARS_UPPER).randString())
        assertTrue CharMatcher.JAVA_LOWER_CASE.matchesAllOf(JRand.character().include(CHARSET.CHARS_LOWER).randString())
        assertTrue CharMatcher.JAVA_LETTER.matchesAllOf(JRand.character().include(CHARSET.CHARS_UPPER, CHARSET.CHARS_LOWER).randString())
        assertTrue CharMatcher.JAVA_LETTER_OR_DIGIT.matchesAllOf(JRand.character().include(CHARSET.CHARS_LOWER, CHARSET.CHARS_UPPER, CHARSET.NUMBERS).randString())

        println JRand.character().include(CHARSET.CHARS_UPPER, CHARSET.NUMBERS).genMany(17).toString()
    }

    void testDouble() {
        assertTrue JRand.dbl().max(2).gen() <= 2
        assertTrue JRand.dbl().min(5).gen() >= 5
    }

    void testFloat() {
        assertTrue JRand.flt().max(2).gen() <=2
        assertTrue JRand.flt().min(5).gen() >=5
    }

    void testDecimal() {
        println JRand.decimal().min(4).min(1).digits(2).gen()
        assertTrue JRand.decimal().max(4).min(1).digits(2).gen().length() == 4
    }

    boolean likelihoodTest(MethodClosure func) {
        def likelihood = new Random().nextInt(100)
        def generator = func(likelihood)

        def bucketYes = 0
        def bucketNo = 0

        int iterations = 1000

        for (int i = 0; i <= iterations; i++) {
            if (generator.gen()) {
                bucketYes++
            } else {
                bucketNo++;
            }
        }

        def actual = (bucketYes / iterations) * 100
        println("Likelihood actual": actual);
        println("Likelihood expected": likelihood);
        assertTrue((likelihood - 5) <= actual && actual <= (likelihood + 5))

    }
}
<commit_msg>Update char test<commit_after>package me.xdrop.jrand

import com.google.common.base.CharMatcher
import me.xdrop.jrand.builders.basics.enums.CHARSET
import org.codehaus.groovy.runtime.MethodClosure

class JRandTest extends GroovyTestCase {

    void testBool() {
        def instance = JRand.bool()
        assertTrue instance.likelihood(100).gen()
        assertFalse instance.likelihood(0).gen()
        likelihoodTest(instance.&likelihood)
    }

    void testChar() {
        assertTrue CharMatcher.JAVA_UPPER_CASE.matchesAllOf(JRand.character().include(CHARSET.CHARS_UPPER).genString())
        assertTrue CharMatcher.JAVA_LOWER_CASE.matchesAllOf(JRand.character().include(CHARSET.CHARS_LOWER).genString())
        assertTrue CharMatcher.JAVA_LETTER.matchesAllOf(JRand.character().include(CHARSET.CHARS_UPPER, CHARSET.CHARS_LOWER).genString())
        assertTrue CharMatcher.JAVA_LETTER_OR_DIGIT.matchesAllOf(JRand.character().include(CHARSET.CHARS_LOWER, CHARSET.CHARS_UPPER, CHARSET.NUMBERS).genString())

    }

    void testDouble() {
        assertTrue JRand.dbl().max(2).gen() <= 2
        assertTrue JRand.dbl().min(5).gen() >= 5
    }

    void testFloat() {
        assertTrue JRand.flt().max(2).gen() <=2
        assertTrue JRand.flt().min(5).gen() >=5
    }

    void testDecimal() {
        println JRand.decimal().min(4).min(1).digits(2).gen()
        assertTrue JRand.decimal().max(4).min(1).digits(2).gen().length() == 4
    }

    boolean likelihoodTest(MethodClosure func) {
        def likelihood = new Random().nextInt(100)
        def generator = func(likelihood)

        def bucketYes = 0
        def bucketNo = 0

        int iterations = 1000

        for (int i = 0; i <= iterations; i++) {
            if (generator.gen()) {
                bucketYes++
            } else {
                bucketNo++;
            }
        }

        def actual = (bucketYes / iterations) * 100
        println("Likelihood actual": actual);
        println("Likelihood expected": likelihood);
        assertTrue((likelihood - 5) <= actual && actual <= (likelihood + 5))

    }
}

{'fraction_non_alphanumeric': 0.13123543123543124, 'fraction_numerical': 0.016317016317016316, 'mean_word_length': 2.8244206773618536, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 7, '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': '4816067', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1326, 'n_words': 217}