<commit_before>package water.util;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import water.TestUtil;

import java.util.Random;

public class IcedBitSetTest extends TestUtil {
  @BeforeClass() public static void setup() { stall_till_cloudsize(1); }

  static void check(IcedBitSet bs, int bitoff, Integer[] idx) {
    String correct = "{";
    if (bitoff > 0) {
      correct += "..." + bitoff + " 0-bits... ";
    }
    for (int i=bitoff; i<bs.size(); ++i) {
      if (ArrayUtils.find(idx, i) != -1) {
        Assert.assertTrue(bs.contains(i));
        correct +="1";
      }
      else {
        Assert.assertTrue(!bs.contains(i));
        correct +="0";
      }
      if ((i-bitoff+1)%8 == 0 && i != bs.size()-1) correct += " ";
    }
    correct += "}";
    String s = bs.toString();
//    System.out.println(s);
//    System.out.println(correct);
    Assert.assertTrue(s.equals(correct));
  }

  static void fill(IcedBitSet bs, Integer[] idx) {
    Random rng = new Random();
    for (int i = 0; i < idx.length; ++i) {
      idx[i] = rng.nextInt(bs.size());
      bs.set(idx[i]);
    }
  }

  @Test public void fill8() {
    int len = 8;
    IcedBitSet bs = new IcedBitSet(len);
    Integer[] idx = new Integer[(int) Math.floor(len / 2)];
    fill(bs, idx);
    Assert.assertEquals(bs.size(), 32);
    check(bs, 0, idx);
  }

  @Test public void fill17() {
    int len = 17;
    IcedBitSet bs = new IcedBitSet(len);
    Integer[] idx = new Integer[(int) Math.floor(len / 2)];<commit_msg>PUBDEV-6044: IcedBitSetTest does not need and does not use running H2O; also, changed assertion to produce more informative error messages<commit_after>package water.util;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

import java.util.Random;

public class IcedBitSetTest {
  static void check(IcedBitSet bs, int bitoff, Integer[] idx) {
    String correct = "{";
    if (bitoff > 0) {
      correct += "..." + bitoff + " 0-bits... ";
    }
    for (int i=bitoff; i<bs.size(); ++i) {
      if (ArrayUtils.find(idx, i) != -1) {
        Assert.assertTrue(bs.contains(i));
        correct +="1";
      }
      else {
        Assert.assertTrue(!bs.contains(i));
        correct +="0";
      }
      if ((i-bitoff+1)%8 == 0 && i != bs.size()-1) correct += " ";
    }
    correct += "}";
    String s = bs.toString();
    Assert.assertEquals(correct, s);
  }

  static void fill(IcedBitSet bs, Integer[] idx) {
    Random rng = new Random();
    for (int i = 0; i < idx.length; ++i) {
      idx[i] = rng.nextInt(bs.size());
      bs.set(idx[i]);
    }
  }

  @Test public void fill8() {
    int len = 8;
    IcedBitSet bs = new IcedBitSet(len);
    Integer[] idx = new Integer[(int) Math.floor(len / 2)];
    fill(bs, idx);
    Assert.assertEquals(bs.size(), 32);
    check(bs, 0, idx);
  }

  @Test public void fill17() {
    int len = 17;
    IcedBitSet bs = new IcedBitSet(len);
    Integer[] idx = new Integer[(int) Math.floor(len / 2)];
{'fraction_non_alphanumeric': 0.17141909814323608, 'fraction_numerical': 0.015915119363395226, 'mean_word_length': 2.648125755743652, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3134405', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1057, 'n_words': 267}