summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-12-31 14:52:36 +0100
committerSven Gothel <[email protected]>2012-12-31 14:52:36 +0100
commit8b3e5b94bcd3167278eb972b2be37086d3bd2996 (patch)
treec09970a1990e3bb7bb676f275c0a51af63df3cb6
parentac16df0bab94fab313030ead42644844d1690a82 (diff)
PrimitiveStack: Add 'void position(int)' to set new position. Add test case w/ initialSizeElem:=0.
-rw-r--r--src/java/com/jogamp/common/util/FloatStack.java10
-rw-r--r--src/java/com/jogamp/common/util/PrimitiveStack.java18
-rw-r--r--src/junit/com/jogamp/common/util/TestFloatStack01.java78
3 files changed, 79 insertions, 27 deletions
diff --git a/src/java/com/jogamp/common/util/FloatStack.java b/src/java/com/jogamp/common/util/FloatStack.java
index e5790a9..2addd76 100644
--- a/src/java/com/jogamp/common/util/FloatStack.java
+++ b/src/java/com/jogamp/common/util/FloatStack.java
@@ -63,6 +63,14 @@ public class /*name*/FloatStack/*name*/ implements PrimitiveStack {
public final int position() { return position; }
@Override
+ public final void position(int newPosition) throws IndexOutOfBoundsException {
+ if( 0 > position || position >= buffer.length ) {
+ throw new IndexOutOfBoundsException("Invalid new position "+newPosition+", "+this.toString());
+ }
+ position = newPosition;
+ }
+
+ @Override
public final int remaining() { return buffer.length - position; }
@Override
@@ -72,7 +80,7 @@ public class /*name*/FloatStack/*name*/ implements PrimitiveStack {
public final void setGrowSize(int newGrowSize) { growSize = newGrowSize; }
public final String toString() {
- return "FloatStack[0..(top "+position+").."+buffer.length+", remaining "+remaining()+"]";
+ return "FloatStack[0..(pos "+position+").."+buffer.length+", remaining "+remaining()+"]";
}
public final /*value*/float/*value*/[] buffer() { return buffer; }
diff --git a/src/java/com/jogamp/common/util/PrimitiveStack.java b/src/java/com/jogamp/common/util/PrimitiveStack.java
index 23447e3..89ae72e 100644
--- a/src/java/com/jogamp/common/util/PrimitiveStack.java
+++ b/src/java/com/jogamp/common/util/PrimitiveStack.java
@@ -41,16 +41,24 @@ public interface PrimitiveStack {
int capacity();
/**
- * Returns the current position where the next put operation will store the next element.
+ * Returns the current position of this stack.
* <p>
- * The position equals to the number of elements already stored.
+ * Position is in the range: 0 &le; position &lt; {@link #capacity()}.
* </p>
- * <p>
- * 0 denotes an empty stack.
+ * <p>
+ * The position equals to the number of elements stored.
* </p>
**/
int position();
+ /**
+ * Sets the position of this stack.
+ *
+ * @param newPosition the new position
+ * @throws IndexOutOfBoundsException if <code>newPosition</code> is outside of range: 0 &le; position &lt; {@link #capacity()}.
+ */
+ void position(int newPosition) throws IndexOutOfBoundsException;
+
/**
* Returns the remaining elements left before stack will grow about {@link #getGrowSize()}.
* <pre>
@@ -68,5 +76,5 @@ public interface PrimitiveStack {
int getGrowSize();
/** Set new {@link #growSize(). */
- void setGrowSize(int newGrowSize);
+ void setGrowSize(int newGrowSize);
}
diff --git a/src/junit/com/jogamp/common/util/TestFloatStack01.java b/src/junit/com/jogamp/common/util/TestFloatStack01.java
index 0a2b077..90ac2e0 100644
--- a/src/junit/com/jogamp/common/util/TestFloatStack01.java
+++ b/src/junit/com/jogamp/common/util/TestFloatStack01.java
@@ -51,15 +51,28 @@ public class /*testname*/TestFloatStack01/*testname*/ extends JunitTracer {
@Test
- public void test01PrimitiveArray() {
+ public void test01PrimitiveArray_I32_G02() {
+ final int initialSizeElem = 32;
+ final int growSizeElem = 2;
+ testPrimitiveArrayImpl(initialSizeElem, growSizeElem);
+ }
+
+ @Test
+ public void test02PrimitiveArray_I00_G32() {
+ final int initialSizeElem = 0;
+ final int growSizeElem = 32;
+ testPrimitiveArrayImpl(initialSizeElem, growSizeElem);
+ }
+
+ static private final boolean VERBOSE = false;
+
+ private void testPrimitiveArrayImpl(int initialSizeElem, int growSizeElem) {
final int compNum = 3;
/*value*/float/*value*/[] e0 =
new /*value*/float/*value*/[] { 0, 1, 2 };
/*value*/float/*value*/[] e1 =
new /*value*/float/*value*/[] { 3, 4, 5 };
- final int initialSizeElem = 32;
- final int growSizeElem = 2;
final int totalSizeElem = initialSizeElem+2*growSizeElem;
final int initialSizeComp = initialSizeElem*compNum;
@@ -72,27 +85,38 @@ public class /*testname*/TestFloatStack01/*testname*/ extends JunitTracer {
//
// PUT
//
-
+ if(VERBOSE) {
+ System.err.println("0: "+fs0);
+ }
for(int i=0; i<totalSizeElem; i++) {
if(i < initialSizeElem) {
- Assert.assertTrue("Error "+fs0, fs0.remaining() == (initialSizeElem-i)*compNum);
+ Assert.assertTrue("Error #"+i+", "+fs0, fs0.remaining() == (initialSizeElem-i)*compNum);
} else {
- int j = ( i - initialSizeElem ) % growSizeElem ;
- Assert.assertTrue("Error "+fs0, fs0.remaining() == j*compNum);
+ final int j = ( i - initialSizeElem ) % growSizeElem ;
+ final int k = ( 0 < j && j < growSizeElem ) ? growSizeElem - j : 0;
+ Assert.assertTrue("Error #"+i+"("+j+", "+k+"), "+fs0, fs0.remaining() == k*compNum);
}
Assert.assertTrue("Error "+fs0, fs0.position() == i*compNum);
- // String s;
+ String s;
if( 0 == i % 2) {
- // s = Arrays.toString(e0);
+ if(VERBOSE) {
+ s = Arrays.toString(e0);
+ }
fs0.putOnTop(e0, 0, compNum);
} else {
- // s = Arrays.toString(e1);
+ if(VERBOSE) {
+ s = Arrays.toString(e1);
+ }
fs0.putOnTop(e1, 0, compNum);
}
- // System.err.println("#"+i+"/"+totalSizeElem+": "+fs0+" <- "+s);
+ if(VERBOSE) {
+ System.err.println("#"+i+"/"+totalSizeElem+": "+fs0+" <- "+s);
+ }
+ }
+ if(VERBOSE) {
+ System.err.println("X: "+fs0);
}
- // System.err.println("X: "+fs0);
Assert.assertTrue("Error "+fs0, fs0.remaining() == 0);
Assert.assertTrue("Error "+fs0, fs0.position() == totalSizeComp);
@@ -145,7 +169,20 @@ public class /*testname*/TestFloatStack01/*testname*/ extends JunitTracer {
}
@Test
- public void test02FloatBuffer() {
+ public void test11FloatBuffer_I32_G02() {
+ final int initialSizeElem = 32;
+ final int growSizeElem = 2;
+ testFloatBufferImpl(initialSizeElem, growSizeElem);
+ }
+
+ @Test
+ public void test12FloatBuffer_I00_G32() {
+ final int initialSizeElem = 0;
+ final int growSizeElem = 32;
+ testFloatBufferImpl(initialSizeElem, growSizeElem);
+ }
+
+ private void testFloatBufferImpl(int initialSizeElem, int growSizeElem) {
final int compNum = 3;
/*value2*/FloatBuffer/*value2*/ fb0 =
/*value2*/FloatBuffer/*value2*/.allocate(3*compNum);
@@ -161,8 +198,6 @@ public class /*testname*/TestFloatStack01/*testname*/ extends JunitTracer {
fb0.put(e2);
fb0.position(0);
- final int initialSizeElem = 32;
- final int growSizeElem = 2;
final int totalSizeElem = initialSizeElem+2*growSizeElem;
final int initialSizeComp = initialSizeElem*compNum;
@@ -178,18 +213,19 @@ public class /*testname*/TestFloatStack01/*testname*/ extends JunitTracer {
for(int i=0; i<totalSizeElem; i++) {
if( 0 == i ) {
- Assert.assertTrue("Error "+fs0+", "+fb0, fb0.position() == 0);
+ Assert.assertTrue("Error #"+i+", "+fs0+", "+fb0, fb0.position() == 0);
} else if( 0 == i % 2) {
- Assert.assertTrue("Error "+fs0+", "+fb0, fb0.position() == 2*compNum);
+ Assert.assertTrue("Error #"+i+", "+fs0+", "+fb0, fb0.position() == 2*compNum);
fb0.position(0);
} else {
- Assert.assertTrue("Error "+fs0+", "+fb0, fb0.position() == compNum);
+ Assert.assertTrue("Error #"+i+", "+fs0+", "+fb0, fb0.position() == compNum);
}
if(i < initialSizeElem) {
- Assert.assertTrue("Error "+fs0, fs0.remaining() == (initialSizeElem-i)*compNum);
+ Assert.assertTrue("Error #"+i+", "+fs0, fs0.remaining() == (initialSizeElem-i)*compNum);
} else {
- int j = ( i - initialSizeElem ) % growSizeElem ;
- Assert.assertTrue("Error "+fs0, fs0.remaining() == j*compNum);
+ final int j = ( i - initialSizeElem ) % growSizeElem ;
+ final int k = ( 0 < j && j < growSizeElem ) ? growSizeElem - j : 0;
+ Assert.assertTrue("Error #"+i+"("+j+", "+k+"), "+fs0, fs0.remaining() == k*compNum);
}
Assert.assertTrue("Error "+fs0, fs0.position() == i*compNum);