org.apache.sis.test.Assert.assertMapEquals()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中org.apache.sis.test.Assert.assertMapEquals()方法的一些代码示例,展示了Assert.assertMapEquals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert.assertMapEquals()方法的具体详情如下:
包路径:org.apache.sis.test.Assert
类名称:Assert
方法名:assertMapEquals

Assert.assertMapEquals介绍

[英]Asserts that the given map contains the same entries. In case of failure, this method lists the missing or unexpected entries.
[中]断言给定的映射包含相同的条目。如果失败,此方法将列出丢失的或意外的条目。

代码示例

代码示例来源:origin: apache/sis

/**
 * Implementation of the {@link #testStrongReferences()} method,
 * to be reused by {@link CacheTest}.
 *
 * @param weakMap  the map implementation to test.
 */
static void testStrongReferences(final Map<Integer,Integer> weakMap) {
  final Random random = new Random();
  for (int pass=0; pass<NUM_RETRY; pass++) {
    weakMap.clear();
    final HashMap<Integer,Integer> strongMap = new HashMap<>();
    for (int i=0; i<SAMPLE_SIZE; i++) {
      final Integer key   = random.nextInt(SAMPLE_SIZE);
      final Integer value = random.nextInt(SAMPLE_SIZE);
      assertEquals("containsKey:",   strongMap.containsKey(key),     weakMap.containsKey(key));
      assertEquals("containsValue:", strongMap.containsValue(value), weakMap.containsValue(value));
      assertSame  ("get:",           strongMap.get(key),             weakMap.get(key));
      if (random.nextBoolean()) {
        // Test addition.
        assertSame("put:", strongMap.put(key, value), weakMap.put(key, value));
      } else {
        // Test remove
        assertSame("remove:", strongMap.remove(key), weakMap.remove(key));
      }
      assertMapEquals(strongMap, weakMap);
    }
  }
}

代码示例来源:origin: apache/sis

/**
 * Tests {@link CollectionsExt#toCaseInsensitiveNameMap(Collection, Locale)}.
 */
@Test
public void testToCaseInsensitiveNameMap() {
  final List<Map.Entry<String,String>> elements = new ArrayList<>();
  elements.add(new AbstractMap.SimpleEntry<>("AA", "AA"));
  elements.add(new AbstractMap.SimpleEntry<>("Aa", "Aa"));
  elements.add(new AbstractMap.SimpleEntry<>("BB", "BB"));
  elements.add(new AbstractMap.SimpleEntry<>("bb", "bb"));
  elements.add(new AbstractMap.SimpleEntry<>("CC", "CC"));
  final Map<String,String> expected = new HashMap<>();
  assertNull(expected.put("AA", "AA"));
  assertNull(expected.put("Aa", "Aa"));   // No mapping for "aa", because of ambiguity between "AA" and "Aa".
  assertNull(expected.put("BB", "BB"));
  assertNull(expected.put("bb", "bb"));
  assertNull(expected.put("CC", "CC"));
  assertNull(expected.put("cc", "CC"));   // Automatically added.
  for (int i=0; i<10; i++) {
    Collections.shuffle(elements);
    assertMapEquals(expected, CollectionsExt.toCaseInsensitiveNameMap(elements, Locale.ROOT));
  }
}

代码示例来源:origin: apache/sis

/**
 * Tests {@link SystemUnit#getBaseUnits()}. This method indirectly tests the results of
 * {@link SystemUnit#multiply(Unit)}, {@link SystemUnit#divide(Unit)} and {@link SystemUnit#pow(int)}
 * since this test uses constants that were created with above operations.
 */
@Test
public void testGetBaseDimensions() {
  assertNull("METRE",  Units.METRE .getBaseUnits());      // Null value as per JSR-363 specification.
  assertNull("SECOND", Units.SECOND.getBaseUnits());
  assertTrue("UNITY",  Units.UNITY .getBaseUnits().isEmpty());
  assertMapEquals(Collections.singletonMap(Units.METRE, 3), Units.CUBIC_METRE.getBaseUnits());
  final Map<Unit<?>,Integer> expected = new HashMap<>(4);
  assertNull(expected.put(Units.KILOGRAM, 1));
  assertNull(expected.put(Units.METRE,    1));
  assertNull(expected.put(Units.SECOND,  -2));
  assertMapEquals(expected, Units.NEWTON.getBaseUnits());
}

代码示例来源:origin: apache/sis

/**
 * Tests {@link UnitDimension#getBaseDimensions()}. This method indirectly tests the results
 * of {@link UnitDimension#multiply(Dimension)}, {@link UnitDimension#divide(Dimension)} and
 * {@link UnitDimension#pow(int)} since this test uses constants that were created with above
 * operations.
 */
@Test
public void testGetBaseDimensions() {
  assertNull("LENGTH",        LENGTH       .getBaseDimensions());     // Null value as per JSR-363 specification.
  assertNull("TIME",          TIME         .getBaseDimensions());
  assertTrue("DIMENSIONLESS", DIMENSIONLESS.getBaseDimensions().isEmpty());
  assertMapEquals(Collections.singletonMap(LENGTH, 3), VOLUME.getBaseDimensions());
  final Map<Dimension,Integer> expected = new HashMap<>(4);
  assertNull(expected.put(MASS,    1));
  assertNull(expected.put(LENGTH,  1));
  assertNull(expected.put(TIME,   -2));
  assertMapEquals(expected, FORCE.getBaseDimensions());
}

代码示例来源:origin: apache/sis

assertMapEquals(strongMap, weakMap);

代码示例来源:origin: apache/sis

/**
 * Tests a dimension with rational power. This tests use the specific detectivity, which dimension is T^2.5 / (M⋅L).
 */
@Test
@DependsOnMethod({"testMultiply", "testDivide", "testPow", "testRoot"})
public void testRationalPower() {
  final Dimension dim = specificDetectivity();
  final Map<Dimension,Fraction> expected = new HashMap<>(4);
  assertNull(expected.put(TIME,   new Fraction( 5, 2)));
  assertNull(expected.put(MASS,   new Fraction(-1, 1)));
  assertNull(expected.put(LENGTH, new Fraction(-1, 1)));
  assertMapEquals(expected, ((UnitDimension) dim).components);
  try {
    dim.getBaseDimensions().toString();
    fail("Mapping from Fraction to Integer should not be allowed.");
  } catch (UnconvertibleObjectException e) {
    final String message = e.getMessage();
    assertTrue(message, message.contains("Integer"));
  }
  // 'toString()' formatting tested in UnitFormatTest.testRationalPower().
}

代码示例来源:origin: apache/sis

assertFalse(actual.containsValue(t23));
assertFalse(actual.containsValue(t00));
assertMapEquals(expected, actual);
assertFalse(actual.containsValue(t23));
assertFalse(actual.containsValue(t00));
assertMapEquals(expected, actual);
assertTrue (actual.containsValue(t23));
assertFalse(actual.containsValue(t00));
assertMapEquals(expected, actual);
assertTrue (actual.containsValue(t23));
assertTrue (actual.containsValue(t00));
assertMapEquals(expected, actual);

代码示例来源:origin: apache/sis

/**
 * Tests {@link UnitDimension#multiply(Dimension)}.
 */
@Test
@DependsOnMethod("testEqualsAndHashCode")
public void testMultiply() {
  assertSame(LENGTH, LENGTH.multiply(DIMENSIONLESS));
  assertSame(AREA,   LENGTH.multiply(LENGTH));
  assertSame(VOLUME, LENGTH.multiply(AREA));
  assertSame(VOLUME, AREA  .multiply(LENGTH));
  final Map<Dimension,Integer> expected = new HashMap<>(4);
  assertNull(expected.put(LENGTH, 1));
  assertNull(expected.put(TIME,   1));
  assertMapEquals(expected, LENGTH.multiply(TIME).getBaseDimensions());
}

代码示例来源:origin: apache/sis

/**
 * Tests {@link SystemUnit#multiply(Unit)}.
 */
@Test
@DependsOnMethod("testEqualsAndHashCode")
public void testMultiply() {
  assertSame(Units.METRE,        Units.METRE.multiply(Units.UNITY));
  assertSame(Units.SQUARE_METRE, Units.METRE.multiply(Units.METRE));
  assertSame(Units.CUBIC_METRE,  Units.METRE.multiply(Units.SQUARE_METRE));
  assertSame(Units.CUBIC_METRE,  Units.SQUARE_METRE.multiply(Units.METRE));
  final Map<Unit<?>,Integer> expected = new HashMap<>(4);
  assertNull(expected.put(Units.METRE,  1));
  assertNull(expected.put(Units.SECOND, 1));
  assertMapEquals(expected, Units.METRE.multiply(Units.SECOND).getBaseUnits());
}

代码示例来源:origin: apache/sis

assertNull(expected.put( keyByMainThread,  valueByMainThread));
assertNull(expected.put(keyByOtherThread, valueByOtherThread));
assertMapEquals(expected, cache);

相关文章