<commit_before>package toadmess.explosives;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

import org.bukkit.util.config.Configuration;
import org.junit.Before;
import org.junit.Test;

public class ExplodingConfTest {
	private Configuration conf;
	
	@Before
	public void setup() {
		conf = new Configuration(null);
	}
	
	@Test
	public void testEmptyConfig() {
		checkEmptyConfigDefaults(conf, "");
	}
	
	@Test
	public void testEmptyConfig_InvalidPath() {
		checkEmptyConfigDefaults(conf, "someplace.overtherainbow");
	}
	
	private void checkEmptyConfigDefaults(final Configuration conf, final String confPath) {
		final ExplodingConf ec = new ExplodingConf(conf, confPath);
		
		// Check some defualt bounds are created
		checkBoundsAreDefault(ec);
		
		// Check the fire defaults to false even though it's not in the config.
		checkFire(ec, false, false);
		
		// Check the next radius multiplier defaults to 1.0 event though none was specified in the config
		checkRadiusMultiplier(ec, 1.0F, false);
		checkRadiusMultiplier(ec, 1.0F, false);
		
		// Check the next player damage multiplier defaults to 1.0 even though none was specified in the config
		checkPlayerDmgMultiplier(ec, 1.0F, false);
		checkPlayerDmgMultiplier(ec, 1.0F, false);
		
		// Check the next creature damage multiplier defaults to 1.0 even though none was specified in the config
		checkCreatureDmgMultiplier(ec, 1.0F, false);
		checkCreatureDmgMultiplier(ec, 1.0F, false);
	}
	
	@Test
	public void testFire_False() { testFire(false); }
	
	@Test
	public void testFire_True() { testFire(true); }
	
	private void testFire(final boolean confHasFireSetToTrue) {
		conf.setProperty("someentity." + HEMain.CONF_ENTITY_FIRE, confHasFireSetToTrue);
		checkFire(new ExplodingConf(conf, "someentity"), confHasFireSetToTrue, true);
	}
	
	@Test
	public void testRadiusMultiplierSingle() {
		conf.setProperty("someentity." + HEMain.CONF_ENTITY_RADIUSMULT, 0.23F);
		final ExplodingConf ec = new ExplodingConf(conf, "someentity");
		checkRadiusMultiplier(ec, 0.23F, true);
		checkRadiusMultiplier(ec, 0.23F, true);
		checkRadiusMultiplier(ec, 0.23F, true);
	}
	
	@Test
	public void testRadiusMultiplierMulti() {
		checkMultipliers(eMultiplierType.RADIUS);
	}

	private enum eMultiplierType { RADIUS, PLAYER_DMG, CREATURE_DMG };
	private void checkMultipliers(final eMultiplierType multiplerType) {
		final String confPrefix = "someentity";
		
		/**
		 * Set up a configuration like:
		 * 
		 * radiusMultiplier:
		 *     - {chance: 0.2, value: 2.0}
         *     - {chance: 0.7, value: 1.0}
         *     - {chance: 0.1, value: 0.0}
		 */
		final List<HashMap<String,Object>> listOMultipliers = new ArrayList<HashMap<String,Object>>();
		final HashMap<String,Object> firstMultiplier = new HashMap<String,Object>();
		final HashMap<String,Object> secondMultiplier = new HashMap<String,Object>();
		final HashMap<String,Object> thirdMultiplier = new HashMap<String,Object>();
		
		listOMultipliers.add(firstMultiplier);
		listOMultipliers.add(secondMultiplier);
		listOMultipliers.add(thirdMultiplier);
		
		firstMultiplier.put(HEMain.CONF_MULTIPLIER_CHANCE, 0.2D); 
		firstMultiplier.put(HEMain.CONF_MULTIPLIER_VALUE, 2.0D);
		
		secondMultiplier.put(HEMain.CONF_MULTIPLIER_CHANCE, 0.7D); 
		secondMultiplier.put(HEMain.CONF_MULTIPLIER_VALUE, 1.0D);
		
		thirdMultiplier.put(HEMain.CONF_MULTIPLIER_CHANCE, 0.1D); 
		thirdMultiplier.put(HEMain.CONF_MULTIPLIER_VALUE, 0.0D);
		
		conf.setProperty(confPrefix + "." + HEMain.CONF_ENTITY_RADIUSMULT, listOMultipliers);
		
		final PredicatableNumGen rng = new PredicatableNumGen(0.01D, 1.0D);
		final ExplodingConf ec = new ExplodingConf(conf, confPrefix, rng);
		
		for(int i = 0; i < 5; i++) { // Make our fake RNG Cycle round a few times
			final float expectedMultiplier;
			if(rng.peekNextDouble() <= 0.7D) {
				expectedMultiplier = 1.0F;
			} else if (rng.peekNextDouble() <= 0.9D) {
				expectedMultiplier = 2.0F;
			} else {
				expectedMultiplier = 0.0F;
			}

			switch(multiplerType) {
			case RADIUS:
				checkRadiusMultiplier(ec, expectedMultiplier, true);
				break;
			case PLAYER_DMG:
				checkPlayerDmgMultiplier(ec, expectedMultiplier, true);
				break;
			case CREATURE_DMG:
				checkCreatureDmgMultiplier(ec, expectedMultiplier, true);
				break;
			}
		}
	}
	
	@Test
	public void testPlayerDmgMultiplierSingle() {
		fail("TODO");
	}

	@Test
	public void testPlayerDmgMultiplierMulti() {
		checkMultipliers(eMultiplierType.PLAYER_DMG);
	}

	@Test
	public void testCreatureDmgMultiplierSingle() {
		fail("TODO");
	}

	@Test
	public void testCreatureDmgMultiplierMulti() {
		checkMultipliers(eMultiplierType.CREATURE_DMG);
	}
	
	private void checkRadiusMultiplier(final ExplodingConf ec, final float expectMultiplier, final boolean expectRadiusConfig) {
		assertEquals((Float) expectMultiplier, (Float) ec.getNextRadiusMultiplier());
		assertEquals(expectRadiusConfig, ec.hasRadiusConfig());
	}
	
	private void checkPlayerDmgMultiplier(final ExplodingConf ec, final float expectMultiplier, final boolean expectPlayerDmgConfig) {
		assertEquals((Float) expectMultiplier, (Float) ec.getNextRadiusMultiplier());
		assertEquals(expectPlayerDmgConfig, ec.hasPlayerDamageConfig());
	}
	
	private void checkCreatureDmgMultiplier(final ExplodingConf ec, final float expectMultiplier, final boolean expectCreatureDmgConfig) {
		assertEquals((Float) expectMultiplier, (Float) ec.getNextRadiusMultiplier());
		assertEquals(expectCreatureDmgConfig, ec.hasCreatureDamageConfig());
	}

	private void checkFire(final ExplodingConf ec, final boolean expectFire, final boolean expectFireConfig) {
		assertEquals(expectFire, ec.getFire());
		assertEquals(expectFireConfig, ec.hasFireConfig());
	}

	private void checkBoundsAreDefault(final ExplodingConf ec) {
		assertNull(ec.getActiveBounds().getMaxX());
		assertNull(ec.getActiveBounds().getMaxY());
		assertNull(ec.getActiveBounds().getMaxZ());
		assertNull(ec.getActiveBounds().getMaxX());
		assertNull(ec.getActiveBounds().getMaxY());
		assertNull(ec.getActiveBounds().getMaxZ());<commit_msg>Finished best part of unit testing of ExplodingConf<commit_after>package toadmess.explosives;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

import org.bukkit.util.config.Configuration;
import org.junit.Before;
import org.junit.Test;

public class ExplodingConfTest {
	private Configuration conf;
	
	@Before
	public void setup() {
		conf = new Configuration(null);
	}
	
	@Test
	public void testEmptyConfig() {
		checkEmptyConfigDefaults(conf, "");
	}
	
	@Test
	public void testEmptyConfig_InvalidPath() {
		checkEmptyConfigDefaults(conf, "someplace.overtherainbow");
	}
	
	private void checkEmptyConfigDefaults(final Configuration conf, final String confPath) {
		final ExplodingConf ec = new ExplodingConf(conf, confPath);
		
		// Check some defualt bounds are created
		checkBoundsAreDefault(ec);
		
		// Check the fire defaults to false even though it's not in the config.
		checkFire(ec, false, false);
		
		// Check the next radius multiplier defaults to 1.0 event though none was specified in the config
		checkRadiusMultiplier(ec, 1.0F, false);
		checkRadiusMultiplier(ec, 1.0F, false);
		
		// Check the next player damage multiplier defaults to 1.0 even though none was specified in the config
		checkPlayerDmgMultiplier(ec, 1.0F, false);
		checkPlayerDmgMultiplier(ec, 1.0F, false);
		
		// Check the next creature damage multiplier defaults to 1.0 even though none was specified in the config
		checkCreatureDmgMultiplier(ec, 1.0F, false);
		checkCreatureDmgMultiplier(ec, 1.0F, false);
	}
	
	@Test
	public void testFire_False() { testFire(false); }
	
	@Test
	public void testFire_True() { testFire(true); }
	
	private void testFire(final boolean confHasFireSetToTrue) {
		conf.setProperty("someentity." + HEMain.CONF_ENTITY_FIRE, confHasFireSetToTrue);
		checkFire(new ExplodingConf(conf, "someentity"), confHasFireSetToTrue, true);
	}
	
	@Test
	public void testRadiusMultiplierSingle() {
		conf.setProperty("someentity." + HEMain.CONF_ENTITY_RADIUSMULT, 0.23F);
		final ExplodingConf ec = new ExplodingConf(conf, "someentity");
		checkRadiusMultiplier(ec, 0.23F, true);
		checkRadiusMultiplier(ec, 0.23F, true);
		checkRadiusMultiplier(ec, 0.23F, true);
	}
	
	@Test
	public void testRadiusMultiplierMulti() {
		checkMultipliers(eMultiplierType.RADIUS);
	}

	private enum eMultiplierType { 
		RADIUS(HEMain.CONF_ENTITY_RADIUSMULT), 
		PLAYER_DMG(HEMain.CONF_ENTITY_PLAYER_DAMAGEMULT), 
		CREATURE_DMG(HEMain.CONF_ENTITY_CREATURE_DAMAGEMULT);
		private final String confKey;
		private eMultiplierType(final String confKey) { this.confKey = confKey;}
		protected String getConfKey() { return this.confKey; }
	};
	private void checkMultipliers(final eMultiplierType multiplerType) {
		final String confPrefix = "someentity";
		
		/**
		 * Set up a configuration like:
		 * 
		 * radiusMultiplier:
		 *     - {chance: 0.2, value: 2.0}
         *     - {chance: 0.7, value: 1.0}
         *     - {chance: 0.1, value: 0.0}
		 */
		final List<HashMap<String,Object>> listOMultipliers = new ArrayList<HashMap<String,Object>>();
		final HashMap<String,Object> firstMultiplier = new HashMap<String,Object>();
		final HashMap<String,Object> secondMultiplier = new HashMap<String,Object>();
		final HashMap<String,Object> thirdMultiplier = new HashMap<String,Object>();
		
		listOMultipliers.add(firstMultiplier);
		listOMultipliers.add(secondMultiplier);
		listOMultipliers.add(thirdMultiplier);
		
		firstMultiplier.put(HEMain.CONF_MULTIPLIER_CHANCE, 0.2D); 
		firstMultiplier.put(HEMain.CONF_MULTIPLIER_VALUE, 2.0D);
		
		secondMultiplier.put(HEMain.CONF_MULTIPLIER_CHANCE, 0.7D); 
		secondMultiplier.put(HEMain.CONF_MULTIPLIER_VALUE, 1.0D);
		
		thirdMultiplier.put(HEMain.CONF_MULTIPLIER_CHANCE, 0.1D); 
		thirdMultiplier.put(HEMain.CONF_MULTIPLIER_VALUE, 0.0D);
		
		conf.setProperty(confPrefix + "." + multiplerType.getConfKey(), listOMultipliers);
		
		final PredicatableNumGen rng = new PredicatableNumGen(0.01D, 1.0D);
		final ExplodingConf ec = new ExplodingConf(conf, confPrefix, rng);
		
		for(int i = 0; i < 5; i++) { // Make our fake RNG Cycle round a few times
			final float expectedMultiplier;
			if(rng.peekNextDouble() <= 0.7D) {
				expectedMultiplier = 1.0F;
			} else if (rng.peekNextDouble() <= 0.9D) {
				expectedMultiplier = 2.0F;
			} else {
				expectedMultiplier = 0.0F;
			}

			switch(multiplerType) {
			case RADIUS:
				checkRadiusMultiplier(ec, expectedMultiplier, true);
				break;
			case PLAYER_DMG:
				checkPlayerDmgMultiplier(ec, expectedMultiplier, true);
				break;
			case CREATURE_DMG:
				checkCreatureDmgMultiplier(ec, expectedMultiplier, true);
				break;
			}
		}
	}
	
	@Test
	public void testPlayerDmgMultiplierSingle() {
		conf.setProperty("someentity." + HEMain.CONF_ENTITY_PLAYER_DAMAGEMULT, 0.23F);
		final ExplodingConf ec = new ExplodingConf(conf, "someentity");
		checkPlayerDmgMultiplier(ec, 0.23F, true);
		checkPlayerDmgMultiplier(ec, 0.23F, true);
		checkPlayerDmgMultiplier(ec, 0.23F, true);
	}

	@Test
	public void testPlayerDmgMultiplierMulti() {
		checkMultipliers(eMultiplierType.PLAYER_DMG);
	}

	@Test
	public void testCreatureDmgMultiplierSingle() {
		conf.setProperty("someentity." + HEMain.CONF_ENTITY_CREATURE_DAMAGEMULT, 0.23F);
		final ExplodingConf ec = new ExplodingConf(conf, "someentity");
		checkCreatureDmgMultiplier(ec, 0.23F, true);
		checkCreatureDmgMultiplier(ec, 0.23F, true);
		checkCreatureDmgMultiplier(ec, 0.23F, true);
	}

	@Test
	public void testCreatureDmgMultiplierMulti() {
		checkMultipliers(eMultiplierType.CREATURE_DMG);
	}
	
	private void checkRadiusMultiplier(final ExplodingConf ec, final float expectMultiplier, final boolean expectRadiusConfig) {
		assertEquals((Float) expectMultiplier, (Float) ec.getNextRadiusMultiplier());
		assertEquals(expectRadiusConfig, ec.hasRadiusConfig());
	}
	
	private void checkPlayerDmgMultiplier(final ExplodingConf ec, final float expectMultiplier, final boolean expectPlayerDmgConfig) {
		assertEquals((Float) expectMultiplier, (Float) ec.getNextPlayerDamageMultiplier());
		assertEquals(expectPlayerDmgConfig, ec.hasPlayerDamageConfig());
	}
	
	private void checkCreatureDmgMultiplier(final ExplodingConf ec, final float expectMultiplier, final boolean expectCreatureDmgConfig) {
		assertEquals((Float) expectMultiplier, (Float) ec.getNextCreatureDamageMultiplier());
		assertEquals(expectCreatureDmgConfig, ec.hasCreatureDamageConfig());
	}

	private void checkFire(final ExplodingConf ec, final boolean expectFire, final boolean expectFireConfig) {
		assertEquals(expectFire, ec.getFire());
		assertEquals(expectFireConfig, ec.hasFireConfig());
	}

	private void checkBoundsAreDefault(final ExplodingConf ec) {
		assertNull(ec.getActiveBounds().getMaxX());
		assertNull(ec.getActiveBounds().getMaxY());
		assertNull(ec.getActiveBounds().getMaxZ());
		assertNull(ec.getActiveBounds().getMaxX());
		assertNull(ec.getActiveBounds().getMaxY());
		assertNull(ec.getActiveBounds().getMaxZ());
{'fraction_non_alphanumeric': 0.10565754964406145, 'fraction_numerical': 0.012439115773698014, 'mean_word_length': 5.21901211556384, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4688', 'n_tokens_mistral': 4790, 'n_tokens_neox': 4375, 'n_words': 925}