Skip to content

Commit

Permalink
Move tests to java packages
Browse files Browse the repository at this point in the history
  • Loading branch information
hextriclosan committed Sep 23, 2024
1 parent 0bf6d2a commit 580feca
Show file tree
Hide file tree
Showing 85 changed files with 242 additions and 177 deletions.
150 changes: 97 additions & 53 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,226 +2,270 @@ use vm::vm::VM;

#[test]
fn should_do_adding() {
let vm = VM::new(vec!["tests/test_data/Adder.class"], "tests/test_data/std").unwrap();
let last_frame_value = vm.run("Adder").unwrap();
let vm = VM::new(
vec!["tests/test_data/samples/arithmetics/adder/ints/AdderInt.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("samples.arithmetics.adder.ints.AdderInt").unwrap();
assert_eq!(55, get_int(last_frame_value))
}

#[test]
fn should_do_adding_with_longs() {
let vm = VM::new(
vec!["tests/test_data/AdderLong.class"],
vec!["tests/test_data/samples/arithmetics/adder/longs/AdderLong.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("AdderLong").unwrap();
let last_frame_value = vm.run("samples.arithmetics.adder.longs.AdderLong").unwrap();
assert_eq!(171798691900, get_long(last_frame_value))
}

#[test]
fn should_do_adding_with_negative_longs() {
let vm = VM::new(
vec!["tests/test_data/AdderNegativeLong.class"],
vec!["tests/test_data/samples/arithmetics/addernegative/AdderNegativeLong.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("AdderNegativeLong").unwrap();
let last_frame_value = vm
.run("samples.arithmetics.addernegative.AdderNegativeLong")
.unwrap();
assert_eq!(-1990000000000000, get_long(last_frame_value))
}

#[test]
fn should_do_subtraction() {
let vm = VM::new(vec!["tests/test_data/Sub.class"], "tests/test_data/std").unwrap();
let last_frame_value = vm.run("Sub").unwrap();
let vm = VM::new(
vec!["tests/test_data/samples/arithmetics/sub/ints/SubInts.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("samples.arithmetics.sub.ints.SubInts").unwrap();
assert_eq!(-999, get_int(last_frame_value))
}

#[test]
fn should_do_subtraction_with_longs() {
let vm = VM::new(vec!["tests/test_data/SubLong.class"], "tests/test_data/std").unwrap();
let last_frame_value = vm.run("SubLong").unwrap();
let vm = VM::new(
vec!["tests/test_data/samples/arithmetics/sub/longs/SubLongs.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("samples.arithmetics.sub.longs.SubLongs").unwrap();
assert_eq!(-1_000_000_000, get_long(last_frame_value))
}

#[test]
fn should_write_read_instance_fields() {
let vm = VM::new(
vec![
"tests/test_data/InstanceFieldsUser.class",
"tests/test_data/InstanceFields.class",
"tests/test_data/samples/fields/instance/ints/InstanceFieldsUserInts.class",
"tests/test_data/samples/fields/instance/ints/InstanceFields.class",
],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("InstanceFieldsUser").unwrap();
let last_frame_value = vm
.run("samples.fields.instance.ints.InstanceFieldsUserInts")
.unwrap();
assert_eq!(110022, get_int(last_frame_value))
}

#[test]
fn should_write_read_instance_fields_with_longs() {
let vm = VM::new(
vec![
"tests/test_data/InstanceFieldsUserLong.class",
"tests/test_data/InstanceFieldsLong.class",
"tests/test_data/samples/fields/instance/longs/InstanceFieldsUserLong.class",
"tests/test_data/samples/fields/instance/longs/InstanceFields.class",
],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("InstanceFieldsUserLong").unwrap();
let last_frame_value = vm
.run("samples.fields.instance.longs.InstanceFieldsUserLong")
.unwrap();
assert_eq!(4_380_866_642_760, get_long(last_frame_value))
}

#[test]
fn should_write_read_static_fields() {
let vm = VM::new(
vec![
"tests/test_data/StaticFieldsUser.class",
"tests/test_data/StaticFields.class",
"tests/test_data/samples/fields/staticinitialization/ints/StaticFieldsUserInts.class",
"tests/test_data/samples/fields/staticinitialization/ints/StaticFields.class",
],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("StaticFieldsUser").unwrap();
let last_frame_value = vm
.run("samples.fields.staticinitialization.ints.StaticFieldsUserInts")
.unwrap();
assert_eq!(110022, get_int(last_frame_value))
}

#[test]
fn should_do_extreme_stack_operations() {
let vm = VM::new(
vec!["tests/test_data/ExtremeStackTest.class"],
vec!["tests/test_data/samples/arithmetics/extremestack/ints/ExtremeStackInt.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("ExtremeStackTest").unwrap();
let last_frame_value = vm
.run("samples.arithmetics.extremestack.ints.ExtremeStackInt")
.unwrap();
assert_eq!(454, get_int(last_frame_value))
}

#[test]
fn should_do_extreme_stack_operations_with_longs() {
let vm = VM::new(
vec!["tests/test_data/ExtremeStackTestLong.class"],
vec!["tests/test_data/samples/arithmetics/extremestack/longs/ExtremeStackLong.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("ExtremeStackTestLong").unwrap();
let last_frame_value = vm
.run("samples.arithmetics.extremestack.longs.ExtremeStackLong")
.unwrap();
assert_eq!(454, get_long(last_frame_value))
}

#[test]
fn should_do_calculate_fibonacci_iteratively() {
let vm = VM::new(
vec!["tests/test_data/FibonacciIterative.class"],
vec!["tests/test_data/samples/arithmetics/fibonacci/iterative/FibonacciIterative.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("FibonacciIterative").unwrap();
let last_frame_value = vm
.run("samples.arithmetics.fibonacci.iterative.FibonacciIterative")
.unwrap();
assert_eq!(55, get_int(last_frame_value))
}

#[test]
fn should_do_calculate_fibonacci_recursively() {
let vm = VM::new(
vec!["tests/test_data/FibonacciRecursive.class"],
vec!["tests/test_data/samples/arithmetics/fibonacci/recursive/FibonacciRecursive.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("FibonacciRecursive").unwrap();
let last_frame_value = vm
.run("samples.arithmetics.fibonacci.recursive.FibonacciRecursive")
.unwrap();
assert_eq!(55, get_int(last_frame_value))
}

#[test]
fn should_do_arrays() {
let vm = VM::new(vec!["tests/test_data/Array.class"], "tests/test_data/std").unwrap();
let last_frame_value = vm.run("Array").unwrap();
let vm = VM::new(
vec!["tests/test_data/samples/arrays/array/ints/ArrayInt.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("samples.arrays.array.ints.ArrayInt").unwrap();
assert_eq!(740, get_int(last_frame_value))
}

#[test]
fn should_do_arrays_with_longs() {
let vm = VM::new(
vec!["tests/test_data/ArrayLong.class"],
vec!["tests/test_data/samples/arrays/array/longs/ArrayLong.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("ArrayLong").unwrap();
let last_frame_value = vm.run("samples.arrays.array.longs.ArrayLong").unwrap();
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();
let vm = VM::new(
vec!["tests/test_data/samples/arrays/array3d/Array3D.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("samples.arrays.array3d.Array3D").unwrap();
assert_eq!(780, get_int(last_frame_value))
}

#[test]
fn should_do_class_static_initialization() {
let vm = VM::new(
vec!["tests/test_data/StaticInitialization.class"],
vec!["tests/test_data/samples/fields/staticinitialization/array/StaticInitializationArray.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("StaticInitialization").unwrap();
let last_frame_value = vm
.run("samples.fields.staticinitialization.array.StaticInitializationArray")
.unwrap();
assert_eq!(257, get_int(last_frame_value))
}

#[test]
fn should_do_class_static_initialization_multiple_classes() {
let vm = VM::new(
vec![
"tests/test_data/Dependable.class",
"tests/test_data/DependsOnDependable.class",
"tests/test_data/StaticInitializationUser.class",
"tests/test_data/samples/fields/staticinitialization/chain/Dependable.class",
"tests/test_data/samples/fields/staticinitialization/chain/DependsOnDependable.class",
"tests/test_data/samples/fields/staticinitialization/chain/StaticInitializationChain.class",
],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("StaticInitializationUser").unwrap();
let last_frame_value = vm
.run("samples.fields.staticinitialization.chain.StaticInitializationChain")
.unwrap();
assert_eq!(350, get_int(last_frame_value))
}

#[test]
fn should_do_class_static_initialization_within_one_class() {
let vm = VM::new(
vec!["tests/test_data/StaticInitializationWithinOneClass.class"],
vec!["tests/test_data/samples/fields/staticinitialization/oneclass/StaticInitializationWithinOneClass.class"],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("StaticInitializationWithinOneClass").unwrap();
let last_frame_value = vm
.run("samples.fields.staticinitialization.oneclass.StaticInitializationWithinOneClass")
.unwrap();
assert_eq!(100, get_int(last_frame_value))
}

#[test]
fn should_do_class_static_initialization_advanced() {
let vm = VM::new(
vec![
"tests/test_data/StaticInitializationAdvanced.class",
"tests/test_data/ClassA.class",
"tests/test_data/ClassB.class",
"tests/test_data/ClassC.class",
"tests/test_data/ClassD.class",
"tests/test_data/ClassE.class",
"tests/test_data/Helper.class",
"tests/test_data/samples/fields/staticinitialization/advanced/StaticInitializationAdvanced.class",
"tests/test_data/samples/fields/staticinitialization/advanced/ClassC.class",
"tests/test_data/samples/fields/staticinitialization/advanced/ClassD.class",
"tests/test_data/samples/fields/staticinitialization/advanced/ClassE.class",
"tests/test_data/samples/fields/staticinitialization/advanced/Helper.class",
],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("StaticInitializationAdvanced").unwrap();
let last_frame_value = vm
.run("samples.fields.staticinitialization.advanced.StaticInitializationAdvanced")
.unwrap();
assert_eq!(826, get_int(last_frame_value))
}

#[test]
fn should_do_class_static_initialization_circular() {
let vm = VM::new(
vec![
"tests/test_data/StaticInitializationCircular.class",
"tests/test_data/ClassACircular.class",
"tests/test_data/ClassBCircular.class",
"tests/test_data/samples/fields/staticinitialization/circular/StaticInitializationCircular.class",
"tests/test_data/samples/fields/staticinitialization/circular/ClassACircular.class",
"tests/test_data/samples/fields/staticinitialization/circular/ClassBCircular.class",
],
"tests/test_data/std",
)
.unwrap();
let last_frame_value = vm.run("StaticInitializationCircular").unwrap();
let last_frame_value = vm
.run("samples.fields.staticinitialization.circular.StaticInitializationCircular")
.unwrap();
assert_eq!(700, get_int(last_frame_value))
}

Expand Down
Binary file removed tests/test_data/Adder.class
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_data/Adder.java → tests/test_data/AdderInt.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//javac -g -parameters Adder.java
package samples.arithmetics.adder.ints;

public class Adder {
public class AdderInt {

public static void main(String[] args) {
int result = add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
Expand Down
Binary file removed tests/test_data/AdderLong.class
Binary file not shown.
1 change: 1 addition & 0 deletions tests/test_data/AdderLong.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package samples.arithmetics.adder.longs;

public class AdderLong {

Expand Down
Binary file removed tests/test_data/AdderNegativeLong.class
Binary file not shown.
1 change: 1 addition & 0 deletions tests/test_data/AdderNegativeLong.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package samples.arithmetics.addernegative;

public class AdderNegativeLong {

Expand Down
2 changes: 2 additions & 0 deletions tests/test_data/Array3D.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package samples.arrays.array3d;

public class Array3D {
public static void main(String[] args) {
int[][][] array = new int[][][]{
Expand Down
4 changes: 3 additions & 1 deletion tests/test_data/Array.java → tests/test_data/ArrayInt.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
public class Array {
package samples.arrays.array.ints;

public class ArrayInt {

public static void main(String[] args) {
// 1. Initialize two arrays with different sizes
Expand Down
2 changes: 2 additions & 0 deletions tests/test_data/ArrayLong.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package samples.arrays.array.longs;

public class ArrayLong {

public static void main(String[] args) {
Expand Down
Binary file removed tests/test_data/ClassA.class
Binary file not shown.
Binary file removed tests/test_data/ClassB.class
Binary file not shown.
Binary file removed tests/test_data/ClassC.class
Binary file not shown.
Binary file removed tests/test_data/ClassD.class
Binary file not shown.
Binary file removed tests/test_data/ClassE.class
Binary file not shown.
Binary file removed tests/test_data/Dependable.class
Binary file not shown.
8 changes: 0 additions & 8 deletions tests/test_data/Dependable.java

This file was deleted.

Binary file removed tests/test_data/DependsOnDependable.class
Binary file not shown.
8 changes: 0 additions & 8 deletions tests/test_data/DependsOnDependable.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package samples.arithmetics.extremestack.ints;

public class ExtremeStackTest {
public class ExtremeStackInt {

public static void main(String[] args) {
// Test nested operations and method calls
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package samples.arithmetics.extremestack.longs;

public class ExtremeStackTestLong {
public class ExtremeStackLong {

public static void main(String[] args) {
// Test nested operations and method calls
Expand Down
Binary file removed tests/test_data/ExtremeStackTest.class
Binary file not shown.
Binary file removed tests/test_data/ExtremeStackTestLong.class
Binary file not shown.
Loading

0 comments on commit 580feca

Please sign in to comment.