### Question:
Transition { public static <A> INDArray buildStackedObservations(List<Transition<A>> transitions) { int size = transitions.size(); long[] shape = getShape(transitions); INDArray[] array = new INDArray[size]; for (int i = 0; i < size; i++) { array[i] = transitions.get(i).getObservation().getData(); } return Nd4j.concat(0, array).reshape(shape); } Transition(Observation observation, A action, double reward, boolean isTerminal); private  Transition(Observation observation, A action, double reward, boolean isTerminal, INDArray nextObservation); void setNextObservation(Observation nextObservation); static INDArray concat(INDArray[] history); Transition<A> dup(); static INDArray buildStackedObservations(List<Transition<A>> transitions); static INDArray buildStackedNextObservations(List<Transition<A>> transitions);  }### Answer:
@Test public void when_CallingBuildStackedObservationsAndShapeRankIs2_expect_2DResultWithObservationsStackedOnDimension0() { List<Transition<Integer>> transitions = new ArrayList<Transition<Integer>>(); double[] obs1 = new double[] { 0.0, 1.0, 2.0 }; Observation observation1 = buildObservation(obs1); Observation nextObservation1 = buildObservation(new double[] { 100.0, 101.0, 102.0 }); transitions.add(buildTransition(observation1,0, 0.0, nextObservation1)); double[] obs2 = new double[] { 10.0, 11.0, 12.0 }; Observation observation2 = buildObservation(obs2); Observation nextObservation2 = buildObservation(new double[] { 110.0, 111.0, 112.0 }); transitions.add(buildTransition(observation2, 0, 0.0, nextObservation2)); INDArray result = Transition.buildStackedObservations(transitions); double[][] expected = new double[][] { obs1, obs2 }; assertExpected(expected, result); }
@Test public void when_CallingBuildStackedObservationsAndShapeRankIsGreaterThan2_expect_ResultWithOneMoreDimensionAndObservationsStackedOnDimension0() { List<Transition<Integer>> transitions = new ArrayList<Transition<Integer>>(); double[][] obs1 = new double[][] { { 0.0, 1.0, 2.0 }, { 3.0, 4.0, 5.0 }, { 6.0, 7.0, 8.0 }, }; Observation observation1 = buildObservation(obs1); double[] nextObs1 = new double[] { 100.0, 101.0, 102.0 }; Observation nextObservation1 = buildNextObservation(obs1, nextObs1); transitions.add(buildTransition(observation1, 0, 0.0, nextObservation1)); double[][] obs2 = new double[][] { { 10.0, 11.0, 12.0 }, { 13.0, 14.0, 15.0 }, { 16.0, 17.0, 18.0 }, }; Observation observation2 = buildObservation(obs2); double[] nextObs2 = new double[] { 110.0, 111.0, 112.0 }; Observation nextObservation2 = buildNextObservation(obs2, nextObs2); transitions.add(buildTransition(observation2, 0, 0.0, nextObservation2)); INDArray result = Transition.buildStackedObservations(transitions); double[][][] expected = new double[][][] { obs1, obs2 }; assertExpected(expected, result); }