<commit_before>/*
 * Copyright (c) 2013-2016 Cinchapi Inc.
 * 
 * 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 com.cinchapi.concourse.plugin.data;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.junit.Assert;
import org.junit.Test;

import com.cinchapi.concourse.test.ConcourseBaseTest;
import com.cinchapi.concourse.util.Random;

/**
 * <p>
 * Tests to confirm that data is entered correctly into the {@link Dataset}, and
 * retrieved via inversion.
 * </p>
 * 
 * @author <NAME>
 */
public class DatasetTest extends ConcourseBaseTest {

    private Dataset<Long, String, Object> dataset;

    @Override
    public void beforeEachTest() {
        dataset = new ResultDataset();
    }

    @Override
    public void afterEachTest() {
        dataset = null;
    }

    @Test
    public void testInsert() {
        Map<String, Map<Object, Set<Long>>> expected = new HashMap<String, Map<Object, Set<Long>>>();
        int count = Random.getScaleCount();
        for (int i = 0; i < count; i++) {
            String key = Random.getString();
            Map<Object, Set<Long>> value = expected.get(key);
            if(value == null) {
                value = new HashMap<Object, Set<Long>>();
            }
            Object subkey = Random.getObject();
            Set<Long> subvalue = value.get(subkey);
            if(subvalue == null) {
                subvalue = new HashSet<Long>();
            }
            Long element = Random.getLong();
            subvalue.add(element);
            value.put(subkey, subvalue);
            expected.put(key, value);
            dataset.insert(element, key, subkey);
        }
        Assert.assertEquals(expected, dataset.invert());
    }

    @Test
    public void testPut() {
        Map<String, Map<Object, Set<Long>>> inverted = new HashMap<String, Map<Object, Set<Long>>>();
        Map<Long, Map<String, Set<Object>>> original = new HashMap<Long, Map<String, Set<Object>>>();
        int count = Random.getScaleCount();
        for (int i = 0; i < count; i++) {
            String string = Random.getString();
            Long loong = Random.getLong();
            Object object = Random.getObject();

            // EXPECTATION OF INVERTED
            Map<Object, Set<Long>> invertedSubmap = inverted.get(string);
            if(invertedSubmap == null) {
                invertedSubmap = new HashMap<Object, Set<Long>>();
            }

            Set<Long> invertedSubset = invertedSubmap.get(object);
            if(invertedSubset == null) {
                invertedSubset = new HashSet<Long>();
            }

            invertedSubset.add(loong);
            invertedSubmap.put(object, invertedSubset);
            inverted.put(string, invertedSubmap);

            // EXPECTATION OF ORIGINAL
            Map<String, Set<Object>> originalSubmap = original.get(loong);
            if(originalSubmap == null) {
                originalSubmap = new HashMap<String, Set<Object>>();
            }

            Set<Object> originalSubset = originalSubmap.get(string);
            if(originalSubset == null) {
                originalSubset = new HashSet<Object>();
            }

            originalSubset.add(object);
            originalSubmap.put(string, originalSubset);
            original.put(loong, originalSubmap);

            // PUT INTO DATASET
            dataset.put(loong, originalSubmap);
        }
        Assert.assertEquals(inverted, dataset.invert());
    }
    
    @Test
    public void testInsertEntry() {
        Map<String, Map<Object, Set<Long>>> expected = new HashMap<String, Map<Object, Set<Long>>>();
        int count = Random.getScaleCount();
        for (int i = 0; i < count; i++) {
            String key = Random.getString();
            Map<Object, Set<Long>> value = expected.get(key);
            if(value == null) {
                value = new HashMap<Object, Set<Long>>();
            }
            Object subkey = Random.getObject();
            Set<Long> subvalue = value.get(subkey);
            if(subvalue == null) {
                subvalue = new HashSet<Long>();
            }
            Long element = Random.getLong();
            subvalue.add(element);
            value.put(subkey, subvalue);
            expected.put(key, value);
            DatasetEntry<Long, String, Object> entry = new DatasetEntry<Long, String, Object>(element, key, subkey);
            dataset.insert(entry);
        }
        Assert.assertEquals(expected, dataset.invert());
    }
    
    @Test
    public void testDuplicateInsertEntry() {
        String key = "key";
        Long record = 0L;
        Boolean value = true;
        
        DatasetEntry<Long, String, Object> entry = new DatasetEntry<Long, String, Object>(record, key, value);
        DatasetEntry<Long, String, Object> duplicate = new DatasetEntry<Long, String, Object>(record, key, value);
        
        dataset.insert(entry);
        dataset.insert(duplicate);
        
        Assert.assertEquals(1, dataset.invert().size());
    }

}<commit_msg>Edited way of testing duplication of insertions<commit_after>/*
 * Copyright (c) 2013-2016 Cinchapi Inc.
 * 
 * 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 com.cinchapi.concourse.plugin.data;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.junit.Assert;
import org.junit.Test;

import com.cinchapi.concourse.test.ConcourseBaseTest;
import com.cinchapi.concourse.util.Random;

/**
 * <p>
 * Tests to confirm that data is entered correctly into the {@link Dataset}, and
 * retrieved via inversion.
 * </p>
 * 
 * @author <NAME>
 */
public class DatasetTest extends ConcourseBaseTest {

    private Dataset<Long, String, Object> dataset;

    @Override
    public void beforeEachTest() {
        dataset = new ResultDataset();
    }

    @Override
    public void afterEachTest() {
        dataset = null;
    }

    @Test
    public void testInsert() {
        Map<String, Map<Object, Set<Long>>> expected = new HashMap<String, Map<Object, Set<Long>>>();
        int count = Random.getScaleCount();
        for (int i = 0; i < count; i++) {
            String key = Random.getString();
            Map<Object, Set<Long>> value = expected.get(key);
            if(value == null) {
                value = new HashMap<Object, Set<Long>>();
            }
            Object subkey = Random.getObject();
            Set<Long> subvalue = value.get(subkey);
            if(subvalue == null) {
                subvalue = new HashSet<Long>();
            }
            Long element = Random.getLong();
            subvalue.add(element);
            value.put(subkey, subvalue);
            expected.put(key, value);
            dataset.insert(element, key, subkey);
        }
        Assert.assertEquals(expected, dataset.invert());
    }

    @Test
    public void testPut() {
        Map<String, Map<Object, Set<Long>>> inverted = new HashMap<String, Map<Object, Set<Long>>>();
        Map<Long, Map<String, Set<Object>>> original = new HashMap<Long, Map<String, Set<Object>>>();
        int count = Random.getScaleCount();
        for (int i = 0; i < count; i++) {
            String string = Random.getString();
            Long loong = Random.getLong();
            Object object = Random.getObject();

            // EXPECTATION OF INVERTED
            Map<Object, Set<Long>> invertedSubmap = inverted.get(string);
            if(invertedSubmap == null) {
                invertedSubmap = new HashMap<Object, Set<Long>>();
            }

            Set<Long> invertedSubset = invertedSubmap.get(object);
            if(invertedSubset == null) {
                invertedSubset = new HashSet<Long>();
            }

            invertedSubset.add(loong);
            invertedSubmap.put(object, invertedSubset);
            inverted.put(string, invertedSubmap);

            // EXPECTATION OF ORIGINAL
            Map<String, Set<Object>> originalSubmap = original.get(loong);
            if(originalSubmap == null) {
                originalSubmap = new HashMap<String, Set<Object>>();
            }

            Set<Object> originalSubset = originalSubmap.get(string);
            if(originalSubset == null) {
                originalSubset = new HashSet<Object>();
            }

            originalSubset.add(object);
            originalSubmap.put(string, originalSubset);
            original.put(loong, originalSubmap);

            // PUT INTO DATASET
            dataset.put(loong, originalSubmap);
        }
        Assert.assertEquals(inverted, dataset.invert());
    }
    
    @Test
    public void testInsertEntry() {
        Map<String, Map<Object, Set<Long>>> expected = new HashMap<String, Map<Object, Set<Long>>>();
        int count = Random.getScaleCount();
        for (int i = 0; i < count; i++) {
            String key = Random.getString();
            Map<Object, Set<Long>> value = expected.get(key);
            if(value == null) {
                value = new HashMap<Object, Set<Long>>();
            }
            Object subkey = Random.getObject();
            Set<Long> subvalue = value.get(subkey);
            if(subvalue == null) {
                subvalue = new HashSet<Long>();
            }
            Long element = Random.getLong();
            subvalue.add(element);
            value.put(subkey, subvalue);
            expected.put(key, value);
            DatasetEntry<Long, String, Object> entry = new DatasetEntry<Long, String, Object>(element, key, subkey);
            dataset.insert(entry);
        }
        Assert.assertEquals(expected, dataset.invert());
    }
    
    @Test
    public void testDuplicateInsertEntry() {
        String key1 = "key1";
        Long record1 = 0L;
        Boolean value1 = true;
        
        String key2 = "key2";
        Long record2 = 1L;
        Boolean value2 = false;
        
        DatasetEntry<Long, String, Object> entry1 = new DatasetEntry<Long, String, Object>(record1, key1, value1);
        DatasetEntry<Long, String, Object> duplicate1 = new DatasetEntry<Long, String, Object>(record1, key1, value1);
        
        DatasetEntry<Long, String, Object> entry2 = new DatasetEntry<Long, String, Object>(record2, key2, value2);
        DatasetEntry<Long, String, Object> duplicate2 = new DatasetEntry<Long, String, Object>(record2, key2, value2);
        
        dataset.insert(entry1);
        dataset.insert(duplicate1);
        dataset.insert(entry2);
        dataset.insert(duplicate2);
        
        Dataset<Long, String, Object> expected = new ResultDataset();
        
        expected.insert(0L, "key1", true);      // entry1
        expected.insert(1L, "key2", false);     // entry2
        
        Assert.assertEquals(expected.invert(), dataset.invert());
    }

}
{'fraction_non_alphanumeric': 0.11834319526627218, 'fraction_numerical': 0.005748098055790364, 'mean_word_length': 2.236935704514364, 'pattern_counts': {'":': 0, '<': 130, '<?xml version=': 0, '>': 124, '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': '683920', 'n_tokens_mistral': 3301, 'n_tokens_neox': 3211, 'n_words': 863}