From 5999d4b49ffdfed2d8ca61d7551573a4c92a30e0 Mon Sep 17 00:00:00 2001 From: Igor Rudenko Date: Sat, 21 Sep 2024 23:50:49 +0300 Subject: [PATCH] Add test for multi-dimensional arrays --- tests/integration_test.rs | 7 +++++++ tests/test_data/Array3D.class | Bin 0 -> 748 bytes tests/test_data/Array3D.java | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 tests/test_data/Array3D.class create mode 100644 tests/test_data/Array3D.java diff --git a/tests/integration_test.rs b/tests/integration_test.rs index f35cb1b7..2ed49ad8 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -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( diff --git a/tests/test_data/Array3D.class b/tests/test_data/Array3D.class new file mode 100644 index 0000000000000000000000000000000000000000..842303dbab1bb87bbec7a6f84d73cb45ede93763 GIT binary patch literal 748 zcmZ`%O>fgc5Ph4qz4pdV19a1xsz_W=QmPgO;X??O_)w*wlpv*43clc^QRULOC{0j% z&!6C$3zuFvfe_6P=uhDna3ajcg}?#Xp4m4$Z|3c+FMocW0C<9%5*cs-!-WZpA%7UX zk2a5@Djlp<&yx(P5sK-h7#jw}z_IIQ95k-t%6ekRYVpyLyZw~r#a`3RU$KW*w zQRnSW^lp|futXGHltDI+hy6}>JJw~~tIiv`2yT{ZeWqTPW=E$WZ=xafM{{+0#1vY-(-vDWus-}7aPr%k>Xn#7YUmwE^AzE zG%4Y4+O`hAoYP)wyg#QU8lMuae)kKqkLL1nGa(!&uyINvr5<)FlNIQkIg;7o)wP}V z$rcX`Wvq^|yRM9K#q`aJdj{XG)&oFp~KzakvMLj*++FoZQF w#il@k>5nEo#S)x9SU}L5#(n)WUFH3b3!Uqv`^*2~ng7)PK{w8@Jd^AH0u{-1k^lez literal 0 HcmV?d00001 diff --git a/tests/test_data/Array3D.java b/tests/test_data/Array3D.java new file mode 100644 index 00000000..148c1d7c --- /dev/null +++ b/tests/test_data/Array3D.java @@ -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; + } + +}