<commit_before>package org.ycavatars.toymongo.core.collection;

import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import org.junit.Assert;
import org.junit.Test;

import java.util.*;

/**
 * @author ycavatars
 */
public class TestBtreeMap {

  @Test
  public void testPutAll_throughConstructor() {
    Map<String, String> that = new HashMap<>();
    for (int i = 0; i < BTreeMap.MAX_NODE_KEYS; i++) {
      that.put("key" + i, "value" + i);
    }

    BTreeMap<String, String> map = new BTreeMap<>(that);
    Assert.assertEquals(map.size(), BTreeMap.MAX_NODE_KEYS);
  }

  @Test
  public void testPut_rootIsNotFull() {
    BTreeMap<String, String> map = new BTreeMap<>();
    map.put("keyA", "valueA");
    map.put("keyB", "valueB");

    Assert.assertEquals(map.get("keyA"), "valueA");
    Assert.assertEquals(map.get("keyB"), "valueB");
  }

  @Test
  public void testPut_rootIsFull() {
    Map<String, String> that = new HashMap<>();
    for (int i = 0; i < BTreeMap.MAX_NODE_KEYS; i++) {
      that.put("key" + i, "value" + i);
    }

    BTreeMap<String, String> map = new BTreeMap<>(that);
    map.put("key1001", "value1001");
    map.put("key1002", "value1002");
    map.put("key1003", "value1003");

    Assert.assertEquals(map.get("key1001"), "value1001");
    Assert.assertEquals(map.get("key1002"), "value1002");
    Assert.assertEquals(map.get("key1003"), "value1003");
  }

  @Test
  public void testCopyEntryIterator_fullRoot() {
    // create map with data
    List<Map.Entry<String, String>> entries =
        Lists.newArrayListWithCapacity(BTreeMap.MAX_NODE_KEYS);
    Map<String, String> that = new HashMap<>();
    for (int i = 0; i < BTreeMap.MAX_NODE_KEYS; i++) {
      String key = "key" + i;
      String value = "value" + i;
      that.put(key, value);
      entries.add(new BTreeMap.Entry<>(key, value));
    }
    BTreeMap<String, String> map = new BTreeMap<>(that);

    // sort key in the same way as BTreeMap
    entries.sort(Comparator.comparing((Map.Entry e) -> (Comparable) e.getKey()));

    Iterator<Map.Entry<String, String>> entrySetIterator = map.entrySet()
        .iterator();
    for (Map.Entry<String, String> e : entries) {
      Assert.assertTrue(entrySetIterator.hasNext());

      Map.Entry<String, String> thatEntry = entrySetIterator.next();
      Assert.assertEquals(e.getKey(), thatEntry.getKey());
      Assert.assertEquals(e.getValue(), thatEntry.getValue());
    }

    try {
      Assert.assertFalse(entrySetIterator.hasNext());
    } catch (ArrayIndexOutOfBoundsException e) {
      Assert.fail(Throwables.getStackTraceAsString(e));
    }

    try {
      entrySetIterator.next();
      Assert.fail();
    } catch (NoSuchElementException e) {
    }
  }

  @Test
  public void testCopyEntryIterator_changeNextElement() {
    Map<String, String> map = new BTreeMap<>();
    map.put("a", "b");

    Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();

    try {
      Assert.assertTrue(iterator.hasNext());
      Map.Entry<String, String> e = iterator.next();
      Assert.assertEquals("a", e.getKey());
      Assert.assertEquals("b", e.getValue());

      e.setValue("123");

      Assert.assertEquals("b", map.get("a"));
      Assert.assertEquals("123", e.getValue());
    } catch (Exception e) {
      Assert.fail(Throwables.getStackTraceAsString(e));
    }
  }
}<commit_msg>add splitOnce test case<commit_after>package org.ycavatars.toymongo.core.collection;

import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import org.junit.Assert;
import org.junit.Test;

import java.util.*;

/**
 * @author ycavatars
 */
public class TestBtreeMap {

  @Test
  public void testPutAll_throughConstructor() {
    Map<String, String> that = new HashMap<>();
    for (int i = 0; i < BTreeMap.MAX_NODE_KEYS; i++) {
      that.put("key" + i, "value" + i);
    }

    BTreeMap<String, String> map = new BTreeMap<>(that);
    Assert.assertEquals(map.size(), BTreeMap.MAX_NODE_KEYS);
  }

  @Test
  public void testPut_rootIsNotFull() {
    BTreeMap<String, String> map = new BTreeMap<>();
    map.put("keyA", "valueA");
    map.put("keyB", "valueB");

    Assert.assertEquals(map.get("keyA"), "valueA");
    Assert.assertEquals(map.get("keyB"), "valueB");
  }

  @Test
  public void testPut_rootIsFull() {
    Map<String, String> that = new HashMap<>();
    for (int i = 0; i < BTreeMap.MAX_NODE_KEYS; i++) {
      that.put("key" + i, "value" + i);
    }

    BTreeMap<String, String> map = new BTreeMap<>(that);
    map.put("key1001", "value1001");
    map.put("key1002", "value1002");
    map.put("key1003", "value1003");

    Assert.assertEquals(map.get("key1001"), "value1001");
    Assert.assertEquals(map.get("key1002"), "value1002");
    Assert.assertEquals(map.get("key1003"), "value1003");
  }

  @Test
  public void testCopyEntryIterator_fullRoot() {
    // create map with data
    List<Map.Entry<String, String>> entries =
        Lists.newArrayListWithCapacity(BTreeMap.MAX_NODE_KEYS);
    Map<String, String> that = new HashMap<>();
    for (int i = 0; i < BTreeMap.MAX_NODE_KEYS; i++) {
      String key = "key" + i;
      String value = "value" + i;
      that.put(key, value);
      entries.add(new BTreeMap.Entry<>(key, value));
    }
    BTreeMap<String, String> map = new BTreeMap<>(that);

    // sort key in the same way as BTreeMap
    entries.sort(Comparator.comparing((Map.Entry e) -> (Comparable) e.getKey()));

    Iterator<Map.Entry<String, String>> entrySetIterator = map.entrySet()
        .iterator();
    for (Map.Entry<String, String> e : entries) {
      Assert.assertTrue(entrySetIterator.hasNext());

      Map.Entry<String, String> thatEntry = entrySetIterator.next();
      Assert.assertEquals(e.getKey(), thatEntry.getKey());
      Assert.assertEquals(e.getValue(), thatEntry.getValue());
    }

    try {
      Assert.assertFalse(entrySetIterator.hasNext());
    } catch (ArrayIndexOutOfBoundsException e) {
      Assert.fail(Throwables.getStackTraceAsString(e));
    }

    try {
      entrySetIterator.next();
      Assert.fail();
    } catch (NoSuchElementException e) {
    }
  }

  @Test
  public void testCopyEntryIterator_changeNextElement() {
    Map<String, String> map = new BTreeMap<>();
    map.put("a", "b");

    Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();

    try {
      Assert.assertTrue(iterator.hasNext());
      Map.Entry<String, String> e = iterator.next();
      Assert.assertEquals("a", e.getKey());
      Assert.assertEquals("b", e.getValue());

      e.setValue("123");

      Assert.assertEquals("b", map.get("a"));
      Assert.assertEquals("123", e.getValue());
    } catch (Exception e) {
      Assert.fail(Throwables.getStackTraceAsString(e));
    }
  }

  @Test
  public void testSplitChild_splitOnce() {
    BTreeMap<String, String> map = new BTreeMap<>();
    for (int i = 0; i < BTreeMap.MAX_NODE_KEYS; i++) {
      map.put("key" + i, "value" + i);
    }
    for (int i = 0; i < (BTreeMap.MAX_NODE_KEYS / 2); i++) {
      map.put("skey" + i, "svalue" + i);
    }

    int expectedSize = BTreeMap.MAX_NODE_KEYS + BTreeMap.MAX_NODE_KEYS / 2;
    Assert.assertEquals(expectedSize, map.size());
  }
}
{'fraction_non_alphanumeric': 0.16438166458939205, 'fraction_numerical': 0.01634122697687301, 'mean_word_length': 3.4470443349753697, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 59, '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': '6616020', 'n_tokens_mistral': 2479, 'n_tokens_neox': 2371, 'n_words': 476}