<commit_before>/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You 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 edu.brandeis.cs.steele.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.*;

public class ImmutableListTest {
  @Test
  public void nothington() {
    System.out.println("nothington()");
    Integer[] elements = new Integer[]{};
    List<Integer> expResult = Collections.<Integer>emptyList();
    ImmutableList<Integer> result = ImmutableList.of();
    assertTrue(result instanceof ImmutableList.Nothington);
    listTest(expResult, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    assertTrue(resultFromArray instanceof ImmutableList.Nothington);
    listTest(result, resultFromArray);
  }
  @Test
  public void singleton() {
    System.out.println("singleton()");
    Integer[] elements = new Integer[]{ 0 };
    Integer e0 = elements[0];
    List<Integer> expResult = Collections.singletonList(e0);
    ImmutableList<Integer> result = ImmutableList.of(e0);
    assertTrue(result instanceof ImmutableList.Singleton);
    listTest(expResult, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    assertTrue(resultFromArray instanceof ImmutableList.Singleton);
    listTest(result, resultFromArray);
  }
  @Test
  public void doubleton() {
    System.out.println("doubleton()");
    Integer[] elements = new Integer[]{ 0, 1 };
    Integer e0 = elements[0];
    Integer e1 = elements[1];
    List<Integer> expResult1 = Arrays.asList(e0, e1);
    List<Integer> expResult2 = new ArrayList<Integer>(Arrays.asList(e0, e1));
    List<Integer> expResult3 = new LinkedList<Integer>(Arrays.asList(e0, e1));
    ImmutableList<Integer> result = ImmutableList.of(e0, e1);
    assertTrue(result instanceof ImmutableList.Singleton); // implementation detail
    assertTrue(result instanceof ImmutableList.Doubleton);
    listTest(expResult1, result);
    listTest(expResult2, result);
    listTest(expResult3, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    assertTrue(resultFromArray instanceof ImmutableList.Doubleton);
    listTest(result, resultFromArray);
  }
  @Test
  public void tripleton() {
    System.out.println("tripleton()");
    Integer[] elements = new Integer[]{ 0, 1, 2 };
    Integer e0 = elements[0];
    Integer e1 = elements[1];
    Integer e2 = elements[2];
    List<Integer> expResult = Arrays.asList(e0, e1, e2);
    ImmutableList<Integer> result = ImmutableList.of(e0, e1, e2);
    assertTrue(result instanceof ImmutableList.Tripleton);
    listTest(expResult, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    assertTrue(resultFromArray instanceof ImmutableList.Tripleton);
    listTest(result, resultFromArray);
  }
  @Test
  public void quadrupleton() {
    System.out.println("quadrupleton()");
    Integer[] elements = new Integer[]{ 0, 1, 2, 3 };
    Integer e0 = elements[0];
    Integer e1 = elements[1];
    Integer e2 = elements[2];
    Integer e3 = elements[3];
    List<Integer> expResult = Arrays.asList(e0, e1, e2, e3);
    ImmutableList<Integer> result = ImmutableList.of(e0, e1, e2, e3);
    assertTrue(result instanceof ImmutableList.Quadrupleton);
    listTest(expResult, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    assertTrue(resultFromArray instanceof ImmutableList.Quadrupleton);
    listTest(result, resultFromArray);
  }
  @Test
  public void quintupleton() {
    System.out.println("quintupleton()");
    Integer[] elements = new Integer[]{ 0, 1, 2, 3, 4 };
    Integer e0 = elements[0];
    Integer e1 = elements[1];
    Integer e2 = elements[2];
    Integer e3 = elements[3];
    Integer e4 = elements[4];
    List<Integer> expResult = Arrays.asList(e0, e1, e2, e3, e4);
    ImmutableList<Integer> result = ImmutableList.of(e0, e1, e2, e3, e4);
    assertTrue(result instanceof ImmutableList.Quintupleton);
    listTest(expResult, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    assertTrue(resultFromArray instanceof ImmutableList.Quintupleton);
    listTest(result, resultFromArray);
  }
  @Test
  public void restleton() {
    System.out.println("restleton()");
    Integer[] elements = new Integer[]{ 0, 1, 2, 3, 4, 5 };
    Integer e0 = elements[0];
    Integer e1 = elements[1];
    Integer e2 = elements[2];
    Integer e3 = elements[3];
    Integer e4 = elements[4];
    Integer e5 = elements[5];
    List<Integer> expResult = Arrays.asList(e0, e1, e2, e3, e4, e5);
    ImmutableList<Integer> result = ImmutableList.of(e0, e1, e2, e3, e4, e5);
    //assertTrue(result instanceof ImmutableList.Restleton);
    listTest(expResult, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    //assertTrue(resultFromArray instanceof ImmutableList.Restleton);
    listTest(result, resultFromArray);
  }
  @Test
  public void iterable() {
    System.out.println("iterable()");
    Integer[] elements = new Integer[]{ 0, 1, 2, 3, 4};
    Integer e0 = elements[0];
    Integer e1 = elements[1];
    Integer e2 = elements[2];
    Integer e3 = elements[3];
    Integer e4 = elements[4];
    List<Integer> expResult = Collections.unmodifiableList(Arrays.asList(e0, e1, e2, e3, e4));
    ImmutableList<Integer> result = ImmutableList.of(expResult);
    // copmile test for covariant subList
    ImmutableList<Integer> immutableSubList = result.subList(0, 1);
    assertTrue(result instanceof ImmutableList.Quintupleton);
    listTest(expResult, result);
  }
  private <E> void listTest(List<E> expResult, List<E> result) {
    listTest(expResult, result, true);
  }
  private <E> void listTest(List<E> expResult, List<E> result, boolean recurse) {
    assertEquals(expResult, result);
    assertEquals(expResult.size(), result.size());
    assertEquals(
      "expResult class: "+expResult.getClass().getSimpleName()+
      " result class: "+result.getClass().getSimpleName(),
      expResult.toString(), result.toString());
    assertEquals(expResult.hashCode(), result.hashCode());
    assertTrue(Arrays.equals(expResult.toArray(), result.toArray()));
    @SuppressWarnings("unchecked")
    final E[] ref = (E[])new Object[0];<commit_msg>- added tests for common factory overloads - suppressed bogus warnings<commit_after>/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You 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 edu.brandeis.cs.steele.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.*;

public class ImmutableListTest {
  @Test
  public void nothington() {
    System.out.println("nothington()");
    Integer[] elements = new Integer[]{};
    List<Integer> expResult = Collections.<Integer>emptyList();
    ImmutableList<Integer> result = ImmutableList.of();
    assertTrue(result instanceof ImmutableList.Nothington);
    listTest(expResult, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    assertTrue(resultFromArray instanceof ImmutableList.Nothington);
    listTest(result, resultFromArray);
  }
  @Test
  public void singleton() {
    System.out.println("singleton()");
    Integer[] elements = new Integer[]{ 0 };
    Integer e0 = elements[0];
    List<Integer> expResult = Collections.singletonList(e0);
    ImmutableList<Integer> result = ImmutableList.of(e0);
    assertTrue(result instanceof ImmutableList.Singleton);
    listTest(expResult, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    assertTrue(resultFromArray instanceof ImmutableList.Singleton);
    listTest(result, resultFromArray);
  }
  @Test
  public void doubleton() {
    System.out.println("doubleton()");
    Integer[] elements = new Integer[]{ 0, 1 };
    Integer e0 = elements[0];
    Integer e1 = elements[1];
    List<Integer> expResult1 = Arrays.asList(e0, e1);
    List<Integer> expResult2 = new ArrayList<Integer>(Arrays.asList(e0, e1));
    List<Integer> expResult3 = new LinkedList<Integer>(Arrays.asList(e0, e1));
    ImmutableList<Integer> result = ImmutableList.of(e0, e1);
    assertTrue(result instanceof ImmutableList.Singleton); // implementation detail
    assertTrue(result instanceof ImmutableList.Doubleton);
    listTest(expResult1, result);
    listTest(expResult2, result);
    listTest(expResult3, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    assertTrue(resultFromArray instanceof ImmutableList.Doubleton);
    listTest(result, resultFromArray);
  }
  @Test
  public void tripleton() {
    System.out.println("tripleton()");
    Integer[] elements = new Integer[]{ 0, 1, 2 };
    Integer e0 = elements[0];
    Integer e1 = elements[1];
    Integer e2 = elements[2];
    List<Integer> expResult = Arrays.asList(e0, e1, e2);
    ImmutableList<Integer> result = ImmutableList.of(e0, e1, e2);
    assertTrue(result instanceof ImmutableList.Tripleton);
    listTest(expResult, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    assertTrue(resultFromArray instanceof ImmutableList.Tripleton);
    listTest(result, resultFromArray);
  }
  @Test
  public void quadrupleton() {
    System.out.println("quadrupleton()");
    Integer[] elements = new Integer[]{ 0, 1, 2, 3 };
    Integer e0 = elements[0];
    Integer e1 = elements[1];
    Integer e2 = elements[2];
    Integer e3 = elements[3];
    List<Integer> expResult = Arrays.asList(e0, e1, e2, e3);
    ImmutableList<Integer> result = ImmutableList.of(e0, e1, e2, e3);
    assertTrue(result instanceof ImmutableList.Quadrupleton);
    listTest(expResult, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    assertTrue(resultFromArray instanceof ImmutableList.Quadrupleton);
    listTest(result, resultFromArray);
  }
  @Test
  public void quintupleton() {
    System.out.println("quintupleton()");
    Integer[] elements = new Integer[]{ 0, 1, 2, 3, 4 };
    Integer e0 = elements[0];
    Integer e1 = elements[1];
    Integer e2 = elements[2];
    Integer e3 = elements[3];
    Integer e4 = elements[4];
    List<Integer> expResult = Arrays.asList(e0, e1, e2, e3, e4);
    ImmutableList<Integer> result = ImmutableList.of(e0, e1, e2, e3, e4);
    assertTrue(result instanceof ImmutableList.Quintupleton);
    listTest(expResult, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    assertTrue(resultFromArray instanceof ImmutableList.Quintupleton);
    listTest(result, resultFromArray);
  }
  @Test
  public void restleton() {
    System.out.println("restleton()");
    Integer[] elements = new Integer[]{ 0, 1, 2, 3, 4, 5 };
    Integer e0 = elements[0];
    Integer e1 = elements[1];
    Integer e2 = elements[2];
    Integer e3 = elements[3];
    Integer e4 = elements[4];
    Integer e5 = elements[5];
    List<Integer> expResult = Arrays.asList(e0, e1, e2, e3, e4, e5);
    ImmutableList<Integer> result = ImmutableList.of(e0, e1, e2, e3, e4, e5);
    //assertTrue(result instanceof ImmutableList.Restleton);
    listTest(expResult, result);
    ImmutableList<Integer> resultFromArray = ImmutableList.of(elements);
    //assertTrue(resultFromArray instanceof ImmutableList.Restleton);
    listTest(result, resultFromArray);
  }
  @Test
  public void iterable() {
    System.out.println("iterable()");
    Integer[] elements = new Integer[]{ 0, 1, 2, 3, 4};
    Integer e0 = elements[0];
    Integer e1 = elements[1];
    Integer e2 = elements[2];
    Integer e3 = elements[3];
    Integer e4 = elements[4];
    List<Integer> expResult = Collections.unmodifiableList(Arrays.asList(e0, e1, e2, e3, e4));
    ImmutableList<Integer> result = ImmutableList.of(expResult);
    // compile test for covariant subList
    ImmutableList<Integer> immutableSubList = result.subList(0, 1);
    assertTrue(result instanceof ImmutableList.Quintupleton);
    listTest(expResult, result);
  }
  @Test
  public void commonOverloads() {
    System.out.println("commonOverloads()");
    List<List<Integer>> elements = new ArrayList<List<Integer>>();
    elements.add(Arrays.asList(0));
    elements.add(Arrays.asList(1));
    elements.add(Arrays.asList(2));
    elements.add(Arrays.asList(3));
    elements.add(Arrays.asList(4));
    List<Integer> e0 = elements.get(0);
    List<Integer> e1 = elements.get(1);
    List<Integer> e2 = elements.get(2);
    List<Integer> e3 = elements.get(3);
    List<Integer> e4 = elements.get(4);

    final List<List<Integer>> expResult = Collections.unmodifiableList(elements);
    @SuppressWarnings("unchecked") // Arrays.asList complains when making list of parameterized types
    final List<List<Integer>> altExpResult = Arrays.asList(e0, e1, e2, e3, e4);
    // ImmutableList provides overloads for up to 5 arguments, and only for 6+ will
    // if fall back to pure varargs
    final ImmutableList<List<Integer>> result = ImmutableList.of(e0, e1, e2, e3, e4);
    // compile test for covariant subList
    //ImmutableList<Integer> immutableSubList = result.subList(0, 1);
    assertTrue(result instanceof ImmutableList.Quintupleton);
    listTest(expResult, result);
  }
  private <E> void listTest(List<E> expResult, List<E> result) {
    listTest(expResult, result, true);
  }
  private <E> void listTest(List<E> expResult, List<E> result, boolean recurse) {
    assertEquals(expResult, result);
    assertEquals(expResult.size(), result.size());
    assertEquals(
      "expResult class: "+expResult.getClass().getSimpleName()+
      " result class: "+result.getClass().getSimpleName(),
      expResult.toString(), result.toString());
    assertEquals(expResult.hashCode(), result.hashCode());
    assertTrue(Arrays.equals(expResult.toArray(), result.toArray()));
    @SuppressWarnings("unchecked")
    final E[] ref = (E[])new Object[0];
{'fraction_non_alphanumeric': 0.12190709994185671, 'fraction_numerical': 0.02022094450545901, 'mean_word_length': 4.352697095435684, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '419160', 'n_tokens_mistral': 4749, 'n_tokens_neox': 4723, 'n_words': 1213}