-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathPyArrayTest.java
More file actions
53 lines (41 loc) · 2.47 KB
/
Copy pathPyArrayTest.java
File metadata and controls
53 lines (41 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package org.python.core;
import junit.framework.TestCase;
/**
* Tests for PyArray.
*/
public class PyArrayTest extends TestCase {
public void testSetSliceNegativeStep() {
PyArray arrayToModify = new PyArray(PyBytes.class, new String[] {"a", "b", "c", "d"});
// Replacing single element
PyArray arrayOneElement = new PyArray(PyBytes.class, new String[] {"z"});
arrayToModify.setslice(0, 0, -1, arrayOneElement);
assertEquals(new PyArray(PyBytes.class, new String[] {"z", "b", "c", "d"}), arrayToModify);
// Replacing multiple elements
arrayToModify = new PyArray(PyBytes.class, new String[] {"a", "b", "c", "d"});
PyArray arrayThreeElements = new PyArray(PyBytes.class, new String[] {"x", "y", "z"});
arrayToModify.setslice(2, 0, -1, arrayThreeElements);
assertEquals(new PyArray(PyBytes.class, new String[] {"z", "y", "x", "d"}), arrayToModify);
// Replacing multiple elements - step size = (-2)
arrayToModify = new PyArray(PyBytes.class, new String[] {"a", "b", "c", "d"});
PyArray arrayTwoElements = new PyArray(PyBytes.class, new String[] {"x", "y"});
arrayToModify.setslice(3, 0, -2, arrayTwoElements);
assertEquals(new PyArray(PyBytes.class, new String[] {"a", "y", "c", "x"}), arrayToModify);
}
public void testSetSlicePositiveStep() {
PyArray arrayToModify = new PyArray(PyBytes.class, new String[] {"a", "b", "c", "d"});
// Replacing single element
PyArray arrayOneElement = new PyArray(PyBytes.class, new String[] {"z"});
arrayToModify.setslice(0, 1, 1, arrayOneElement);
assertEquals(new PyArray(PyBytes.class, new String[] {"z", "b", "c", "d"}), arrayToModify);
// Replacing multiple elements
arrayToModify = new PyArray(PyBytes.class, new String[] {"a", "b", "c", "d"});
PyArray arrayMultipleElements = new PyArray(PyBytes.class, new String[] {"x", "y"});
arrayToModify.setslice(1, 3, 1, arrayMultipleElements);
assertEquals(new PyArray(PyBytes.class, new String[] {"a", "x", "y", "d"}), arrayToModify);
// Replace multiple elements - step = 2
arrayToModify = new PyArray(PyBytes.class, new String[] {"a", "b", "c", "d"});
arrayMultipleElements = new PyArray(PyBytes.class, new String[] {"x", "y"});
arrayToModify.setslice(0, 3, 2, arrayMultipleElements);
assertEquals(new PyArray(PyBytes.class, new String[] {"x", "b", "y", "d"}), arrayToModify);
}
}