Skip to content

Commit

Permalink
Merge pull request #93 from mcgivrer/feature/add-test-on-materials
Browse files Browse the repository at this point in the history
Feat(Material): Add Test on Material
  • Loading branch information
mcgivrer authored Nov 25, 2021
2 parents 997745d + 2df48f1 commit de9bad0
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum DefaultMaterial {
RUBBER(new Material("rubber", 0.8, 0.88, 0.98, 0.3)),
GLASS(new Material("glass", 0.4, 1, 1, 1)),
ICE(new Material("ice", 0.1, 0.1, 1, 1)),
AIR(new Material("air", 1, 1, 1, 1)),
AIR(new Material("air", 1, 1, 1, 0.01)),
STATIC(new Material("static", 0, 0, 0, 0)),
NEUTRAL(new Material("neutral", 1, 1, 1, 1));

Expand All @@ -43,7 +43,7 @@ public static Material newMaterial(

public static final Map<String, Material> materials = new HashMap<>();

private final String name;
public String name;

public double bounciness;
public double dynFriction;
Expand Down
13 changes: 10 additions & 3 deletions src/test/java/features/GameDefSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,13 @@ public void theTextObjectDefaultFontForIsNull(String name) {
assertNull("The default TextObject font is not null", to.font);
}

@And("the Entity {string} as {string} Material")
public void theEntityAsMaterial(String entityName, String materialTypeName) {
@And("I set Material {string} to the GameObject {string}")
public void theEntityAsMaterial(String materialTypeName, String entityName) {
Scene scene = getCurrentScene();
GameObject e = scene.getGameObject(entityName);
// TODO parse materialTypeName to use the right DefaultMaterial.
e.material = Material.DefaultMaterial.WOOD.getMaterial();
Material mat = Material.DefaultMaterial.valueOf(materialTypeName).getMaterial();
e.material = mat;
}

@Given("the Game is instantiated with config {string}")
Expand All @@ -235,4 +236,10 @@ public void theGameIsInstantiatedWithConfig(String configFileName) {
}


@Then("the GameObject {string} has Material {string}")
public void theGameObjectHasMaterial(String entityName, String materialTypeName) {
Scene scene = getCurrentScene();
GameObject e = scene.getGameObject(entityName);
assertEquals("Material has not been set with the right material", materialTypeName, e.material.name);
}
}
36 changes: 36 additions & 0 deletions src/test/java/features/MaterialStepdefs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package features;

import fr.snapgames.fromclasstogame.core.physic.Material;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;

import static org.junit.Assert.assertEquals;

public class MaterialStepdefs {
Material mat;

@Given("A Material of type {string}")
public void aMaterialOfType(String materialTypeName) {
mat = Material.DefaultMaterial.valueOf(materialTypeName).getMaterial();
}

@And("the Material has a bounciness of {double}")
public void theMaterialHasABouncinessOf(Double bouncinessValue) {
assertEquals("Bounciness for material has not the right value", bouncinessValue, mat.bounciness, 0.0);
}

@And("the Material has a density of {double}")
public void theMaterialHasADensityOf(Double densityValue) {
assertEquals("Density for material has not the right value", densityValue, mat.density, 0.0);
}

@And("the Material has a dynamic friction of {double}")
public void theMaterialHasADynFrictionOf(Double dynFrictionValue) {
assertEquals("Dynamic Friction for material has not the right value", dynFrictionValue, mat.dynFriction, 0.0);
}

@And("the Material has a static friction of {double}")
public void theMaterialHasAStaticFrictionOf(Double staFrictionValue) {
assertEquals("Static Friction for material has not the right value", staFrictionValue, mat.staticFriction, 0.0);
}
}
75 changes: 75 additions & 0 deletions src/test/resources/features/GameObject_can_have_Material.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Feature: Any GamesObject can have some material assigned

In the Game process to animate GameObject, PhysicEngine needs physic data. Those data are coming from the
Material Object. Any GameObject can have an assigned Material.

Scenario: 01 - The Entity has material
Given the Game is instantiated
And the Game is running
And I activate the scene "test1"
And I add a GameObject named "player" at (160.0,100.0)
And I set Material "WOOD" to the GameObject "player"
Then the GameObject "player" has Material "wood"

Scenario: 02 - ROCK Material has some specific Physic values
Given A Material of type "ROCK"
Then the Material has a bounciness of 0.6
And the Material has a dynamic friction of 1
And the Material has a static friction of 1
And the Material has a density of 1

Scenario: 03 - WOOD Material has some specific Physic values
Given A Material of type "WOOD"
Then the Material has a bounciness of 0.1
And the Material has a dynamic friction of 0.69
And the Material has a static friction of 0.69
And the Material has a density of 0.3

Scenario: 04 - METAL Material has some specific Physic values
Given A Material of type "METAL"
Then the Material has a bounciness of 0.05
And the Material has a dynamic friction of 1
And the Material has a static friction of 1
And the Material has a density of 1.2

Scenario: 05 - RUBBER Material has some specific Physic values
Given A Material of type "RUBBER"
Then the Material has a bounciness of 0.8
And the Material has a dynamic friction of 0.88
And the Material has a static friction of 0.98
And the Material has a density of 0.3

Scenario: 06 - GLASS Material has some specific Physic values
Given A Material of type "GLASS"
Then the Material has a bounciness of 0.4
And the Material has a dynamic friction of 1
And the Material has a static friction of 1
And the Material has a density of 1

Scenario: 07 - ICE Material has some specific Physic values
Given A Material of type "ICE"
Then the Material has a bounciness of 0.1
And the Material has a dynamic friction of 0.1
And the Material has a static friction of 1
And the Material has a density of 1

Scenario: 08 - AIR Material has some specific Physic values
Given A Material of type "AIR"
Then the Material has a bounciness of 1
And the Material has a dynamic friction of 1
And the Material has a static friction of 1
And the Material has a density of 0.01

Scenario: 09 - STATIC Material has some specific Physic values
Given A Material of type "STATIC"
Then the Material has a bounciness of 0
And the Material has a dynamic friction of 0
And the Material has a static friction of 0
And the Material has a density of 0

Scenario: 10 - NEUTRAL Material has some specific Physic values
Given A Material of type "NEUTRAL"
Then the Material has a bounciness of 1
And the Material has a dynamic friction of 1
And the Material has a static friction of 1
And the Material has a density of 1
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ Feature: The game has scene with different types of GameObject.
And I activate the scene "test1"
And I add a TextObject named "score" at (10.0,10.0)
Then the TextObject default font for "score" is null

0 comments on commit de9bad0

Please sign in to comment.