当前位置: 首页>>代码示例>>Java>>正文


Java From类代码示例

本文整理汇总了Java中com.pholser.junit.quickcheck.From的典型用法代码示例。如果您正苦于以下问题:Java From类的具体用法?Java From怎么用?Java From使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


From类属于com.pholser.junit.quickcheck包,在下文中一共展示了From类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: whenPuttingAResourceAndMethodThrows_DoNotCreateTheResource

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Property
public void whenPuttingAResourceAndMethodThrows_DoNotCreateTheResource(
        @NonMeta @NonAbstract AttributeType type, @From(ResourceValues.class) Object value) {

    Collection previousResources = (Collection) type.instances().collect(toSet());

    try {
        type.putAttribute(value);
        assumeTrue("Assumed putResource would throw", false);
    } catch (GraknTxOperationException e) {
        // This is expected to throw
    }

    Collection newResources = (Collection) type.instances().collect(toSet());

    assertEquals(previousResources.size(), newResources.size());
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:18,代码来源:AttributeTypePropertyTest.java

示例2: testLegalMoves

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void testLegalMoves(@ForAll(sampleSize = 10) @From(GameGenerator.class) Game game) throws Exception {
    Game.Event[] moves = game.getLegalMoves();

    boolean containsHire = false;
    boolean containsWait = false;
    boolean containsObserve = false;
    boolean containsTurnIn = false;

    for (Game.Event e : moves) {
        if (e instanceof Game.HumanJobPosting) containsHire = true;
        if (e instanceof Game.Wait) containsWait = true;
        if (e instanceof Game.QueryLaunch) containsObserve = true;
        if (e instanceof Game.TurnIn) containsTurnIn = true;
    }

    assertTrue(containsHire);
    assertFalse(containsWait);
    assertFalse(containsObserve);
    assertTrue(containsTurnIn);
}
 
开发者ID:keenon,项目名称:lense,代码行数:22,代码来源:GameTest.java

示例3: reportsFailure

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void reportsFailure(@ForAll @From(Encoded.class) @Encoded.InCharset("US-ASCII") String value,
    @TestedOn(ints = {1, 2, 3, 5, 100}) int bufferSize) throws Exception {
  assumeTrue(value.indexOf('\r') == -1 && value.indexOf('\n') == -1);
  assumeThat(value.length(), greaterThan(0));

  Appendable appendable = mock(Appendable.class);
  RuntimeException e1 = new RuntimeException();
  RuntimeException e2 = new RuntimeException();
  when(appendable.append(anyChar())).thenThrow(e1, e2);

  ByteBuffer src = ByteBuffer.wrap((value + "\r\n").getBytes(US_ASCII));
  assertThat(parseReply(src, bufferSize, new CharAppendingParser<>(() -> appendable), assertNoResult(), e -> e,
      charsetDecoder), equalTo(e1));
  verifyZeroInteractions(charsetDecoder);
  verify(appendable, times(value.length())).append(anyChar());
  verifyNoMoreInteractions(appendable);
}
 
开发者ID:vkorenev,项目名称:RedRadishes,代码行数:19,代码来源:CharAppendingParserTest.java

示例4: infos_with_same_values_should_be_equal

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Property
public void infos_with_same_values_should_be_equal(
    final String keyword,
    final String name,
    final List<@From(ArgumentGenerator.class) Argument> arguments
) throws Exception {
    final BasicInfo leftInfo = new BasicInfo(
        keyword,
        name,
        arguments
    );

    final BasicInfo rightInfo = new BasicInfo(
        keyword,
        name,
        arguments
    );

    assertThat(leftInfo).isEqualTo(rightInfo);
    assertThat(leftInfo.hashCode()).isEqualTo(rightInfo.hashCode());
}
 
开发者ID:pgentile,项目名称:zucchini-ui,代码行数:22,代码来源:BasicInfoPropertiesTest.java

示例5: testCompileNormalizedModel

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void testCompileNormalizedModel(@ForAll(sampleSize = 1000) @From(GraphicalModelGenerator.class) GraphicalModel model,
                                       @ForAll(sampleSize = 10) @From(WeightsGenerator.class) ConcatVector weights) throws Exception {
  CliqueTree.MarginalResult unnormalizedSolve = new CliqueTree(model, weights).calculateMarginals();
  GraphicalModel normalized = new CliqueTree(model, weights).compileNormalizedModel();
  CliqueTree.MarginalResult normalizedSolve = new CliqueTree(normalized, weights).calculateMarginals();
  assertEquals(unnormalizedSolve, normalizedSolve);


  double partitionWithWeights = normalizedSolve.partitionFunction;
  double partitionWithoutWeights = new CliqueTree(normalized, new ConcatVector(0)).calculateMarginals().partitionFunction;
  assertEquals(partitionWithoutWeights, partitionWithWeights, 1e-5);
  assertFalse(Double.isNaN(partitionWithoutWeights));
  assertFalse(Double.isNaN(partitionWithWeights));
  assertEquals(1.0, partitionWithWeights, 1e-5);
  assertEquals(1.0, partitionWithoutWeights, 1e-5);
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:18,代码来源:CliqueTreeTest.java

示例6: testConstructWithObservations

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void testConstructWithObservations(@ForAll(sampleSize = 50) @From(PartiallyObservedConstructorDataGenerator.class) PartiallyObservedConstructorData data,
                                          @ForAll(sampleSize = 2) @From(ConcatVectorGenerator.class) ConcatVector weights) throws Exception {
  int[] obsArray = new int[9];
  for (int i = 0; i < obsArray.length; i++) obsArray[i] = -1;
  for (int i = 0; i < data.observations.length; i++) {
    obsArray[data.factor.neigborIndices[i]] = data.observations[i];
  }

  TableFactor normalObservations = new TableFactor(weights, data.factor);
  for (int i = 0; i < obsArray.length; i++) {
    if (obsArray[i] != -1) {
      normalObservations = normalObservations.observe(i, obsArray[i]);
    }
  }

  TableFactor constructedObservations = new TableFactor(weights, data.factor, data.observations);

  assertArrayEquals(normalObservations.neighborIndices, constructedObservations.neighborIndices);
  for (int[] assn : normalObservations) {
    assertEquals(normalObservations.getAssignmentValue(assn), constructedObservations.getAssignmentValue(assn), 1.0e-9);
  }
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:24,代码来源:TableFactorTest.java

示例7: testObserve

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void testObserve(@ForAll(sampleSize = 50) @From(TableFactorGenerator.class) TableFactor factor,
                        @ForAll(sampleSize = 2) @InRange(minInt = 0, maxInt = 3) int observe,
                        @ForAll(sampleSize = 2) @InRange(minInt = 0, maxInt = 1) int value) throws Exception {
  if (!Arrays.stream(factor.neighborIndices).boxed().collect(Collectors.toSet()).contains(observe)) return;
  if (factor.neighborIndices.length == 1) return;

  TableFactor observedOut = factor.observe(observe, value);

  int observeIndex = -1;
  for (int i = 0; i < factor.neighborIndices.length; i++) {
    if (factor.neighborIndices[i] == observe) observeIndex = i;
  }

  for (int[] assignment : factor) {
    if (assignment[observeIndex] == value) {
      assertEquals(factor.getAssignmentValue(assignment), observedOut.getAssignmentValue(subsetAssignment(assignment, factor, observedOut)), 1.0e-7);
    }
  }
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:21,代码来源:TableFactorTest.java

示例8: testGetMaxedMarginals

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void testGetMaxedMarginals(@ForAll(sampleSize = 50) @From(TableFactorGenerator.class) TableFactor factor,
                                  @ForAll(sampleSize = 10) @InRange(minInt = 0, maxInt = 3) int marginalizeTo) throws Exception {
  if (!Arrays.stream(factor.neighborIndices).boxed().collect(Collectors.toSet()).contains(marginalizeTo)) return;

  int indexOfVariable = -1;
  for (int i = 0; i < factor.neighborIndices.length; i++) {
    if (factor.neighborIndices[i] == marginalizeTo) {
      indexOfVariable = i;
      break;
    }
  }
  assumeTrue(indexOfVariable > -1);

  double[] gold = new double[factor.getDimensions()[indexOfVariable]];
  for (int i = 0; i < gold.length; i++) {
    gold[i] = Double.NEGATIVE_INFINITY;
  }
  for (int[] assignment : factor) {
    gold[assignment[indexOfVariable]] = Math.max(gold[assignment[indexOfVariable]], factor.getAssignmentValue(assignment));
  }

  normalize(gold);

  assertArrayEquals(gold, factor.getMaxedMarginals()[indexOfVariable], 1.0e-5);
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:27,代码来源:TableFactorTest.java

示例9: testGetSummedMarginals

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void testGetSummedMarginals(@ForAll(sampleSize = 50) @From(TableFactorGenerator.class) TableFactor factor,
                                   @ForAll(sampleSize = 10) @InRange(minInt = 0, maxInt = 3) int marginalizeTo) throws Exception {
  if (!Arrays.stream(factor.neighborIndices).boxed().collect(Collectors.toSet()).contains(marginalizeTo)) return;

  int indexOfVariable = -1;
  for (int i = 0; i < factor.neighborIndices.length; i++) {
    if (factor.neighborIndices[i] == marginalizeTo) {
      indexOfVariable = i;
      break;
    }
  }
  assumeTrue(indexOfVariable > -1);

  double[] gold = new double[factor.getDimensions()[indexOfVariable]];
  for (int[] assignment : factor) {
    gold[assignment[indexOfVariable]] = gold[assignment[indexOfVariable]] + factor.getAssignmentValue(assignment);
  }

  normalize(gold);

  assertArrayEquals(gold, factor.getSummedMarginals()[indexOfVariable], 1.0e-5);
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:24,代码来源:TableFactorTest.java

示例10: testSumOut

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void testSumOut(@ForAll(sampleSize = 50) @From(TableFactorGenerator.class) TableFactor factor,
                       @ForAll(sampleSize = 10) @InRange(minInt = 0, maxInt = 3) int marginalize) throws Exception {
  if (!Arrays.stream(factor.neighborIndices).boxed().collect(Collectors.toSet()).contains(marginalize)) return;
  if (factor.neighborIndices.length <= 1) return;

  TableFactor summedOut = factor.sumOut(marginalize);

  assertEquals(factor.neighborIndices.length - 1, summedOut.neighborIndices.length);
  assertTrue(!Arrays.stream(summedOut.neighborIndices).boxed().collect(Collectors.toSet()).contains(marginalize));

  Map<List<Integer>, List<int[]>> subsetToSuperset = subsetToSupersetAssignments(factor, summedOut);
  for (List<Integer> subsetAssignmentList : subsetToSuperset.keySet()) {
    double sum = 0.0;
    for (int[] supersetAssignment : subsetToSuperset.get(subsetAssignmentList)) {
      sum += factor.getAssignmentValue(supersetAssignment);
    }

    int[] subsetAssignment = new int[subsetAssignmentList.size()];
    for (int i = 0; i < subsetAssignment.length; i++) {
      subsetAssignment[i] = subsetAssignmentList.get(i);
    }

    assertEquals(sum, summedOut.getAssignmentValue(subsetAssignment), 1.0e-5);
  }
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:27,代码来源:TableFactorTest.java

示例11: testMultiply

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void testMultiply(@ForAll(sampleSize = 10) @From(TableFactorGenerator.class) TableFactor factor1,
                         @ForAll(sampleSize = 10) @From(TableFactorGenerator.class) TableFactor factor2) throws Exception {
  TableFactor result = factor1.multiply(factor2);

  for (int[] assignment : result) {
    double factor1Value = factor1.getAssignmentValue(subsetAssignment(assignment, result, factor1));
    double factor2Value = factor2.getAssignmentValue(subsetAssignment(assignment, result, factor2));
    assertEquals(factor1Value * factor2Value, result.getAssignmentValue(assignment), 1.0e-5);
  }

  // Check for no duplication
  for (int i = 0; i < result.neighborIndices.length; i++) {
    for (int j = 0; j < result.neighborIndices.length; j++) {
      if (i == j) continue;
      assertNotSame(result.neighborIndices[i], result.neighborIndices[j]);
    }
  }
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:20,代码来源:TableFactorTest.java

示例12: testResizeOnSetComponent

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void testResizeOnSetComponent(@ForAll(sampleSize = 50) @From(MapGenerator.class) Map<Integer,Integer> featureMap1,
                                     @ForAll(sampleSize = 50) @From(MapGenerator.class) Map<Integer,Integer> featureMap2) {
    ConcatVectorNamespace namespace = new ConcatVectorNamespace();

    ConcatVector namespace1 = toNamespaceVector(namespace, featureMap1);
    ConcatVector namespace2 = toNamespaceVector(namespace, featureMap2);

    ConcatVector regular1 = toVector(featureMap1);
    ConcatVector regular2 = toVector(featureMap2);

    assertEquals(regular1.dotProduct(regular2), namespace1.dotProduct(namespace2), 1.0e-5);

    ConcatVector namespaceSum = namespace1.deepClone();
    namespaceSum.addVectorInPlace(namespace2, 1.0);

    ConcatVector regularSum = regular1.deepClone();
    regularSum.addVectorInPlace(regular2, 1.0);

    assertEquals(regular1.dotProduct(regularSum), namespace1.dotProduct(namespaceSum), 1.0e-5);
    assertEquals(regularSum.dotProduct(regular2), namespaceSum.dotProduct(namespace2), 1.0e-5);
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:23,代码来源:ConcatVectorNamespaceTest.java

示例13: testProtoNamespace

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void testProtoNamespace(@ForAll(sampleSize = 50) @From(NamespaceGenerator.class) ConcatVectorNamespace namespace) throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    namespace.writeToStream(byteArrayOutputStream);
    byteArrayOutputStream.close();

    byte[] bytes = byteArrayOutputStream.toByteArray();

    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);

    ConcatVectorNamespace recovered = ConcatVectorNamespace.readFromStream(byteArrayInputStream);

    assertEquals(namespace.featureToIndex, recovered.featureToIndex);
    assertEquals(namespace.sparseFeatureIndex, recovered.sparseFeatureIndex);
    assertEquals(namespace.reverseSparseFeatureIndex, recovered.reverseSparseFeatureIndex);
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:18,代码来源:ConcatVectorNamespaceTest.java

示例14: testProtoTable

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void testProtoTable(@ForAll(sampleSize = 50) @From(FeatureFactorGenerator.class) ConcatVector[][][] factor3) throws IOException {
    ConcatVectorTable concatVectorTable = convertArrayToVectorTable(factor3);

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    concatVectorTable.writeToStream(byteArrayOutputStream);
    byteArrayOutputStream.close();

    byte[] bytes = byteArrayOutputStream.toByteArray();

    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);

    ConcatVectorTable recovered = ConcatVectorTable.readFromStream(byteArrayInputStream);
    for (int i = 0; i < factor3.length; i++) {
        for (int j = 0; j < factor3[0].length; j++) {
            for (int k = 0; k < factor3[0][0].length; k++) {
                assertTrue(factor3[i][j][k].valueEquals(recovered.getAssignmentValue(new int[]{i, j, k}).get(), 1.0e-5));
            }
        }
    }
    assertTrue(concatVectorTable.valueEquals(recovered, 1.0e-5));
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:23,代码来源:ConcatVectorTableTest.java

示例15: testProtoBatch

import com.pholser.junit.quickcheck.From; //导入依赖的package包/类
@Theory
public void testProtoBatch(@ForAll(sampleSize = 50) @From(ModelBatchTest.BatchGenerator.class) ModelBatch batch) throws IOException {
    ByteArrayInputStream emptyInputStream = new ByteArrayInputStream(new byte[0]);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    ModelLog log = new ModelLogDisk(emptyInputStream, byteArrayOutputStream);
    log.writeWithFactors = true;
    for (GraphicalModel model : batch) {
        log.add(model);
    }
    log.close();

    byte[] bytes = byteArrayOutputStream.toByteArray();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);

    ModelLog recovered = new ModelLogDisk(byteArrayInputStream, byteArrayOutputStream);
    byteArrayInputStream.close();

    assertEquals(batch.size(), recovered.size());

    for (int i = 0; i < batch.size(); i++) {
        assertTrue(batch.get(i).valueEquals(recovered.get(i), 1.0e-5));
    }
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:25,代码来源:ModelLogDiskTest.java


注:本文中的com.pholser.junit.quickcheck.From类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。