Java Code Examples for org.junit.Assert.assertArrayEquals()

The following are Jave code examples for showing how to use assertArrayEquals() of the org.junit.Assert class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Koyaanisqatsi   File: LifeTest.java   View Source Code Vote up 6 votes
private void testLong(int generations, Life.Type type) {
    RLE acorn = RLE.getAcorn();
    System.out.print("Running " + type + " for " + generations +" generations with 1 thread");
    Life sample = Life.fromRLE(acorn, type, generations, 1, false);
    long start = System.currentTimeMillis();
    sample.execute();
    long time1 = System.currentTimeMillis() - start;
    System.out.println(", base time: " + time1 + " ms");
    String[] golden = sample.getResult();

    for (int p = 2; p <= 512; p *= 2) {
        System.out.print("Running " + type + " for " + generations +" generations with " + p + " threads");
        sample = Life.fromRLE(acorn, type, generations, p, false);
        start = System.currentTimeMillis();
        sample.execute();
        long time = System.currentTimeMillis() - start;

        Assert.assertArrayEquals(golden, sample.getResult());

        System.out.println(", time: " + time + " ms, speedup: " + (100 * time1 / time)/100d);
    }

}
 
Example 2
Project: soundwave   File: EsIteratorTest.java   View Source Code Vote up 6 votes
@Test
public void noRetrieval() throws Exception {
  ScrollableResponse<List<Integer>> scrollableResponse = new ScrollableResponse<>();
  scrollableResponse.setValue(Arrays.asList(1, 2, 3, 4, 5));
  scrollableResponse.setScrollToEnd(true);

  EsIterator<Integer> l = new EsIterator<>(scrollableResponse, s -> scrollableResponse);
  int count = 0;
  ArrayList<Integer> result = new ArrayList<>();
  while (l.hasNext()) {
    result.add(l.next());
    count++;
  }
  Assert.assertArrayEquals(new int[]{1, 2, 3, 4, 5},
      ArrayUtils.toPrimitive(result.toArray(new Integer[0])));
}
 
Example 3
Project: rskj   File: TrieImplDeleteTest.java   View Source Code Vote up 6 votes
@Test
public void deleteOneHundredLongValuesGivesTheSameHash() {
    Trie trie1 = new TrieImpl();

    for (int k = 0; k < 200; k++)
        trie1 = trie1.put("key" + k, TrieImplValueTest.makeValue(k + 100));

    for (int k = 1; k < 200; k += 2)
        trie1 = trie1.delete("key" + k);

    Trie trie2 = new TrieImpl();

    for (int k = 0; k < 200; k += 2)
        trie2 = trie2.put("key" + k, TrieImplValueTest.makeValue(k + 100));

    Assert.assertArrayEquals(trie1.getHash(), trie2.getHash());
}
 
Example 4
Project: vertx-zero   File: AsyncTestBase.java   View Source Code Vote up 5 votes
protected void assertArrayEquals(final String message, final float[] expecteds, final float[] actuals, final float delta) throws ArrayComparisonFailure {
    checkThread();
    try {
        Assert.assertArrayEquals(message, expecteds, actuals, delta);
    } catch (final AssertionError e) {
        handleThrowable(e);
    }
}
 
Example 5
Project: JRediClients   File: RedissonScoredSortedSetTest.java   View Source Code Vote up 5 votes
@Test
public void testScoredSortedSetValueRangeNegativeInf() {
    RScoredSortedSet<String> set = redisson.<String>getScoredSortedSet("simple");

    set.add(0, "a");
    set.add(1, "b");
    set.add(2, "c");
    set.add(3, "d");
    set.add(4, "e");

    Collection<String> r = set.valueRange(Double.NEGATIVE_INFINITY, true, 4, false, 1, 2);
    String[] a = r.toArray(new String[0]);
    Assert.assertArrayEquals(new String[]{"b", "c"}, a);
}
 
Example 6
Project: rskj   File: PathEncoderTest.java   View Source Code Vote up 5 votes
@Test
public void decodeHexadecimalPathThreeNibbles() {
    byte[] encoded = new byte[] { 0x6d, (byte)0x80 };

    byte[] path = PathEncoder.decode(encoded, 16, 3);

    Assert.assertNotNull(path);
    Assert.assertArrayEquals(new byte[] { 0x06, 0x0d, 0x08 }, path);
}
 
Example 7
Project: graphflow   File: SortedAdjacencyListTest.java   View Source Code Vote up 5 votes
private void testSort(int[] inputNeighbourIds, short[] inputNeighbourTypes,
    long[] inputNeighbourEdgeIds, int[] sortedNeighbourIds, short[] sortedNeighbourTypes,
    long[] sortedNeighbourEdgeIds) {
    SortedAdjacencyList adjacencyList = getPopulatedAdjacencyList(inputNeighbourIds,
        inputNeighbourTypes, inputNeighbourEdgeIds);
    int expectedSize = inputNeighbourIds.length;
    Assert.assertEquals(expectedSize, adjacencyList.getSize());
    Assert.assertTrue(expectedSize <= adjacencyList.neighbourIds.length); // Check capacity.
    Assert.assertArrayEquals(sortedNeighbourIds, Arrays.copyOf(adjacencyList.neighbourIds,
        adjacencyList.getSize()));
    Assert.assertArrayEquals(sortedNeighbourTypes, Arrays.copyOf(adjacencyList.edgeTypes,
        adjacencyList.getSize()));
    Assert.assertArrayEquals(sortedNeighbourEdgeIds, Arrays.copyOf(adjacencyList.edgeIds,
        adjacencyList.getSize()));
}
 
Example 8
Project: CorePatch   File: BsDiffTest.java   View Source Code Vote up 5 votes
@Test
public void generatePatchTest() throws Exception {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  byte[] oldData = readTestData("BsDiffInternalTestOld.txt");
  byte[] newData = readTestData("BsDiffInternalTestNew.txt");
  byte[] expectedPatch = readTestData("BsDiffInternalTestPatchExpected.patch");

  BsDiffPatchWriter.generatePatch(oldData, newData, out);

  byte[] actualPatch = out.toByteArray();
  Assert.assertEquals(actualPatch.length, expectedPatch.length);
  Assert.assertArrayEquals(actualPatch, expectedPatch);
}
 
Example 9
Project: rskj   File: BodyRequestMessageTest.java   View Source Code Vote up 5 votes
@Test
public void createWithBlockHash() {
    byte[] hash = BlockGenerator.getInstance().getGenesisBlock().getHash();
    BodyRequestMessage message = new BodyRequestMessage(100, hash);

    Assert.assertEquals(100, message.getId());
    Assert.assertArrayEquals(hash, message.getBlockHash());
    Assert.assertEquals(MessageType.BODY_REQUEST_MESSAGE, message.getMessageType());
}
 
Example 10
Project: openjdk-jdk10   File: CompressedOopTest.java   View Source Code Vote up 5 votes
@Test
public void test4() throws Exception {
    HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("charArrayCopyTest", Object.class, Object.class, Object.class);
    StringContainer1 source1 = new StringContainer1();
    StringContainer2 source2 = new StringContainer2();
    char[] result = new char[source1.value.length + source2.value.length];
    installedBenchmarkCode.executeVarargs(source1.value, source2.value, result);
    Assert.assertArrayEquals(new char[]{'T', 'e', 's', 't', ' ', 'S', 't', 'r', 'i', 'n', 'g'}, result);
}
 
Example 11
Project: HooIsNeural   File: NOTGateTest.java   View Source Code Vote up 5 votes
@Test
public void inputOneExpectZero() {
	network.clear();
	network.setInput(new double[] {1});
	network.calculate();
	double[] expected = new double[] {0};
	double[] actual = network.getOutput();
	for (int i = 0; i < actual.length; i++) {
		actual[i] = Math.round(actual[i]);
	}
	
	Assert.assertArrayEquals(expected, actual, 0);
}
 
Example 12
Project: ats-framework   File: Test_Utils.java   View Source Code Vote up 5 votes
@Test
public void testCommandLineAgrumentsParser_6() {

    String[] expectedArgs = new String[]{ "/bin/bash", "-c", "/tmp/test script.sh", "start", "-test",
                                          "last test arg" };
    String[] actualArgs = StringUtils.parseCommandLineArguments("/bin/bash -c \"/tmp/test script.sh\" start -test 'last test arg'");

    Assert.assertArrayEquals(getArrayNotEqualsMsg(expectedArgs, actualArgs), expectedArgs,
                             actualArgs);
}
 
Example 13
Project: hadoop   File: CryptoStreamsTestBase.java   View Source Code Vote up 5 votes
private void seekCheck(InputStream in, int pos) throws Exception {
  byte[] result = new byte[dataLen];
  ((Seekable) in).seek(pos);
  int n = readAll(in, result, 0, dataLen);
  
  Assert.assertEquals(dataLen, n + pos);
  byte[] readData = new byte[n];
  System.arraycopy(result, 0, readData, 0, n);
  byte[] expectedData = new byte[n];
  System.arraycopy(data, pos, expectedData, 0, n);
  Assert.assertArrayEquals(readData, expectedData);
}
 
Example 14
Project: hadoop   File: TestJsonUtil.java   View Source Code Vote up 5 votes
@Test
public void testGetXAttrFromJson() throws IOException {
  String jsonString = 
      "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"}," +
      "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}";
  ObjectReader reader = new ObjectMapper().reader(Map.class);
  Map<?, ?> json = reader.readValue(jsonString);

  // Get xattr: user.a2
  byte[] value = JsonUtil.getXAttr(json, "user.a2");
  Assert.assertArrayEquals(XAttrCodec.decodeValue("0x313131"), value);
}
 
Example 15
Project: datax   File: FilterUtilTest.java   View Source Code Vote up 5 votes
@Test
public void test04() {
    String regular = "^pt=*";

    List<String> matched = FilterUtil.filterByRegular(ALL_STRS, regular);

    System.out.println("matched:" + matched);
    List<String> expected = new ArrayList<String>(ALL_STRS);

    Assert.assertEquals(expected.size(), matched.size());

    Collections.sort(expected);
    Collections.sort(matched);
    Assert.assertArrayEquals(expected.toArray(), matched.toArray());
}
 
Example 16
Project: oryx2   File: TrainTest.java   View Source Code Vote up 5 votes
@Test
public void testURITrain() throws Exception {
  Response response = target("/train/" + TRAIN_DATA.split("\n")[0])
      .request().post(Entity.text(""));
  Assert.assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
  List<Pair<String,String>> data = MockTopicProducer.getData();
  Assert.assertEquals(1, data.size());
  Assert.assertArrayEquals(EXPECTED_TOPIC[0], data.get(0).getSecond().split(","));
}
 
Example 17
Project: autorest.java   File: ArrayTests.java   View Source Code Vote up 4 votes
@Test
public void getFloatValid() throws Exception {
    List<Double> result = client.arrays().getFloatValid();
    Object[] expected = new Double[] {0d, -0.01, -1.2e20};
    Assert.assertArrayEquals(expected, result.toArray());
}
 
Example 18
Project: CorePatch   File: BsDiffTest.java   View Source Code Vote up 4 votes
@Test
public void searchForMatch() throws Exception {
  String[] testCases = {
    "a",
    "aa",
    "az",
    "za",
    "aaaaa",
    "CACAO",
    "banana",
    "tobeornottobe",
    "the quick brown fox jumps over the lazy dog.",
    "elephantelephantelephantelephantelephant",
    "011010011001011010010110011010010",
  };
  for (String testCase : testCases) {
    int size = testCase.length();
    byte[] bytes = testCase.getBytes(StandardCharsets.US_ASCII);
    RandomAccessObject input = new RandomAccessObject.RandomAccessByteArrayObject(bytes);
    RandomAccessObject suffixArray =
        new DivSuffixSorter(new RandomAccessObjectFactory.RandomAccessByteArrayObjectFactory())
            .suffixSort(input);

    // Test exact matches for every non-empty substring.
    for (int lo = 0; lo < size; ++lo) {
      for (int hi = lo + 1; hi <= size; ++hi) {
        byte[] query = Arrays.copyOfRange(bytes, lo, hi);
        int querySize = query.length;
        Assert.assertEquals(querySize, hi - lo);
        RandomAccessObject queryBuf = new RandomAccessObject.RandomAccessByteArrayObject(query);

        BsDiff.Match match = BsDiff.searchForMatch(suffixArray, input, queryBuf, 0, 0, size);

        Assert.assertEquals(querySize, match.length);
        Assert.assertTrue(match.start >= 0);
        Assert.assertTrue(match.start <= size - match.length);
        byte[] suffix = Arrays.copyOfRange(bytes, match.start, match.start + match.length);
        Assert.assertArrayEquals(query, suffix);
      }
    }
  }
}
 
Example 19
Project: rskj   File: TypeConverterTest.java   View Source Code Vote up 4 votes
@Test
public void stringHexToByteArray() {
    Assert.assertArrayEquals(new byte[] { 32 }, TypeConverter.stringHexToByteArray("20"));
}
 
Example 20
Project: rskj   File: NodeBlockProcessorTest.java   View Source Code Vote up 3 votes
@Test
public void processGetBlockHeaderMessageUsingBlockInStore() throws UnknownHostException {
    final Block block = BlockGenerator.getInstance().getBlock(3);

    final BlockStore store = new BlockStore();
    store.saveBlock(block);

    final Blockchain blockchain = BlockChainBuilder.ofSize(0);
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, syncConfiguration);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);

    final SimpleMessageChannel sender = new SimpleMessageChannel();

    processor.processBlockHeadersRequest(sender, 1, block.getHash(), 1);

    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());

    final Message message = sender.getMessages().get(0);

    Assert.assertEquals(MessageType.BLOCK_HEADERS_RESPONSE_MESSAGE, message.getMessageType());

    final BlockHeadersResponseMessage bMessage = (BlockHeadersResponseMessage) message;

    Assert.assertArrayEquals(block.getHeader().getHash(), bMessage.getBlockHeaders().get(0).getHash());
}