Skip to content

Commit

Permalink
~ Matrix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinherron committed Sep 16, 2022
1 parent 837c26c commit 86e67a0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Expand Up @@ -171,6 +171,11 @@ public Matrix transform(Function<Object, Object> f) {
}
}

/**
* Get an unflattened (nested multidimensional) copy of the contained value.
*
* @return an unflattened (nested multidimensional) copy of the contained value.
*/
public Object unflatten() {
return ArrayUtil.unflatten(flatArray, dimensions);
}
Expand Down
@@ -1,8 +1,21 @@
/*
* Copyright (c) 2022 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.milo.opcua.stack.core.types.builtin;

import java.util.Arrays;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class MatrixTest {
private final int[][] primitiveInt2d = {{1, 2}, {3, 4}};
Expand All @@ -11,6 +24,36 @@ class MatrixTest {
private final Matrix primitiveMatrix2d = new Matrix(primitiveInt2d);
private final Matrix boxedMatrix2d = new Matrix(boxedInt2d);

@Test
void matrixTransform() {
Matrix m = Matrix.ofInt32(new int[][]{
{0, 1},
{2, 3}
});

Matrix transformed = m.transform(Object::toString);

Matrix expected = Matrix.ofString(new String[][]{
new String[]{"0", "1"},
new String[]{"2", "3"}
});

assertEquals(expected, transformed);
}

@Test
void matrixUnflatten() {
String[][] value = {
new String[]{"0", "1"},
new String[]{"2", "3"}
};

Matrix m = Matrix.ofString(value);

assertTrue(Arrays.deepEquals(new String[]{"0", "1", "2", "3"}, (Object[]) m.getElements()));
assertTrue(Arrays.deepEquals(value, (String[][]) m.unflatten()));
}

@Test
void matrixToString() {
assertEquals(
Expand Down

0 comments on commit 86e67a0

Please sign in to comment.