<commit_before>package org.intermine.web.logic;

import java.util.HashMap;
import java.util.Map;

import org.intermine.web.logic.widget.Hypergeometric;

import java.math.BigDecimal;

import junit.framework.TestCase;

public class WebUtilTest extends TestCase
{
    private Double maxValue = 1000.0;
    private HashMap<String, BigDecimal> resultsMap = new HashMap();
    private String[] id = new String[3];
    private int[] taggedSample = new int[3];
    private int[] taggedPopulation = new int[3];
    private BigDecimal[] expectedResults = new BigDecimal[3];
    private int bagsize = 3;
    private int total = 100;
    HashMap<String, BigDecimal> bonferroniMap = new HashMap();
    HashMap<String, BigDecimal> benjaminiMap = new HashMap();

    public  WebUtilTest(String arg) {
        super(arg);
    }

    public void setUp() throws Exception {

        // these numbers are generated via this website:
        // http://www.quantitativeskills.com/sisa/distributions/hypghlp.htm

        id[0] = "notEnriched";
        taggedSample[0] = 1;
        taggedPopulation[0] = 10;
        expectedResults[0] = new BigDecimal(0.27346938775509510577421679045073688030242919921875);

        id[1] = "underrepresented";
        taggedSample[1] = 1;
        taggedPopulation[1] = 50;
        expectedResults[1] = new BigDecimal(0.8787878787878582);

        id[2] = "overrepresented";
        taggedSample[2] = 3;
        taggedPopulation[2] = 20;
        expectedResults[2] = new BigDecimal(0.00705009276437833);

        for (int i = 0; i < 3; i++) {
            double p = Hypergeometric.calculateP(taggedSample[i], bagsize, taggedPopulation[i], total);
            resultsMap.put(id[i], new BigDecimal(p));
            bonferroniMap.put(id[i], new BigDecimal(p * bagsize));
            benjaminiMap.put(id[i], new BigDecimal(p));
        }
    }

    public void testHypergeometric() throws Exception {
        for (int i = 0; i < 3; i++) {
            assertEquals(expectedResults[i], resultsMap.get(id[i]));
        }
    }

    public void testBonferroni() throws Exception {
        Map<String, BigDecimal> adjustedMap = WebUtil.calcErrorCorrection("Bonferroni", maxValue, resultsMap);

        // rounding issue
        for (String label : bonferroniMap.keySet()) {<commit_msg>added case to enrichment widget test<commit_after>package org.intermine.web.logic;

import java.util.HashMap;
import java.util.Map;

import org.intermine.web.logic.widget.Hypergeometric;

import java.math.BigDecimal;

import junit.framework.TestCase;

public class WebUtilTest extends TestCase
{
    private Double maxValue = 1000.0;
    private HashMap<String, BigDecimal> resultsMap = new HashMap();
    private String[] id = new String[4];
    private int[] taggedSample = new int[4];
    private int[] taggedPopulation = new int[4];
    private BigDecimal[] expectedResults = new BigDecimal[4];
    private int bagsize = 3;
    private int total = 100;
    HashMap<String, BigDecimal> bonferroniMap = new HashMap();
    HashMap<String, BigDecimal> benjaminiMap = new HashMap();

    public  WebUtilTest(String arg) {
        super(arg);
    }

    public void setUp() throws Exception {

        // these numbers are generated via this website:
        // http://www.quantitativeskills.com/sisa/distributions/hypghlp.htm

        id[0] = "notEnriched";
        taggedSample[0] = 1;
        taggedPopulation[0] = 10;
        expectedResults[0] = new BigDecimal(0.27346938775509510577421679045073688030242919921875);

        id[1] = "underrepresented";
        taggedSample[1] = 1;
        taggedPopulation[1] = 50;
        expectedResults[1] = new BigDecimal(0.8787878787878582);

        id[2] = "overrepresented";
        taggedSample[2] = 3;
        taggedPopulation[2] = 20;
        expectedResults[2] = new BigDecimal(0.00705009276437833);

        id[3] = "one";
        taggedSample[3] = 3;
        taggedPopulation[3] = 100;
        expectedResults[3] = new BigDecimal(1);


        for (int i = 0; i < 4; i++) {
            double p = Hypergeometric.calculateP(taggedSample[i], bagsize, taggedPopulation[i], total);
            resultsMap.put(id[i], new BigDecimal(p));
            bonferroniMap.put(id[i], new BigDecimal(p * bagsize));
            benjaminiMap.put(id[i], new BigDecimal(p));
        }
    }

    public void testHypergeometric() throws Exception {
        for (int i = 0; i < 4; i++) {
            assertEquals(expectedResults[i], resultsMap.get(id[i]));
        }
    }

    public void testBonferroni() throws Exception {
        Map<String, BigDecimal> adjustedMap = WebUtil.calcErrorCorrection("Bonferroni", maxValue, resultsMap);

        // rounding issue
        for (String label : bonferroniMap.keySet()) {
{'fraction_non_alphanumeric': 0.11622992392223161, 'fraction_numerical': 0.05431107354184277, 'mean_word_length': 2.9739714525608734, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2495823', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1407, 'n_words': 340}