コード例 #1
0
ファイル: GProductTest.java プロジェクト: adiffer/Clados
  @Test
  public void testProductResult() {
    int tS = (int) Math.pow(2, 12);
    int tSum = tS * (tS + 1) / 2;
    for (short k = 0; k < tGP12.getBladeCount(); k++) {
      short[] tSpot = tGP12.getResult(k);
      int tSumP = 0;
      for (int j = 0; j < tSpot.length; j++) {
        tSumP += Math.abs(tSpot[j]);
      }
      assertTrue(tSum == tSumP);
    }

    tS = (int) Math.pow(2, 8);
    tSum = tS * (tS + 1) / 2;
    for (short k = 0; k < tGP8.getBladeCount(); k++) {
      short[] tSpot = tGP8.getResult(k);
      int tSumP = 0;
      for (int j = 0; j < tSpot.length; j++) {
        tSumP += Math.abs(tSpot[j]);
      }
      assertTrue(tSum == tSumP);
    }

    tS = (int) Math.pow(2, 4);
    tSum = tS * (tS + 1) / 2;
    for (short k = 0; k < tGP4.getBladeCount(); k++) {
      short[] tSpot = tGP4.getResult(k);
      int tSumP = 0;
      for (int j = 0; j < tSpot.length; j++) {
        tSumP += Math.abs(tSpot[j]);
      }
      assertTrue(tSum == tSumP);
    }
  }
コード例 #2
0
ファイル: GProductTest.java プロジェクト: adiffer/Clados
 @Test
 public void testBladeCount() {
   assertTrue(tGP4.getBladeCount() == Math.pow(2, 4));
   assertTrue(tGP8.getBladeCount() == Math.pow(2, 8));
   // assertTrue(tGP10.getBladeCount() == Math.pow(2, 10));
   assertTrue(tGP12.getBladeCount() == Math.pow(2, 12));
 }
コード例 #3
0
 int integerBreak(int n) {
   if (n == 2 || n == 3) return n - 1;
   int div = n / 3;
   int reminder = n % 3;
   if (reminder == 1) return (int) Math.pow(3, div - 1) * 4;
   else if (reminder == 0) return (int) Math.pow(3, div);
   return (int) Math.pow(3, div) * 2;
 }
コード例 #4
0
ファイル: C2SChunkTest.java プロジェクト: CodEnFisH/h2o-dev
  @Test
  public void test_inflate_impl() {
    for (int l = 0; l < 2; ++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
      long[] man = new long[] {-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();
      Assert.assertEquals(man.length + 1 + l, cc.len());
      Assert.assertTrue(cc instanceof C2SChunk);
      if (l == 1) {
        Assert.assertTrue(cc.isNA0(0));
        Assert.assertTrue(cc.isNA(0));
      }
      for (int i = 0; i < man.length; ++i) {
        Assert.assertEquals((float) (man[i] * Math.pow(10, exp[i])), (float) cc.at0(l + i), 0);
        Assert.assertEquals((float) (man[i] * Math.pow(10, exp[i])), (float) cc.at(l + i), 0);
      }
      Assert.assertTrue(cc.isNA0(man.length + l));
      Assert.assertTrue(cc.isNA(man.length + l));

      nc = cc.inflate_impl(new NewChunk(null, 0));
      nc.values(0, nc.len());
      Assert.assertEquals(man.length + 1 + l, nc.len());
      Assert.assertEquals(man.length + 1 + l, nc.sparseLen());
      if (l == 1) {
        Assert.assertTrue(nc.isNA0(0));
        Assert.assertTrue(nc.isNA(0));
      }
      for (int i = 0; i < man.length; ++i) {
        Assert.assertEquals((float) (man[i] * Math.pow(10, exp[i])), (float) nc.at0(l + i), 0);
        Assert.assertEquals((float) (man[i] * Math.pow(10, exp[i])), (float) nc.at(l + i), 0);
      }
      Assert.assertTrue(nc.isNA0(man.length + l));
      Assert.assertTrue(nc.isNA(man.length + l));

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

      Assert.assertTrue(Arrays.equals(cc._mem, cc2._mem));
    }
  }
コード例 #5
0
  /** Test method for {@link GroupElement#toRadix16(byte[])}. */
  @Test
  public void testToRadix16() {
    assertThat(GroupElement.toRadix16(BYTES_ZERO), is(RADIX16_ZERO));
    assertThat(GroupElement.toRadix16(BYTES_ONE), is(RADIX16_ONE));
    assertThat(GroupElement.toRadix16(BYTES_42), is(RADIX16_42));

    byte[] from1234567890 = GroupElement.toRadix16(BYTES_1234567890);
    int total = 0;
    for (int i = 0; i < from1234567890.length; i++) {
      assertThat(from1234567890[i], is(greaterThanOrEqualTo((byte) -8)));
      assertThat(from1234567890[i], is(lessThanOrEqualTo((byte) 8)));
      total += from1234567890[i] * Math.pow(16, i);
    }
    assertThat(total, is(1234567890));

    byte[] pkrR16 = GroupElement.toRadix16(BYTES_PKR);
    for (int i = 0; i < pkrR16.length; i++) {
      assertThat(pkrR16[i], is(greaterThanOrEqualTo((byte) -8)));
      assertThat(pkrR16[i], is(lessThanOrEqualTo((byte) 8)));
    }
  }