<commit_before>package edu.ucsc.dbtune.inum;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import edu.ucsc.dbtune.core.DBIndex;
import edu.ucsc.dbtune.core.DatabaseConnection;
import edu.ucsc.dbtune.core.IndexExtractor;
import edu.ucsc.dbtune.util.Combinations;
import edu.ucsc.dbtune.util.Strings;
import java.util.Set;
import org.hamcrest.CoreMatchers;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.mockito.Mockito;

/**
 * Test the {@link Inum} class.
 *
 * @author <EMAIL> (<NAME>)
 */
public class InumTest {
  @Test public void testInumSpaceGeneration() throws Exception {
    final Inum inum = configureInum();
    inum.start();
    assertThat(inum.getInumSpace(), CoreMatchers.<Object>notNullValue());
    assertThat(inum.getInumSpace().getAllSavedOptimalPlans().isEmpty(), is(false));
  }

  @Test public void testCombinationGeneration() throws Exception {
    final Set<DummyIndex> indexes = Sets.newHashSet();
    for(int idx = 0; idx < 3; idx++){
      indexes.add(new DummyIndex(configureIndex("create index " + idx)));
    }

    final Set<Set<DummyIndex>> combinations = Combinations.findCombinations(indexes);
    assertThat(combinations.size(), equalTo(8));
  }

  private static DatabaseConnection configureConnection(DBIndex index) throws Exception {
    final Set<DBIndex> configuration = Sets.newHashSet();
    configuration.add(index);
    IndexExtractor extractor = Mockito.mock(IndexExtractor.class);
    Mockito.when(extractor.recommendIndexes(Mockito.anyString())).thenReturn(configuration);
    DatabaseConnection connection = Mockito.mock(DatabaseConnection.class);
    Mockito.when(connection.getIndexExtractor()).thenReturn(extractor);
    return connection;
  }

  private static DBIndex configureIndex(String text) {<commit_msg>added a missing test (shutting down INUM test)...<commit_after>package edu.ucsc.dbtune.inum;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import edu.ucsc.dbtune.core.DBIndex;
import edu.ucsc.dbtune.core.DatabaseConnection;
import edu.ucsc.dbtune.core.IndexExtractor;
import edu.ucsc.dbtune.util.Combinations;
import edu.ucsc.dbtune.util.Strings;
import java.util.Set;
import org.hamcrest.CoreMatchers;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.mockito.Mockito;

/**
 * Test the {@link Inum} class.
 *
 * @author <EMAIL> (<NAME>)
 */
public class InumTest {
  @Test public void testInumSpaceGeneration() throws Exception {
    final Inum inum = configureInum();
    inum.start();
    assertThat(inum.getInumSpace(), CoreMatchers.<Object>notNullValue());
    assertThat(inum.getInumSpace().getAllSavedOptimalPlans().isEmpty(), is(false));
  }

  @Test public void testCombinationGeneration() throws Exception {
    final Set<DummyIndex> indexes = Sets.newHashSet();
    for(int idx = 0; idx < 3; idx++){
      indexes.add(new DummyIndex(configureIndex("create index " + idx)));
    }

    final Set<Set<DummyIndex>> combinations = Combinations.findCombinations(indexes);
    assertThat(combinations.size(), equalTo(8));
  }

  @Test (expected = InumExecutionException.class) public void testInumShutdown() throws Exception {
    final Inum inum = configureInum();
    inum.end();
    inum.estimateCost("lalala", Sets.<DBIndex>newHashSet());
    fail("if we reached this line...then test has failed");
  }

  private static DatabaseConnection configureConnection(DBIndex index) throws Exception {
    final Set<DBIndex> configuration = Sets.newHashSet();
    configuration.add(index);
    IndexExtractor extractor = Mockito.mock(IndexExtractor.class);
    Mockito.when(extractor.recommendIndexes(Mockito.anyString())).thenReturn(configuration);
    DatabaseConnection connection = Mockito.mock(DatabaseConnection.class);
    Mockito.when(connection.getIndexExtractor()).thenReturn(extractor);
    return connection;
  }

  private static DBIndex configureIndex(String text) {
{'fraction_non_alphanumeric': 0.12124105011933174, 'fraction_numerical': 0.001431980906921241, 'mean_word_length': 5.18141592920354, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 18, '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': '1560348', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1294, 'n_words': 257}