Java Code Examples for org.junit.jupiter.api.Assertions#assertArrayEquals()

The following examples show how to use org.junit.jupiter.api.Assertions#assertArrayEquals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PacketTest.java    From SimpleNet with MIT License 6 votes vote down vote up
@ParameterizedTest
@ValueSource(strings = { "Hello World!" })
void testPutStringBigEndianUTF16IntoPacket(String s) {
    packet.putString(s, StandardCharsets.UTF_16);

    byte[] bytes = s.getBytes(StandardCharsets.UTF_16);
    short length = (short) bytes.length;
    
    Assertions.assertEquals(packet.getSize(), Short.BYTES + length);
    Assertions.assertEquals(packet.getQueue().size(), 2);

    ByteBuffer buffer = ByteBuffer.allocate(Short.BYTES + length);
    packet.getQueue().poll().accept(buffer);
    packet.getQueue().poll().accept(buffer);
    buffer.flip();
    Assertions.assertEquals(length, buffer.getShort());

    byte[] data = new byte[length];
    buffer.get(data);
    Assertions.assertArrayEquals(bytes, data);
}
 
Example 2
Source File: VisualModelTests.java    From workcraft with MIT License 6 votes vote down vote up
@Test
public void testGroupingDontGroupConnectionsSimple() {
    VisualModel model = createModel();

    VisualGroup root = (VisualGroup) model.getRoot();
    VisualComponent c1 = createComponent(root);
    VisualComponent c2 = createComponent(root);
    VisualComponent c3 = createComponent(root);
    VisualConnection con1 = createConnection(c1, c2, root);
    VisualConnection con2 = createConnection(c2, c3, root);

    model.addToSelection(con1);
    model.addToSelection(con2);
    model.groupSelection();

    Assertions.assertArrayEquals(new VisualNode[] {c1, c2, c3, con1, con2 },
            root.getChildren().toArray(new VisualNode[0]));
}
 
Example 3
Source File: PrimitiveArrayTest.java    From Prism with MIT License 6 votes vote down vote up
@Test
public void testLongArrayFromJsonObject() {
    JsonArray jsonArray = new JsonArray();
    for (long number : LONG_ARRAY) {
        jsonArray.add(number);
    }

    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("key", PrimitiveArray.LONG_ARRAY_ID);
    jsonObject.add("value", jsonArray);

    PrimitiveArray primitiveArray = PrimitiveArray.of(jsonObject);

    Assertions.assertNotNull(primitiveArray);
    Assertions.assertEquals(primitiveArray.getKey(), PrimitiveArray.LONG_ARRAY_ID);
    Assertions.assertArrayEquals(LONG_ARRAY, (long[]) primitiveArray.getArray());
}
 
Example 4
Source File: TestMultiBlocks.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testValidConstructor() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test"));
    MultiBlock multiblock = new MultiBlock(item, new Material[9], BlockFace.DOWN);

    Assertions.assertEquals(item, multiblock.getSlimefunItem());
    Assertions.assertArrayEquals(new Material[9], multiblock.getStructure());
    Assertions.assertEquals(BlockFace.DOWN, multiblock.getTriggerBlock());
}
 
Example 5
Source File: 合并K个排序链表解法2.java    From algorithm-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public static void main(String[] args) {
    ListNode head1 = ListUtil.buildList(1, 4, 5);
    ListNode head2 = ListUtil.buildList(1, 3, 4);
    ListNode head3 = ListUtil.buildList(2, 6);
    ListNode[] array = new ListNode[] { head1, head2, head3 };
    ListNode result = mergeKLists(array);
    List<Integer> list = ListUtil.toList(result);
    System.out.println(list);
    Assertions.assertArrayEquals(new Integer[] { 1, 1, 2, 3, 4, 4, 5, 6 }, list.toArray(new Integer[0]));
}
 
Example 6
Source File: PrimitiveArrayTest.java    From Prism with MIT License 5 votes vote down vote up
@Test
public void testIntArrayFromIntArray() {
    PrimitiveArray primitiveArray = new PrimitiveArray(INT_ARRAY);

    Assertions.assertEquals(primitiveArray.getKey(), PrimitiveArray.INT_ARRAY_ID);
    Assertions.assertArrayEquals(INT_ARRAY, (int[]) primitiveArray.getArray());
}
 
Example 7
Source File: TestArrayTools.java    From javageci with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("Appending zero length arrays returns new array")
void appendZeroLengthArray() {
    final var a = new String[]{"a", "b", "c"};
    final var b = new String[0];
    final var result = ArrayTools.join(a, b);
    Assertions.assertNotSame(a, result);
    Assertions.assertArrayEquals(a, result);
}
 
Example 8
Source File: 二叉树的层次遍历2.java    From algorithm-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public static void main(String[] args) {
    TreeNode tree = TreeUtils.buildTree(3, 9, 20, null, null, 15, 7);
    List<List<Integer>> resultList = levelOrderBottom(tree);
    List<List<Integer>> expectList = new LinkedList<>();
    expectList.add(Arrays.asList(15, 7));
    expectList.add(Arrays.asList(9, 20));
    expectList.add(Arrays.asList(3));
    Assertions.assertArrayEquals(expectList.toArray(), resultList.toArray());
}
 
Example 9
Source File: ComplexUtilsTest.java    From commons-numbers with Apache License 2.0 5 votes vote down vote up
@Test
void testComplexToInterleaved() {
    setArrays();
    Assertions.assertArrayEquals(di, ComplexUtils.complex2Interleaved(c), Math.ulp(1.0), msg);
    // Interleaved complex to float, whole array
    Assertions.assertArrayEquals(fi, ComplexUtils.complex2InterleavedFloat(c), Math.ulp(1.0f), msg);

    // 2d
    TestUtils.assertEquals(msg, di2d0, ComplexUtils.complex2Interleaved(c2d, 0), 0);
    TestUtils.assertEquals(msg, di2d1, ComplexUtils.complex2Interleaved(c2d, 1), 0);
    TestUtils.assertEquals(msg, di2d1, ComplexUtils.complex2Interleaved(c2d), 0);

    TestUtils.assertEquals(msg, fi2d0, ComplexUtils.complex2InterleavedFloat(c2d, 0), 0);
    TestUtils.assertEquals(msg, fi2d1, ComplexUtils.complex2InterleavedFloat(c2d, 1), 0);
    TestUtils.assertEquals(msg, fi2d1, ComplexUtils.complex2InterleavedFloat(c2d), 0);

    // 3d
    TestUtils.assertEquals(msg, di3d0, ComplexUtils.complex2Interleaved(c3d, 0), 0);
    TestUtils.assertEquals(msg, di3d1, ComplexUtils.complex2Interleaved(c3d, 1), 0);
    TestUtils.assertEquals(msg, di3d2, ComplexUtils.complex2Interleaved(c3d, 2), 0);
    TestUtils.assertEquals(msg, di3d2, ComplexUtils.complex2Interleaved(c3d), 0);

    TestUtils.assertEquals(msg, fi3d0, ComplexUtils.complex2InterleavedFloat(c3d, 0), 0);
    TestUtils.assertEquals(msg, fi3d1, ComplexUtils.complex2InterleavedFloat(c3d, 1), 0);
    TestUtils.assertEquals(msg, fi3d2, ComplexUtils.complex2InterleavedFloat(c3d, 2), 0);
    TestUtils.assertEquals(msg, fi3d2, ComplexUtils.complex2InterleavedFloat(c3d), 0);

    // 4d
    TestUtils.assertEquals(msg, di4d0, ComplexUtils.complex2Interleaved(c4d, 0), 0);
    TestUtils.assertEquals(msg, di4d1, ComplexUtils.complex2Interleaved(c4d, 1), 0);
    TestUtils.assertEquals(msg, di4d2, ComplexUtils.complex2Interleaved(c4d, 2), 0);
    TestUtils.assertEquals(msg, di4d3, ComplexUtils.complex2Interleaved(c4d, 3), 0);
    TestUtils.assertEquals(msg, di4d3, ComplexUtils.complex2Interleaved(c4d), 0);
}
 
Example 10
Source File: TestPStmtKey.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link org.apache.commons.dbcp2.PStmtKey#PStmtKey(String, String, String, int[])}.
 *
 * See https://issues.apache.org/jira/browse/DBCP-494
 */
@Test
public void testCtorStringStringArrayOfNullInts() {
    final int[] input = null;
    final PStmtKey pStmtKey = new PStmtKey("", "", "", input);
    Assertions.assertArrayEquals(input, pStmtKey.getColumnIndexes());
}
 
Example 11
Source File: ARTUnitTest.java    From adaptive-radix-tree with MIT License 5 votes vote down vote up
@Test
public void testRemovePessimisticLCPFromOptimisticCompressedPath1() {
	InnerNode node = new Node4();
	// number of optimistic equal characters in all children of this InnerNode
	int optimisticCPLength = 10, lcp = 3;
	String compressedPath = "abcdefgh"; // pessimistic compressed path
	System.arraycopy(compressedPath.getBytes(), 0, node.prefixKeys, 0, compressedPath.length());
	node.prefixLen = compressedPath
			.length() + optimisticCPLength;
	int expectedNewPrefixLen = compressedPath.length() + optimisticCPLength - lcp - 1;

	InnerNode nodeLeft = new Node4();
	node.addChild((byte) 'i', nodeLeft);
	node.addChild((byte) 'j', Mockito.spy(Node.class));

	String prevDepth = "prevdepthbytes";
	String optimisticPath = "0123456789";
	String key = prevDepth + compressedPath + optimisticPath + "ik";
	LeafNode<String, String> nodeLeftLeft = new LeafNode<>(BinaryComparables.forString().get(key), key, "value");
	nodeLeft.addChild((byte) 'k', nodeLeftLeft);
	nodeLeft.addChild((byte) 'l', Mockito.spy(Node.class));

	AdaptiveRadixTree.removePessimisticLCPFromCompressedPath(node, prevDepth.length() + lcp, lcp);
	Assertions.assertEquals(expectedNewPrefixLen, node.prefixLen);


	Assertions.assertArrayEquals("efgh0123".getBytes(), getValidPrefixKey(node));
}
 
Example 12
Source File: VisualNodeTests.java    From workcraft with MIT License 5 votes vote down vote up
@Test
public void testGetPath() {
    VisualGroup root = createGroup(null);
    Assertions.assertEquals(1, Hierarchy.getPath(root).length);
    VisualGroup node1 = createGroup(root);
    Assertions.assertArrayEquals(new VisualGroup[]{root, node1}, Hierarchy.getPath(node1));
    VisualGroup node2 = createGroup(node1);
    Assertions.assertArrayEquals(new VisualGroup[]{root, node1, node2}, Hierarchy.getPath(node2));
}
 
Example 13
Source File: TestCommons.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
protected void eq(byte[] actual, byte[] expected) {
	try {
		Assertions.assertArrayEquals(expected, actual);
	} catch (AssertionError e) {
		registerError(e);
		throw e;
	}
}
 
Example 14
Source File: MtaArchiveBuilderTest.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private void assertExistingJarFile(Path mtaArchiveFile, String fileName, byte[] expectedContent) throws IOException {
    try (JarInputStream in = new JarInputStream(Files.newInputStream(mtaArchiveFile))) {
        for (ZipEntry e; (e = in.getNextEntry()) != null;) {
            if (fileName.equals(e.getName()) && !e.isDirectory()) {
                Assertions.assertArrayEquals(expectedContent, IOUtils.toByteArray(in));
                return;
            }
        }
        throw new AssertionError(MessageFormat.format("Zip archive file \"{0}\" could not be found", fileName));
    }
}
 
Example 15
Source File: MetadataComparatorTest.java    From reposilite with Apache License 2.0 5 votes vote down vote up
@Test
void testMetadataComparator() {
    List<String> strings = new ArrayList<>(Arrays.asList(STRINGS));
    Collections.shuffle(strings);

    String[] sorted = strings.stream()
            .map(string -> new Pair<>(string.split("[-.]"), string))
            .sorted(METADATA_COMPARATOR)
            .map(Pair::getValue)
            .toArray(String[]::new);

    System.out.println(Arrays.toString(STRINGS));
    System.out.println(Arrays.toString(sorted));
    Assertions.assertArrayEquals(STRINGS, sorted);
}
 
Example 16
Source File: PlatformHttpTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void multipart() {
    final byte[] bytes = new byte[] { 0xc, 0x0, 0xf, 0xe, 0xb, 0xa, 0xb, 0xe };
    final byte[] returnedBytes = RestAssured.given().contentType("multipart/form-data")
            .multiPart("file", "bytes.bin", bytes)
            .formParam("description", "cofe babe")
            .post("/platform-http/multipart")
            .then()
            .statusCode(200)
            .extract().body().asByteArray();
    Assertions.assertArrayEquals(bytes, returnedBytes);
}
 
Example 17
Source File: RapidoidTest.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
protected void eq(double[] expected, double[] actual, double delta) {
	try {
		Assertions.assertArrayEquals(expected, actual, delta);
	} catch (AssertionError e) {
		registerError(e);
		throw e;
	}
}
 
Example 18
Source File: LinearPatternTest.java    From panda with Apache License 2.0 4 votes vote down vote up
@Test
void testIdentifiers() {
    Assertions.assertArrayEquals(ArrayUtils.of("a", "b", "c"), identifiersOf("a:unit b:unit c:unit", "unit unit unit"));
    Assertions.assertArrayEquals(ArrayUtils.of("a", "b", "c"), identifiersOf("a:unit b:* c:unit", "unit random unit"));
}
 
Example 19
Source File: FileUtilsTest.java    From panda with Apache License 2.0 4 votes vote down vote up
@Test
void getContentAsLines() throws IOException {
    Assertions.assertArrayEquals(CONTENT.split(System.lineSeparator()), FileUtils.getContentAsLines(content));
}
 
Example 20
Source File: 二叉树的所有路径.java    From algorithm-tutorial with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
public static void main(String[] args) {
    TreeNode tree = TreeUtils.buildTree(1, 2, 3, 5);
    System.out.println("result = " + binaryTreePaths(tree));
    Assertions.assertArrayEquals(Arrays.asList("1->2->5", "1->3").toArray(),
        binaryTreePaths(tree).toArray(new String[0]));
}