Skip to content

Commit e3658d7

Browse files
committed
fixing more maintainability and intentionality issues
1 parent 931d873 commit e3658d7

File tree

10 files changed

+62
-69
lines changed

10 files changed

+62
-69
lines changed

entity-component-system/src/main/java/com/iluwatar/App.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public static void main(String[] args) {
7575
velocity1.applyForce(0.5f, 0.0f, 0.0f);
7676
}
7777

78-
gameSystem.renderSystem();
7978
}
8079
}
8180
}

entity-component-system/src/main/java/com/iluwatar/Entity.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ public void addChild(Entity child) {
131131
}
132132
}
133133

134+
/**
135+
* Finds a Child Entity in Children List.
136+
*
137+
* @param entityId the child entity to be removed
138+
*/
139+
public Entity findChildEntity(UUID entityId) {
140+
for (Entity child : children) {
141+
if (Objects.equals(child.getEntityId(), entityId)) {
142+
return child;
143+
}
144+
}
145+
return null;
146+
}
134147

135148
/**
136149
* Removes a child entity from this entity.
@@ -206,15 +219,6 @@ public List<Component> getComponents() {
206219
return components;
207220
}
208221

209-
/**
210-
* Renders the entity and its components.
211-
*/
212-
public void renderEntity() {
213-
//for (Component component : components) {
214-
// Render each component
215-
//}
216-
}
217-
218222
// Getters and Setters for fields
219223

220224
/**

entity-component-system/src/main/java/com/iluwatar/GameSystem.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,6 @@ public void update(float deltaTime) {
108108
}
109109
}
110110

111-
/**
112-
* Renders the system (rendering logic can be implemented as needed).
113-
*/
114-
public void renderSystem() {
115-
//for (Entity entity : entities) {
116-
// Implement rendering logic
117-
//}
118-
}
119-
120111
/**
121112
* Sorts the entities by their distance from a given reference point in descending order.
122113
*

entity-component-system/src/main/java/com/iluwatar/HealthComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
package com.iluwatar;
2626

27-
import java.util.logging.Logger;
27+
2828

2929
/**
3030
* Abstract class representing a health component in the ECS system.

entity-component-system/src/main/java/com/iluwatar/VelocityComponent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525
package com.iluwatar;
2626

27-
import java.util.logging.Logger;
2827

2928
/**
3029
* A component that handles the velocity of an entity in 3D space.

entity-component-system/src/test/java/com/iluwatar/AppTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import static org.junit.jupiter.api.Assertions.*;
2828
import org.junit.jupiter.api.BeforeEach;
2929
import org.junit.jupiter.api.Test;
30-
import java.io.ByteArrayOutputStream;
31-
import java.io.PrintStream;
3230

3331
class AppTest {
3432

@@ -108,9 +106,9 @@ void testFinalEntityStateAfterSimulation() {
108106
GameSystem gameSystem = new GameSystem();
109107
gameSystem.addEntity(entity1);
110108
gameSystem.addEntity(entity2);
111-
TransformComponent transform1 = new TransformComponent(new float[]{5.0f, 0.0f, 0.0f},
109+
TransformComponent Testtransform = new TransformComponent(new float[]{5.0f, 0.0f, 0.0f},
112110
new float[]{0.0f, 45.0f, 0.0f}, new float[]{1.0f, 1.0f, 1.0f});
113-
entity1.setTransformComponent(transform1);
111+
entity1.setTransformComponent(Testtransform);
114112

115113
for (int i = 0; i < 10; i++) {
116114
gameSystem.update(1.0f / 60.0f);

entity-component-system/src/test/java/com/iluwatar/EntityTest.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import static org.junit.jupiter.api.Assertions.*;
3131

32-
public class EntityTest {
32+
class EntityTest {
3333

3434
private Entity entity1;
3535
private Entity entity2;
@@ -45,7 +45,6 @@ void setUp() {
4545
new float[]{0.0f, 0.0f, 0.0f}, new float[]{1.0f, 1.0f, 1.0f});
4646
transform2 = new TransformComponent(new float[]{5.0f, 0.0f, 0.0f},
4747
new float[]{0.0f, 45.0f, 0.0f}, new float[]{1.0f, 1.0f, 1.0f});
48-
4948
}
5049

5150
@Test
@@ -131,16 +130,6 @@ void testUpdate() {
131130
assertNotNull(entity1, "Entity1 should be updated.");
132131
}
133132

134-
@Test
135-
void testRenderEntity() {
136-
137-
Component component = new HealthComponent(100);
138-
Entity entity = new Entity("MyEntity");
139-
entity.addComponent(component);
140-
entity.renderEntity();
141-
142-
assertDoesNotThrow(() -> component.update(1.0f), "render function should not throw an exception");
143-
}
144133

145134
@Test
146135
void testGetName() {
@@ -220,6 +209,28 @@ void testUpdate_shouldUpdateChildEntities() {
220209
entity1.update(1.0f);
221210
assertDoesNotThrow(() -> child.update(1.0f));
222211
}
212+
213+
@Test
214+
void testFindChildEntity() {
215+
Entity parent = new Entity("parent");
216+
Entity child = new Entity("child");
217+
child.setParent(parent);
218+
parent.addChild(child);
219+
220+
assertEquals(parent.findChildEntity(child.getEntityId()),child, "The child object should match the one found.");
221+
222+
}
223+
224+
@Test
225+
void testNotFindChildEntity() {
226+
Entity parent = new Entity("parent");
227+
Entity child = new Entity("child");
228+
229+
assertNull(parent.findChildEntity(child.getEntityId()), "The child object should match the one found.");
230+
231+
}
232+
233+
223234
}
224235

225236

entity-component-system/src/test/java/com/iluwatar/GameSystemTest.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,5 @@ void testSortEntitiesByDistance() {
9898
assertEquals(entity2, sortedEntities.get(0), "Entity2 should be closer to the reference point than Entity1.");
9999
assertEquals(entity1, sortedEntities.get(1), "Entity1 should be farther from the reference point than Entity2.");
100100
}
101+
}
101102

102-
@Test
103-
void testRenderSystem() {
104-
105-
try {
106-
gameSystem.renderSystem();
107-
} catch (Exception e) {
108-
fail("Render method should not throw any exceptions.");
109-
}
110-
}
111-
}

entity-component-system/src/test/java/com/iluwatar/HealthComponentTest.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,45 +69,45 @@ void testUpdateFunction() {
6969

7070
@Test
7171
void testGetMaxHealth() {
72-
HealthComponent TesthealthComponent = new HealthComponent(100f);
72+
HealthComponent testHealthComponent = new HealthComponent(100f);
7373

74-
assertEquals(100f, TesthealthComponent.getMaxHealth(), "Max health should be 100.");
74+
assertEquals(100f, testHealthComponent.getMaxHealth(), "Max health should be 100.");
7575
}
7676

7777
@Test
7878
void testSetMaxHealth() {
79-
HealthComponent TesthealthComponent = new HealthComponent(100f);
80-
TesthealthComponent.setMaxHealth(120f);
79+
HealthComponent testHealthComponent = new HealthComponent(100f);
80+
testHealthComponent.setMaxHealth(120f);
8181

82-
assertEquals(120f, TesthealthComponent.getMaxHealth(), "Max health should be updated to 120.");
82+
assertEquals(120f, testHealthComponent.getMaxHealth(), "Max health should be updated to 120.");
8383
}
8484

8585
@Test
8686
void testIsAlive() {
8787

88-
HealthComponent TesthealthComponent = new HealthComponent(100f);
89-
assertTrue(TesthealthComponent.isAlive(), "Entity should be alive initially.");
90-
TesthealthComponent.applyDamage(100f);
88+
HealthComponent testHealthComponent = new HealthComponent(100f);
89+
assertTrue( testHealthComponent.isAlive(), "Entity should be alive initially.");
90+
testHealthComponent.applyDamage(100f);
9191

92-
assertFalse(TesthealthComponent.isAlive(), "Entity should be dead after taking 100 damage.");
92+
assertFalse( testHealthComponent.isAlive(), "Entity should be dead after taking 100 damage.");
9393
}
9494

9595
@Test
9696
void testSetAlive() {
9797

98-
HealthComponent TesthealthComponent = new HealthComponent(100f);
99-
assertTrue(TesthealthComponent.isAlive(), "Entity should be alive initially.");
100-
TesthealthComponent.setAlive(false);
98+
HealthComponent testHealthComponent = new HealthComponent(100f);
99+
assertTrue( testHealthComponent.isAlive(), "Entity should be alive initially.");
100+
testHealthComponent.setAlive(false);
101101

102-
assertFalse(TesthealthComponent.isAlive(), "Entity should be dead after setting alive to false.");
102+
assertFalse( testHealthComponent.isAlive(), "Entity should be dead after setting alive to false.");
103103
}
104104

105105
@Test
106106
void testSetCurrentHealth() {
107-
HealthComponent TesthealthComponent = new HealthComponent(100f);
108-
TesthealthComponent.setCurrentHealth(80f);
107+
HealthComponent testHealthComponent = new HealthComponent(100f);
108+
testHealthComponent.setCurrentHealth(80f);
109109

110-
assertEquals(80f, TesthealthComponent.getCurrentHealth(), "Current health should be updated to 80.");
110+
assertEquals(80f, testHealthComponent.getCurrentHealth(), "Current health should be updated to 80.");
111111
}
112112
@Test
113113
void testHealthCannotGoAboveMax() {

entity-component-system/src/test/java/com/iluwatar/TransformComponentTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ void setUp() {
4242

4343
@Test
4444
void testTransformComponentConstructor() {
45-
TransformComponent Testtransform = new TransformComponent();
45+
TransformComponent testTransform = new TransformComponent();
4646

4747
float[] expectedPosition = new float[]{0.0f, 0.0f, 0.0f};
4848
float[] expectedRotation = new float[]{0.0f, 0.0f, 0.0f};
4949
float[] expectedScale = new float[]{1.0f, 1.0f, 1.0f};
5050

51-
assertArrayEquals(expectedPosition, transform.getPosition(), "Position should be initialized to [0.0f, 0.0f, 0.0f]");
52-
assertArrayEquals(expectedRotation, transform.getRotation(), "Rotation should be initialized to [0.0f, 0.0f, 0.0f]");
53-
assertArrayEquals(expectedScale, transform.getScale(), "Scale should be initialized to [1.0f, 1.0f, 1.0f]");
51+
assertArrayEquals(expectedPosition, testTransform.getPosition(), "Position should be initialized to [0.0f, 0.0f, 0.0f]");
52+
assertArrayEquals(expectedRotation, testTransform.getRotation(), "Rotation should be initialized to [0.0f, 0.0f, 0.0f]");
53+
assertArrayEquals(expectedScale, testTransform.getScale(), "Scale should be initialized to [1.0f, 1.0f, 1.0f]");
5454
}
5555

5656
@Test
@@ -90,9 +90,9 @@ void testGetScale() {
9090

9191
@Test
9292
void testUpdateFunction() {
93-
TransformComponent Testtransform = new TransformComponent();
93+
TransformComponent testTransform = new TransformComponent();
9494

95-
assertDoesNotThrow(() -> transform.update(1.0f), "update function should not throw an exception");
95+
assertDoesNotThrow(() -> testTransform.update(1.0f), "update function should not throw an exception");
9696
}
9797

9898
@Test

0 commit comments

Comments
 (0)