Skip to content

Commit 964976b

Browse files
committed
Adding unit test cases for PShapeOBJ addMaterials() and rgbaValue()
1 parent 4206874 commit 964976b

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package processing.core;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
import java.util.ArrayList;
7+
import java.util.HashMap;
8+
9+
/*
10+
* Unit tests for PShapeOBJ class
11+
* */
12+
public class PShapeOBJTest {
13+
14+
/*
15+
* Test rgbaValue method with white color
16+
* */
17+
@Test
18+
public void testRgbaValueWhiteColor() {
19+
PVector whiteColor = new PVector(1.0f, 1.0f, 1.0f);
20+
int rgba = PShapeOBJ.rgbaValue(whiteColor);
21+
22+
// White: 0xFF
23+
Assert.assertEquals(0xFFFFFFFF, rgba);
24+
}
25+
26+
/*
27+
* Test addMaterial method
28+
* */
29+
@Test
30+
public void testAddMaterials(){
31+
ArrayList<PShapeOBJ.OBJMaterial> materialsList = new ArrayList<>();
32+
HashMap<String, Integer> materialHash = new HashMap<>();
33+
34+
PShapeOBJ.OBJMaterial material = PShapeOBJ.addMaterial("testMaterial",materialsList, materialHash);
35+
36+
Assert.assertEquals("testMaterial",material.name);
37+
Assert.assertEquals(1,materialHash.size());
38+
Assert.assertEquals(1, materialsList.size());
39+
}
40+
41+
/*
42+
* Test addMaterial method with multiple value
43+
* */
44+
@Test
45+
public void testAddMaterialsMultiple(){
46+
ArrayList<PShapeOBJ.OBJMaterial> materialsList = new ArrayList<>();
47+
HashMap<String, Integer> materialHash = new HashMap<>();
48+
49+
PShapeOBJ.OBJMaterial material1 = PShapeOBJ.addMaterial("testMaterial1",materialsList, materialHash);
50+
PShapeOBJ.OBJMaterial material2 = PShapeOBJ.addMaterial("testMaterial2",materialsList, materialHash);
51+
PShapeOBJ.OBJMaterial material3 = PShapeOBJ.addMaterial("testMaterial3",materialsList, materialHash);
52+
53+
// Checking the size
54+
Assert.assertEquals(3,materialsList.size());
55+
Assert.assertEquals(3,materialHash.size());
56+
57+
// Checking the material name
58+
Assert.assertEquals("testMaterial1",material1.name);
59+
Assert.assertEquals("testMaterial2",material2.name);
60+
Assert.assertEquals("testMaterial3",material3.name);
61+
}
62+
63+
/*
64+
* Test addMaterial with null value
65+
* */
66+
@Test
67+
public void testAddMaterialWithNullValue(){
68+
ArrayList<PShapeOBJ.OBJMaterial> materialsList = new ArrayList<>();
69+
HashMap<String, Integer> materialHash = new HashMap<>();
70+
71+
PShapeOBJ.OBJMaterial material1 = PShapeOBJ.addMaterial(null,materialsList, materialHash);
72+
PShapeOBJ.OBJMaterial material2 = PShapeOBJ.addMaterial(null,materialsList, materialHash);
73+
74+
Assert.assertNull(materialsList.get(0).name);
75+
// Checking null value
76+
Assert.assertNotNull(materialHash.get(null));
77+
Assert.assertEquals(1, materialHash.size());
78+
}
79+
80+
/*
81+
* Test addMaterial with duplicate value
82+
* */
83+
@Test
84+
public void testAddMaterialDuplicateNameOverwritesHash(){
85+
ArrayList<PShapeOBJ.OBJMaterial> materialsList = new ArrayList<>();
86+
HashMap<String, Integer> materialHash = new HashMap<>();
87+
88+
PShapeOBJ.addMaterial("material", materialsList, materialHash);
89+
PShapeOBJ.addMaterial("material", materialsList, materialHash);
90+
91+
Assert.assertEquals(2, materialsList.size());
92+
Assert.assertEquals(1, materialHash.size());
93+
94+
Assert.assertEquals(1, materialHash.get("material").intValue());
95+
}
96+
}

0 commit comments

Comments
 (0)