|
| 1 | +package com.jme3.effect.influencers; |
| 2 | + |
| 3 | +import com.jme3.asset.AssetManager; |
| 4 | +import com.jme3.asset.DesktopAssetManager; |
| 5 | +import com.jme3.export.binary.BinaryExporter; |
| 6 | +import com.jme3.math.Vector3f; |
| 7 | +import org.junit.Assert; |
| 8 | +import org.junit.Test; |
| 9 | + |
| 10 | +/** |
| 11 | + * Automated tests for the {@code ParticleInfluencer} class. |
| 12 | + * |
| 13 | + * @author capdevon |
| 14 | + */ |
| 15 | +public class ParticleInfluencerTest { |
| 16 | + |
| 17 | + /** |
| 18 | + * Tests cloning, serialization and de-serialization of a {@code NewtonianParticleInfluencer}. |
| 19 | + */ |
| 20 | + @Test |
| 21 | + public void testNewtonianParticleInfluencer() { |
| 22 | + AssetManager assetManager = new DesktopAssetManager(true); |
| 23 | + |
| 24 | + NewtonianParticleInfluencer inf = new NewtonianParticleInfluencer(); |
| 25 | + inf.setNormalVelocity(1); |
| 26 | + inf.setSurfaceTangentFactor(0.5f); |
| 27 | + inf.setSurfaceTangentRotation(2.5f); |
| 28 | + inf.setInitialVelocity(new Vector3f(0, 1, 0)); |
| 29 | + inf.setVelocityVariation(2f); |
| 30 | + |
| 31 | + NewtonianParticleInfluencer clone = (NewtonianParticleInfluencer) inf.clone(); |
| 32 | + assertEquals(inf, clone); |
| 33 | + Assert.assertNotSame(inf.temp, clone.temp); |
| 34 | + |
| 35 | + NewtonianParticleInfluencer copy = BinaryExporter.saveAndLoad(assetManager, inf); |
| 36 | + assertEquals(inf, copy); |
| 37 | + } |
| 38 | + |
| 39 | + private void assertEquals(NewtonianParticleInfluencer inf, NewtonianParticleInfluencer clone) { |
| 40 | + Assert.assertEquals(inf.getNormalVelocity(), clone.getNormalVelocity(), 0.001f); |
| 41 | + Assert.assertEquals(inf.getSurfaceTangentFactor(), clone.getSurfaceTangentFactor(), 0.001f); |
| 42 | + Assert.assertEquals(inf.getSurfaceTangentRotation(), clone.getSurfaceTangentRotation(), 0.001f); |
| 43 | + Assert.assertEquals(inf.getInitialVelocity(), clone.getInitialVelocity()); |
| 44 | + Assert.assertEquals(inf.getVelocityVariation(), clone.getVelocityVariation(), 0.001f); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Tests cloning, serialization and de-serialization of a {@code RadialParticleInfluencer}. |
| 49 | + */ |
| 50 | + @Test |
| 51 | + public void testRadialParticleInfluencer() { |
| 52 | + AssetManager assetManager = new DesktopAssetManager(true); |
| 53 | + |
| 54 | + RadialParticleInfluencer inf = new RadialParticleInfluencer(); |
| 55 | + inf.setHorizontal(true); |
| 56 | + inf.setOrigin(new Vector3f(0, 1, 0)); |
| 57 | + inf.setRadialVelocity(2f); |
| 58 | + inf.setInitialVelocity(new Vector3f(0, 1, 0)); |
| 59 | + inf.setVelocityVariation(2f); |
| 60 | + |
| 61 | + RadialParticleInfluencer clone = (RadialParticleInfluencer) inf.clone(); |
| 62 | + assertEquals(inf, clone); |
| 63 | + Assert.assertNotSame(inf.temp, clone.temp); |
| 64 | + Assert.assertNotSame(inf.getOrigin(), clone.getOrigin()); |
| 65 | + |
| 66 | + RadialParticleInfluencer copy = BinaryExporter.saveAndLoad(assetManager, inf); |
| 67 | + assertEquals(inf, copy); |
| 68 | + } |
| 69 | + |
| 70 | + private void assertEquals(RadialParticleInfluencer inf, RadialParticleInfluencer clone) { |
| 71 | + Assert.assertEquals(inf.isHorizontal(), clone.isHorizontal()); |
| 72 | + Assert.assertEquals(inf.getOrigin(), clone.getOrigin()); |
| 73 | + Assert.assertEquals(inf.getRadialVelocity(), clone.getRadialVelocity(), 0.001f); |
| 74 | + Assert.assertEquals(inf.getInitialVelocity(), clone.getInitialVelocity()); |
| 75 | + Assert.assertEquals(inf.getVelocityVariation(), clone.getVelocityVariation(), 0.001f); |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments