package water.fvec;

import org.testng.AssertJUnit;
import org.testng.annotations.Test;
import water.TestUtil;

import java.util.Arrays;

public class C2SChunkTest extends TestUtil {
  @Test void test_inflate_impl() {
    for (int l=0; l<1; ++l) {
      NewChunk nc = new NewChunk(null, 0);

      // -32.767, 0.34, 0, 32.767, NA for l==0
      // NA, -32.767, 0.34, 0, 32.767, NA for l==1
      int[] man = new int[]{-32767, 34, 0, 32767};
      int[] exp = new int[]{-3, -2, 1, -3};
      if (l==1) nc.addNA(); //-32768
      for (int i = 0; i < man.length; ++i) nc.addNum(man[i], exp[i]);
      nc.addNA();

      Chunk cc = nc.compress();
      AssertJUnit.assertEquals(man.length + 1 + l, cc.len());
      AssertJUnit.assertTrue(cc instanceof C2SChunk);
      if (l==1) AssertJUnit.assertTrue(cc.isNA0(0));
      for (int i = 0; i < man.length; ++i)
        AssertJUnit.assertEquals((float) (man[i] * Math.pow(10, exp[i])), (float) cc.at0(l + i));
      AssertJUnit.assertTrue(cc.isNA0(man.length + l));

      Chunk cc2 = cc.inflate_impl(new NewChunk(null, 0)).compress();
      AssertJUnit.assertEquals(man.length + 1 + l, cc.len());
      if (l==1) AssertJUnit.assertTrue(cc2.isNA0(0));
      for (int i = 0; i < man.length; ++i)
        AssertJUnit.assertEquals((float) (man[i] * Math.pow(10, exp[i])), (float) cc2.at0(l + i));
      AssertJUnit.assertTrue(cc2.isNA0(man.length + l));
      AssertJUnit.assertTrue(cc2 instanceof C2SChunk);

      AssertJUnit.assertTrue(Arrays.equals(cc._mem, cc2._mem));
    }
  }
}

@@ -393,32 +393,1280 @@
     
-int%5B%5D man = new int
+long%5B%5D man = new long%5B%5D%7B-32767, 34, 0, 32767%7D;%0A      int%5B%5D exp = new int%5B%5D%7B-3, -2, 1, -3%7D;%0A      if (l==1) nc.addNA(); //-32768%0A      for (int i = 0; i %3C man.length; ++i) nc.addNum(man%5Bi%5D, exp%5Bi%5D);%0A      nc.addNA();%0A%0A      Chunk cc = nc.compress();%0A      AssertJUnit.assertEquals(man.length + 1 + l, cc.len());%0A      AssertJUnit.assertTrue(cc instanceof C2SChunk);%0A      if (l==1) AssertJUnit.assertTrue(cc.isNA0(0));%0A      for (int i = 0; i %3C man.length; ++i)%0A        AssertJUnit.assertEquals((float) (man%5Bi%5D * Math.pow(10, exp%5Bi%5D)), (float) cc.at0(l + i));%0A      AssertJUnit.assertTrue(cc.isNA0(man.length + l));%0A%0A      Chunk cc2 = cc.inflate_impl(new NewChunk(null, 0)).compress();%0A      AssertJUnit.assertEquals(man.length + 1 + l, cc.len());%0A      if (l==1) AssertJUnit.assertTrue(cc2.isNA0(0));%0A      for (int i = 0; i %3C man.length; ++i)%0A        AssertJUnit.assertEquals((float) (man%5Bi%5D * Math.pow(10, exp%5Bi%5D)), (float) cc2.at0(l + i));%0A      AssertJUnit.assertTrue(cc2.isNA0(man.length + l));%0A      AssertJUnit.assertTrue(cc2 instanceof C2SChunk);%0A%0A      AssertJUnit.assertTrue(Arrays.equals(cc._mem, cc2._mem));%0A    %7D%0A  %7D%0A  @Test void test_inflate_impl2() %7B%0A    for (int l=0; l%3C1; ++l) %7B%0A      NewChunk nc = new NewChunk(null, 0);%0A%0A      long%5B%5D man = new long
 %5B%5D%7B-
-3
+1
 2767
@@ -1666,33 +1666,33 @@
 %7B-12767, 34, 0, 
-3
+5
 2767%7D;%0A      int

Add more tests for C2SChunk.