Skip to content

Commit

Permalink
Add test for multi-dimensional arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
hextriclosan committed Sep 21, 2024
1 parent 2f9b4ea commit 5999d4b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ fn should_do_arrays_with_longs() {
assert_eq!(233646220932000, get_long(last_frame_value))
}

#[test]
fn should_do_3d_arrays() {
let vm = VM::new(vec!["tests/test_data/Array3D.class"], "tests/test_data/std").unwrap();
let last_frame_value = vm.run("Array3D").unwrap();
assert_eq!(780, get_int(last_frame_value))
}

#[test]
fn should_do_class_static_initialization() {
let vm = VM::new(
Expand Down
Binary file added tests/test_data/Array3D.class
Binary file not shown.
24 changes: 24 additions & 0 deletions tests/test_data/Array3D.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class Array3D {
public static void main(String[] args) {
int[][][] array = new int[][][]{
{{10, 20}, {30, 40}, {50, 60}},
{{70, 80}, {90, 100}, {110, 120}}
};

int result = sum(array);
}

private static int sum(int[][][] array3d) {
int sum = 0;
for (var array2d : array3d) {
for (var array1d: array2d) {
for (var value : array1d) {
sum += value;
}
}
}

return sum;
}

}

0 comments on commit 5999d4b

Please sign in to comment.