<commit_before>//////////////////////////////////////////////////////////////////////////////
// 
//               Copyright 2010, Starting Block Technologies
//                        www.startingblocktech.com
//                           All Rights Reserved
//
//////////////////////////////////////////////////////////////////////////////

package com.startingblocktech.tcases.util;

import static org.junit.Assert.*;

import org.apache.commons.collections15.CollectionUtils;
import org.apache.commons.collections15.IteratorUtils;
import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * Defines test assertion utilities.
 *
 * @version $Revision$, $Date$
 */
public abstract class Asserts
  {
  /**
   * Reports a failure if the actual Collection contains a different set of values than the expected Collection.
   */
  public static <T> void assertSetEquals( String label, Collection<T> expected, Collection<T> actual)
    {
    if( (expected == null) != (actual == null))
      {
      assertEquals( label, expected, actual);
      }

    else if( expected != null)
      {
      Collection<T> unexpected = CollectionUtils.subtract( actual, expected);
      Collection<T> missing = CollectionUtils.subtract( expected, actual);

      if( !(unexpected.isEmpty() && missing.isEmpty()))
        {
        StringBuilder msg = new StringBuilder();

        msg.append( label);
        if( !missing.isEmpty())
          {
          msg.append( ", missing=").append( '[').append( StringUtils.join( missing, ',')).append( ']');
          }
        if( !unexpected.isEmpty())
          {
          msg.append( ", unexpected=").append( '[').append( StringUtils.join( unexpected, ',')).append( ']');
          }

        fail( msg.toString());
        }
      }
    }

  /**
   * Reports a failure if the actual Collection contains a different set of values than the expected array.
   */
  public static <T> void assertSetEquals( String label, T[] expected, Collection<T> actual)
    {
    List<T> expectedList = expected == null ? null : Arrays.asList( expected);
    assertSetEquals( label, expectedList, actual);
    }

  /**
   * Reports a failure if the actual collection contains a different set of values than the expected array.
   */
  public static <T> void assertSetEquals( String label, T[] expected, Iterator<T> actual)
    {
    List<T> expectedList = expected == null ? null : Arrays.asList( expected);
    List<T> actualList = actual == null ? null : IteratorUtils.toList( actual);
    assertSetEquals( label, expectedList, actualList);
    }

  /**
   * Reports a failure if the actual Iterator contains a different sequence of values than the expected List.
   */
  public static <T> void assertSeqEquals( String label, List<T> expected, Iterator<T> actual)
    {
    if( (expected == null) !=(actual == null))
      {
      fail( label
            + " expected: "
            + (expected == null ? null : "[" + StringUtils.join( expected, ",") + "]")
            + ", but was: "
            + (actual == null ? null : "[" + StringUtils.join( IteratorUtils.toArray( actual), ",")
               + "]"));<commit_msg>Add assertSetEquals( String, Collection, Iterator)<commit_after>//////////////////////////////////////////////////////////////////////////////
// 
//               Copyright 2010, Starting Block Technologies
//                        www.startingblocktech.com
//                           All Rights Reserved
//
//////////////////////////////////////////////////////////////////////////////

package com.startingblocktech.tcases.util;

import static org.junit.Assert.*;

import org.apache.commons.collections15.CollectionUtils;
import org.apache.commons.collections15.IteratorUtils;
import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * Defines test assertion utilities.
 *
 * @version $Revision$, $Date$
 */
public abstract class Asserts
  {
  /**
   * Reports a failure if the actual Collection contains a different set of values than the expected Collection.
   */
  public static <T> void assertSetEquals( String label, Collection<T> expected, Collection<T> actual)
    {
    if( (expected == null) != (actual == null))
      {
      assertEquals( label, expected, actual);
      }

    else if( expected != null)
      {
      Collection<T> unexpected = CollectionUtils.subtract( actual, expected);
      Collection<T> missing = CollectionUtils.subtract( expected, actual);

      if( !(unexpected.isEmpty() && missing.isEmpty()))
        {
        StringBuilder msg = new StringBuilder();

        msg.append( label);
        if( !missing.isEmpty())
          {
          msg.append( ", missing=").append( '[').append( StringUtils.join( missing, ',')).append( ']');
          }
        if( !unexpected.isEmpty())
          {
          msg.append( ", unexpected=").append( '[').append( StringUtils.join( unexpected, ',')).append( ']');
          }

        fail( msg.toString());
        }
      }
    }
  /**
   * Reports a failure if the actual Collection contains a different set of values than the expected Collection.
   */
  public static <T> void assertSetEquals( String label, Collection<T> expected, Iterator<T> actual)
    {
    List<T> actualList = actual == null ? null : IteratorUtils.toList( actual);
    assertSetEquals( label, expected, actualList);
    }

  /**
   * Reports a failure if the actual Collection contains a different set of values than the expected array.
   */
  public static <T> void assertSetEquals( String label, T[] expected, Collection<T> actual)
    {
    List<T> expectedList = expected == null ? null : Arrays.asList( expected);
    assertSetEquals( label, expectedList, actual);
    }

  /**
   * Reports a failure if the actual collection contains a different set of values than the expected array.
   */
  public static <T> void assertSetEquals( String label, T[] expected, Iterator<T> actual)
    {
    List<T> expectedList = expected == null ? null : Arrays.asList( expected);
    assertSetEquals( label, expectedList, actual);
    }

  /**
   * Reports a failure if the actual Iterator contains a different sequence of values than the expected List.
   */
  public static <T> void assertSeqEquals( String label, List<T> expected, Iterator<T> actual)
    {
    if( (expected == null) !=(actual == null))
      {
      fail( label
            + " expected: "
            + (expected == null ? null : "[" + StringUtils.join( expected, ",") + "]")
            + ", but was: "
            + (actual == null ? null : "[" + StringUtils.join( IteratorUtils.toArray( actual), ",")
               + "]"));
{'fraction_non_alphanumeric': 0.16934651128485026, 'fraction_numerical': 0.002360230122436938, 'mean_word_length': 2.289665211062591, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, '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': '7145146', 'n_tokens_mistral': 1790, 'n_tokens_neox': 1749, 'n_words': 540}