/*
 * Copyright 2018, Yahoo! Inc. Licensed under the terms of the
 * Apache License 2.0. See LICENSE file at the project root for terms.
 */

package com.yahoo.sketches.cpc;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

import org.testng.annotations.Test;

import com.yahoo.sketches.SketchesArgumentException;
import com.yahoo.sketches.SketchesStateException;

/**
 * @author Lee Rhodes
 */
public class CpcUnionTest {

  @Test
  public void checkExceptions() {
    CpcSketch sk = new CpcSketch(10, 1);
    CpcUnion union = new CpcUnion(10);
    try {
      union.update(sk);
      fail();
    } catch (SketchesArgumentException e) {}
    sk = null;
    union.update(sk);
    union = null;
    try {
      CpcUnion.getBitMatrix(union);
      fail();
    } catch (SketchesStateException e) {}
    union = new CpcUnion(10);
  }

  @Test
  public void checkGetters() {
    int lgK = 10;
    CpcUnion union = new CpcUnion(lgK);
    assertEquals(union.getLgK(), lgK);
    assertEquals(union.getNumCoupons(), 0L);
    CpcSketch sk = new CpcSketch(lgK);
    for (int i = 0; i <= (4 << lgK); i++) { sk.update(i); }
    union.update(sk);
    assertTrue(union.getNumCoupons() > 0);
    assertTrue(CpcUnion.getBitMatrix(union) != null);

  }

}

@@ -1309,10 +1309,577 @@
 ;%0A%0A  %7D%0A%0A
+  @Test%0A  public void checkReduceK() %7B%0A    CpcUnion union = new CpcUnion(12);%0A    CpcSketch sk = new CpcSketch(11);%0A    int u = 1;%0A    sk.update(u);%0A    union.update(sk);%0A    CpcUnion.getBitMatrix(union);%0A    CpcSketch sk2 = new CpcSketch(10);%0A    int shTrans = ((3 * 512) / 32); //sparse-hybrid transition for lgK=9%0A    while (sk2.numCoupons %3C shTrans) %7B sk2.update(++u); %7D%0A    union.update(sk2);%0A    CpcSketch sk3 = new CpcSketch(9);%0A    sk3.update(++u);%0A    union.update(sk3);%0A    CpcSketch sk4 = new CpcSketch(8);%0A    sk4.update(++u);%0A    union.update(sk4);%0A  %7D%0A%0A
 %7D%0A

Add unit tests