Skip to content

Commit

Permalink
Better refactor of getWrap and tests for equals
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinfjola authored and JoopAue committed Mar 24, 2016
1 parent 2086ae1 commit d3a64e5
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 41 deletions.
16 changes: 8 additions & 8 deletions jme3-core/src/main/java/com/jme3/texture/Texture.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,9 @@ public void setWrap(WrapMode mode) {
* if axis is null or invalid for this type of texture
*/
public WrapMode getWrap(WrapAxis axis) {
switch (axis) {
case S:
return wrapS;
case T:
return wrapT;
default:
throw new IllegalArgumentException("invalid WrapAxis: " + axis);
}
if (axis == WrapAxis.S) return wrapS;
else if (axis == WrapAxis.T) return wrapT;
throw new IllegalArgumentException("invalid WrapAxis: " + axis);
}

public abstract Type getType();
Expand Down Expand Up @@ -556,6 +551,11 @@ public boolean equals(Object obj) {
return false;
}
final Texture other = (Texture) obj;

if (this.getWrap(WrapAxis.S) != other.getWrap(WrapAxis.S))
return false;
if (this.getWrap(WrapAxis.T) != other.getWrap(WrapAxis.T))
return false;

// NOTE: Since images are generally considered unique assets in jME3,
// using the image's equals() implementation is not neccessary here
Expand Down
13 changes: 4 additions & 9 deletions jme3-core/src/main/java/com/jme3/texture/Texture2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,13 @@ public void setWrap(WrapMode mode) {
* the axis to return for
* @return the wrap mode of the texture.
* @throws IllegalArgumentException
* if axis is null
* if axis is null or invalid for this type
*/
public WrapMode getWrap(WrapAxis axis) {
if (axis == null) {
throw new IllegalArgumentException("axis can not be null.");
}
switch (axis) {
case R:
throw new IllegalArgumentException("invalid WrapAxis: " + axis);
default:
return super.getWrap(axis);
if (axis == WrapAxis.R) {
throw new IllegalArgumentException("invalid WrapAxis: " + axis);
}
return super.getWrap(axis);
}

@Override
Expand Down
11 changes: 3 additions & 8 deletions jme3-core/src/main/java/com/jme3/texture/Texture3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,10 @@ public void setWrap(WrapMode mode) {
* if axis is null
*/
public WrapMode getWrap(WrapAxis axis) {
if (axis == null) {
throw new IllegalArgumentException("axis can not be null.");
}
switch (axis) {
case R:
return wrapR;
default:
return super.getWrap(axis);
if (axis == WrapAxis.R) {
return wrapR;
}
return super.getWrap(axis);
}

@Override
Expand Down
11 changes: 3 additions & 8 deletions jme3-core/src/main/java/com/jme3/texture/TextureArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,10 @@ public Type getType() {

@Override
public WrapMode getWrap(WrapAxis axis) {
if (axis == null) {
throw new IllegalArgumentException("axis can not be null.");
}
switch (axis) {
case R:
throw new IllegalArgumentException("invalid WrapAxis: " + axis);
default:
return super.getWrap(axis);
if (axis == WrapAxis.R) {
throw new IllegalArgumentException("invalid WrapAxis: " + axis);
}
return super.getWrap(axis);
}

@Override
Expand Down
11 changes: 3 additions & 8 deletions jme3-core/src/main/java/com/jme3/texture/TextureCubeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,10 @@ public void setWrap(WrapMode mode) {
* if axis is null
*/
public WrapMode getWrap(WrapAxis axis) {
if (axis == null) {
throw new IllegalArgumentException("axis can not be null.");
}
switch (axis) {
case R:
return wrapR;
default:
return super.getWrap(axis);
if (axis == WrapAxis.R) {
return wrapR;
}
return super.getWrap(axis);
}

@Override
Expand Down
25 changes: 25 additions & 0 deletions jme3-core/src/test/java/com/jme3/texture/Texture2DTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ public void testGetWrapSetAllAxisR() {
tex.getWrap(Texture.WrapAxis.R);
}

/**
Test equals(Object)
**/

@Test
public void testEqualsSameAxises() {
Texture2D tex1 = new Texture2D();
Texture2D tex2 = new Texture2D();

tex1.setWrap(Texture.WrapMode.EdgeClamp);
tex2.setWrap(Texture.WrapMode.EdgeClamp);

assert tex1.equals(tex2) == true;
assert tex2.equals(tex1) == true;
}

@Test
public void testEqualsDiffAxises() {
Texture2D tex1 = new Texture2D();
Texture2D tex2 = new Texture2D();

tex1.setWrap(Texture.WrapAxis.S, Texture.WrapMode.EdgeClamp);
tex2.setWrap(Texture.WrapAxis.S, Texture.WrapMode.MirroredRepeat);

assert tex1.equals(tex2) == false;
assert tex2.equals(tex1) == false;
}
}
28 changes: 28 additions & 0 deletions jme3-core/src/test/java/com/jme3/texture/Texture3DTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,32 @@ public void testGetWrapSetOneAxisR() {
tex.setWrap(wrapAxis, wrapMode);
assert tex.getWrap(wrapAxis) == wrapMode;
}

/**
Test equals(Object)
**/

@Test
public void testEqualsSameAxises() {
Texture3D tex1 = new Texture3D();
Texture3D tex2 = new Texture3D();

tex1.setWrap(Texture.WrapMode.EdgeClamp);
tex2.setWrap(Texture.WrapMode.EdgeClamp);

assert tex1.equals(tex2) == true;
assert tex2.equals(tex1) == true;
}

@Test
public void testEqualsDiffAxises() {
Texture3D tex1 = new Texture3D();
Texture3D tex2 = new Texture3D();

tex1.setWrap(Texture.WrapAxis.R, Texture.WrapMode.Repeat);
tex2.setWrap(Texture.WrapAxis.R, Texture.WrapMode.MirroredRepeat);

assert tex1.equals(tex2) == false;
assert tex2.equals(tex1) == false;
}
}
28 changes: 28 additions & 0 deletions jme3-core/src/test/java/com/jme3/texture/TextureCubeMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,32 @@ public void testGetWrapSetOneAxisR() {
tex.setWrap(wrapAxis, wrapMode);
assert tex.getWrap(wrapAxis) == wrapMode;
}

/**
Test equals(Object)
**/

@Test
public void testEqualsDiffAxises() {
TextureCubeMap tex1 = new TextureCubeMap();
TextureCubeMap tex2 = new TextureCubeMap();

tex1.setWrap(Texture.WrapMode.EdgeClamp);
tex2.setWrap(Texture.WrapMode.EdgeClamp);

assert tex1.equals(tex2) == true;
assert tex2.equals(tex1) == true;
}

@Test
public void testEqualsSameAxises() {
TextureCubeMap tex1 = new TextureCubeMap();
TextureCubeMap tex2 = new TextureCubeMap();

tex1.setWrap(Texture.WrapAxis.T, Texture.WrapMode.Repeat);
tex2.setWrap(Texture.WrapAxis.T, Texture.WrapMode.EdgeClamp);

assert tex1.equals(tex2) == false;
assert tex2.equals(tex1) == false;
}
}
2 changes: 2 additions & 0 deletions jme3-core/src/test/java/com/jme3/texture/TextureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ public void testGetWrapSetOneAxisT() {
tex.setWrap(wrapAxis, wrapMode);
assert tex.getWrap(wrapAxis) == wrapMode;
}


}

0 comments on commit d3a64e5

Please sign in to comment.