<commit_before>package com.milaboratory.test;

import com.fasterxml.jackson.core.type.TypeReference;
import com.milaboratory.core.sequence.Alphabet;
import com.milaboratory.core.sequence.Sequence;
import com.milaboratory.core.sequence.SequenceBuilder;
import com.milaboratory.util.GlobalObjectMappers;
import com.milaboratory.util.RandomUtil;
import org.apache.commons.math3.random.RandomDataGenerator;
import org.apache.commons.math3.random.RandomGenerator;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class TestUtil {
    public static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.00");

    public static boolean lt() {
        return Objects.equals(System.getProperty("longTests"), "") ||
                Objects.equals(System.getProperty("longTests"), "true");
    }

    @Test
    public void testLT() throws Exception {
        if (lt())
            System.out.println("Long tests.");
        else
            System.out.println("Short tests.");

        if (getProperties().isEmpty()) {
            System.out.println("No system env properties.");
        } else {
            System.out.println("There are some system env properties.");
        }
    }

    public static int its(int shortTest, int longTest) {
        return lt() ? longTest : shortTest;
    }

    public static String env() {
        String serverEnv = System.getProperty("serverEnv");

        if (serverEnv == null)
            return null;

        File serverEnvPath = new File(serverEnv);
        if (serverEnvPath.exists() && serverEnvPath.isDirectory()) {
            String ret = serverEnvPath.getAbsolutePath();
            if (!ret.endsWith(File.separator))
                ret = ret + File.separator;
            return ret;
        } else
            throw new IllegalArgumentException(serverEnv + " not exists.");
    }

    private static volatile Map<String, String> envProperties;

    public static synchronized Map<String, String> getProperties() {
        if (envProperties == null) {
            String e = env();

            if (e == null)
                envProperties = Collections.EMPTY_MAP;
            else {
                File propsFile = new File(e + "properties.json");

                if (!propsFile.exists())
                    envProperties = Collections.EMPTY_MAP;
                else {
                    try {
                        envProperties = GlobalObjectMappers.ONE_LINE
                                .readValue(propsFile, new TypeReference<HashMap<String, String>>() {
                                });
                    } catch (IOException ex) {
                        envProperties = Collections.EMPTY_MAP;
                    }
                }<commit_msg>Util methods for tests.<commit_after>package com.milaboratory.test;

import com.fasterxml.jackson.core.type.TypeReference;
import com.milaboratory.core.sequence.Alphabet;
import com.milaboratory.core.sequence.Sequence;
import com.milaboratory.core.sequence.SequenceBuilder;
import com.milaboratory.util.GlobalObjectMappers;
import com.milaboratory.util.RandomUtil;
import org.apache.commons.math3.random.RandomDataGenerator;
import org.apache.commons.math3.random.RandomGenerator;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class TestUtil {
    public static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.00");

    public static boolean lt() {
        return Objects.equals(System.getProperty("longTests"), "") ||
                Objects.equals(System.getProperty("longTests"), "true");
    }

    @Test
    public void testLT() throws Exception {
        if (lt())
            System.out.println("Long tests.");
        else
            System.out.println("Short tests.");

        if (getProperties().isEmpty()) {
            System.out.println("No system env properties.");
        } else {
            System.out.println("There are some system env properties.");
        }
    }

    public static int its(int shortTest, int longTest) {
        return lt() ? longTest : shortTest;
    }

    public static String env() {
        String serverEnv = System.getProperty("serverEnv");

        if (serverEnv == null)
            return null;

        File serverEnvPath = new File(serverEnv);
        if (serverEnvPath.exists() && serverEnvPath.isDirectory()) {
            String ret = serverEnvPath.getAbsolutePath();
            if (!ret.endsWith(File.separator))
                ret = ret + File.separator;
            return ret;
        } else
            throw new IllegalArgumentException(serverEnv + " not exists.");
    }

    public static void assertJson(Object object) {
        assertJson(object, object.getClass(), false);
    }

    public static void assertJson(Object object, boolean sout) {
        assertJson(object, object.getClass(), sout);
    }

    public static void assertJson(Object object, Class clazz) {
        assertJson(object, clazz, false);
    }

    public static void assertJson(Object object, Class clazz, boolean sout) {
        try {
            String str = GlobalObjectMappers.PRETTY.writeValueAsString(object);
            if (sout)
                System.out.println(str);
            Object deser = GlobalObjectMappers.PRETTY.readValue(str, clazz);
            Assert.assertEquals(object, deser);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private static volatile Map<String, String> envProperties;

    public static synchronized Map<String, String> getProperties() {
        if (envProperties == null) {
            String e = env();

            if (e == null)
                envProperties = Collections.EMPTY_MAP;
            else {
                File propsFile = new File(e + "properties.json");

                if (!propsFile.exists())
                    envProperties = Collections.EMPTY_MAP;
                else {
                    try {
                        envProperties = GlobalObjectMappers.ONE_LINE
                                .readValue(propsFile, new TypeReference<HashMap<String, String>>() {
                                });
                    } catch (IOException ex) {
                        envProperties = Collections.EMPTY_MAP;
                    }
                }
{'fraction_non_alphanumeric': 0.10189250567751704, 'fraction_numerical': 0.001514004542013626, 'mean_word_length': 2.1759615384615385, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3625461', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1661, 'n_words': 401}