<commit_before>package interviewquestions.java;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Return all subsets of a set.
 */
public class Powersets {
  public static <T> Set<Set<T>> powerset(Set<T> set) {
    Set<Set<T>> pset = new HashSet<Set<T>>();
    Set<T> tmp;

    pset.add(set);
    for (T item : set) {
      tmp = new HashSet<T>(set);
      tmp.remove(item);
      pset.addAll(powerset(tmp));
    }

    return pset;
  }

  public static void main(String[] args) {
    Set<Integer> initial = new HashSet<Integer>(Arrays.asList(1, 2, 3));
    Set<Set<Integer>> powerset = powerset(initial);

    test(powerset.size() == 8);
    test(powerset.contains(new HashSet<Integer>()));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(1))));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(2))));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(3))));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(1, 2))));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(1, 3))));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(2, 3))));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(1, 2, 3))));
  }

  public static void test(boolean condition) {
    // assertions are disabled by default in java, mimic their behaviour here
    if (!condition) {
      throw new AssertionError("invalid test");<commit_msg>added test for edge case<commit_after>package interviewquestions.java;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Return all subsets of a set.
 */
public class Powersets {
  public static <T> Set<Set<T>> powerset(Set<T> set) {
    Set<Set<T>> pset = new HashSet<Set<T>>();
    Set<T> tmp;

    pset.add(set);
    for (T item : set) {
      tmp = new HashSet<T>(set);
      tmp.remove(item);
      pset.addAll(powerset(tmp));
    }

    return pset;
  }

  public static void main(String[] args) {
    Set<Integer> initial = new HashSet<Integer>(Arrays.asList(1, 2, 3));
    Set<Set<Integer>> powerset = powerset(initial);

    test(powerset.size() == 8);
    test(powerset.contains(new HashSet<Integer>()));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(1))));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(2))));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(3))));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(1, 2))));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(1, 3))));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(2, 3))));
    test(powerset.contains(new HashSet<Integer>(Arrays.asList(1, 2, 3))));

    // the powerset is never empty, it always contains at least the empty set
    initial = new HashSet<Integer>();
    test(powerset(initial).size() == 1);
    test(powerset(initial).contains(initial));
  }

  public static void test(boolean condition) {
    // assertions are disabled by default in java, mimic their behaviour here
    if (!condition) {
      throw new AssertionError("invalid test");
{'fraction_non_alphanumeric': 0.15866320571057754, 'fraction_numerical': 0.010707332900713823, 'mean_word_length': 4.261092150170649, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 48, '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': '5699943', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1025, 'n_words': 222}