Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primitive Data Types: Multiple Jarray #39

Open
nsanitate opened this issue Aug 7, 2017 · 0 comments
Open

Primitive Data Types: Multiple Jarray #39

nsanitate opened this issue Aug 7, 2017 · 0 comments

Comments

@nsanitate
Copy link
Member

Implement the multiple array type that allow to overcome the differences between Java and JavaScript.

Expected Behavior

  • Declaring a Variable to refer to a Multiple Array
  • Creating, Initializing, and Accessing a Multiple Array
    • shortcut syntax
  • Exceptions
    • array index out of bound exception

Acceptance test

Declaring a Variable to refer to a Multiple Array

let aMultipleArray: Jarray<Jdouble>;

Creating, Initializing, and Accessing a Multiple Array

const aMultipleArray = new Jarray<Jdouble>(jint('3'), jint('2'));

aMultipleArray.set(jint('0'), jint('0'), jdouble('1.1'));
aMultipleArray.set(jint('0'), jint('1'), jdouble('1.2'));
aMultipleArray.set(jint('1'), jint('0'), jdouble('2.1'));
aMultipleArray.set(jint('1'), jint('1'), jdouble('2.2'));
aMultipleArray.set(jint('2'), jint('0'), jdouble('3.1'));
aMultipleArray.set(jint('2'), jint('1'), jdouble('3.2'));

console.log("Element at index 0,0: " + aMultipleArray.get(jint('0'), jint('0')));
console.log("Element at index 0,1: " + aMultipleArray.get(jint('0'), jint('1')));
console.log("Element at index 1,0: " + aMultipleArray.get(jint('1'), jint('0')));
console.log("Element at index 1,1: " + aMultipleArray.get(jint('1'), jint('1')));
console.log("Element at index 2,0: " + aMultipleArray.get(jint('2'), jint('0')));
console.log("Element at index 2,1: " + aMultipleArray.get(jint('2'), jint('1')));

// shortcut syntax
const anotherMultipleArray = new Jarray<Jdouble>([jdouble('1.1'), jdouble('2.1'), jdouble('3.1')], [jdouble('1.2'), jdouble('2.2'), jdouble('3.2')]);

console.log("Element at index 0,0: " + anotherMultipleArray.get(jint('0'), jint('0')));
console.log("Element at index 0,1: " + anotherMultipleArray.get(jint('0'), jint('1')));
console.log("Element at index 1,0: " + anotherMultipleArray.get(jint('1'), jint('0')));
console.log("Element at index 1,1: " + anotherMultipleArray.get(jint('1'), jint('1')));
console.log("Element at index 2,0: " + anotherMultipleArray.get(jint('2'), jint('0')));
console.log("Element at index 2,1: " + anotherMultipleArray.get(jint('2'), jint('1')));

Output:

Element at index 0,0: 1.1
Element at index 0,1: 1.2
Element at index 1,0: 2.1
Element at index 1,1: 2.2
Element at index 2,0: 3.1
Element at index 2,1: 3.2

Element at index 0,0: 1.1
Element at index 0,1: 1.2
Element at index 1,0: 2.1
Element at index 1,1: 2.2
Element at index 2,0: 3.1
Element at index 2,1: 3.2

Exceptions

const aMultipleArray = new Jarray<Jdouble>(jint('3'), jint('2'));
console.log("Element at index 3,0: " + anArray.get(jint('3'), jint('0')));
console.log("Element at index 0,2: " + anArray.get(jint('0'), jint('2')));
console.log("Element at index 3,2: " + anArray.get(jint('3'), jint('2')));

Output:

ERROR: JArrayIndexOutOfBoundsException: 3
ERROR: JArrayIndexOutOfBoundsException: 2
ERROR: JArrayIndexOutOfBoundsException: 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant