public void testColonyGasCost() { Entity testPlanet; double expected; float oRatio; Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>(); for (int i = 0; i < 40; i++) { for (int j = 0; j < 20; j++) { if (i + j > 40) // pressure too high, would fail the pressure test { continue; } AtmosphereDB testAtmosphereDB; atmoGasses.Clear(); atmoGasses.Add(_gasDictionary["N"], i * 0.1f); atmoGasses.Add(_gasDictionary["O"], j * 0.1f); testAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure? testPlanet = setAtmosphere(testAtmosphereDB); if (i + j == 0) { oRatio = 0.0f; } else { oRatio = j * 1.0f / (i + j); } if (j < 1 || j > 3) { expected = 2.0; } else if (oRatio <= 0.30f && j >= 1) { expected = 1.0; } else { expected = 2.0; } Assert.AreEqual(expected, SpeciesProcessor.ColonyCost(testPlanet, _humanSpecies.GetDataBlob <SpeciesDB>())); } } //throw (new NotImplementedException()); }
/// <summary> /// Constructor for PlanetInfoDB /// </summary> /// <param name="type">Type of planet</param> /// <param name="tectonics">Plate techtonics. Ammount of activity depends on age vs mass.</param> /// <param name="surfaceGrav">Gravity of a planet at its surface. In Earth Gravities (Gs).</param> /// <param name="density">In g/cm^3</param> /// <param name="axialTilt">in degrees.</param> /// <param name="magField">In Microtesla (uT)</param> /// <param name="baseTemp">Degrees C.</param> /// <param name="radLevel">not yet used?</param> /// <param name="atmoDust">not yet used?</param> /// <param name="atmosphere">atmosphere</param> public PlanetInfoDB(PlanetType type, TectonicActivity tectonics, float surfaceGrav, double density, float axialTilt, float magField, float baseTemp, float radLevel, float atmoDust, AtmosphereDB atmosphere) { Type = type; Tectonics = tectonics; SurfaceGravity = surfaceGrav; Density = density; AxialTilt = axialTilt; MagneticFeild = magField; BaseTemperature = baseTemp; RadiationLevel = radLevel; AtmosphericDust = atmoDust; Atmosphere = atmosphere; }
// Sets a planet entity to earth normal private Entity setEarthPlanet() { Entity resultPlanet; Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>(); atmoGasses.Add(_gasDictionary["N"], 0.79f); atmoGasses.Add(_gasDictionary["O"], 0.20f); atmoGasses.Add(_gasDictionary["Ar"], 0.01f); AtmosphereDB atmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); resultPlanet = setAtmosphere(atmosphereDB); return(resultPlanet); }
// Sets an entity to earth normal aside from the atmosphere private Entity setAtmosphere(AtmosphereDB atmosDB) { SystemBodyInfoDB earthBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true }; NameDB earthNameDB = new NameDB("Earth"); earthBodyDB.Gravity = 1.0; earthBodyDB.BaseTemperature = 20.0f; Entity resultPlanet = new Entity(_entityManager, new List <BaseDataBlob> { earthBodyDB, earthNameDB, atmosDB }); return(resultPlanet); }
private void UpdateProperties([NotNull] AtmosphereDB atmosphereDB) { if (atmosphereDB == null) { throw new ArgumentNullException("atmosphereDB"); } AtmosphereInAtm = atmosphereDB.AtomsphereDescriptionAtm; AtmosphereInPercent = atmosphereDB.AtomsphereDescriptionInPercent; Pressure = atmosphereDB.Pressure; Albedo = atmosphereDB.Albedo; SurfaceTemp = atmosphereDB.SurfaceTemperature; GreenhouseFactor = atmosphereDB.GreenhouseFactor; GreenhousePressure = atmosphereDB.GreenhousePressure; Hydrosphere = atmosphereDB.Hydrosphere; HydrosphereExtent = atmosphereDB.HydrosphereExtent; }
public void testColonyPressureCost() { Entity testPlanet; double idealPressure; double maxPressure; double expected; float totalPressure; idealPressure = _humanSpecies.GetDataBlob <SpeciesDB>().BasePressure; maxPressure = _humanSpecies.GetDataBlob <SpeciesDB>().MaximumPressureConstraint; Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>(); for (float i = 0.3f; i < 10.0; i += 0.1f) { AtmosphereDB testAtmosphereDB; atmoGasses.Clear(); // Keep atmosphere breathable atmoGasses.Add(_gasDictionary["N"], (float)(2.0f * i)); totalPressure = 2.0f * i; atmoGasses.Add(_gasDictionary["O"], 0.1f); totalPressure += 0.1f; testAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure? testPlanet = setAtmosphere(testAtmosphereDB); if (totalPressure > 4.0) { expected = 2.0; } else { expected = 1.0; } Assert.AreEqual(expected, SpeciesProcessor.ColonyCost(testPlanet, _humanSpecies.GetDataBlob <SpeciesDB>())); } // Check with pressure from just one gas and multiple gases //throw (new NotImplementedException()); Assert.AreEqual(1.0, SpeciesProcessor.ColonyCost(_earthPlanet, _humanSpecies.GetDataBlob <SpeciesDB>())); }
public void GetDataBlobByEntity() { Entity testEntity = PopulateEntityManager(); // Get the Population DB of a specific entity. ColonyInfoDB popDB = testEntity.GetDataBlob <ColonyInfoDB>(); Assert.IsNotNull(popDB); // get a DB we know the entity does not have: AtmosphereDB atmoDB = testEntity.GetDataBlob <AtmosphereDB>(); Assert.IsNull(atmoDB); // test with invalid data blob type Assert.Catch(typeof(KeyNotFoundException), () => { testEntity.GetDataBlob <BaseDataBlob>(); }); // and again for the second lookup type: // Get the Population DB of a specific entity. int typeIndex = EntityManager.GetTypeIndex <ColonyInfoDB>(); popDB = testEntity.GetDataBlob <ColonyInfoDB>(typeIndex); Assert.IsNotNull(popDB); // get a DB we know the entity does not have: typeIndex = EntityManager.GetTypeIndex <AtmosphereDB>(); atmoDB = testEntity.GetDataBlob <AtmosphereDB>(typeIndex); Assert.IsNull(atmoDB); // test with invalid type index: Assert.Catch(typeof(ArgumentOutOfRangeException), () => { testEntity.GetDataBlob <AtmosphereDB>(-42); }); // test with invalid T vs type at typeIndex typeIndex = EntityManager.GetTypeIndex <ColonyInfoDB>(); Assert.Catch(typeof(InvalidCastException), () => { testEntity.GetDataBlob <SystemBodyInfoDB>(typeIndex); }); }
// Sets a planet entity to earth normal private Entity setEarthPlanet() { Entity resultPlanet; Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>(); atmoGasses.Add(_gasDictionary["N"], 0.79f); atmoGasses.Add(_gasDictionary["O"], 0.20f); atmoGasses.Add(_gasDictionary["Ar"], 0.01f); AtmosphereDB atmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 57.2f, atmoGasses); resultPlanet = setAtmosphere(atmosphereDB); resultPlanet.GetDataBlob <SystemBodyInfoDB>().BaseTemperature = 14.0f; resultPlanet.GetDataBlob <SystemBodyInfoDB>().Gravity = 1.0; return(resultPlanet); }
public void testColonyToxicityCost() { SystemBodyInfoDB earthBodyDB = new SystemBodyInfoDB { BodyType = BodyType.Terrestrial, SupportsPopulations = true }; NameDB earthNameDB = new NameDB("Earth"); double expectedCost; string gasSym; Dictionary <string, AtmosphericGasSD> lowToxicGases, highToxicGases, benignGases; AtmosphericGasSD oxygenGas; lowToxicGases = new Dictionary <string, AtmosphericGasSD>(); highToxicGases = new Dictionary <string, AtmosphericGasSD>(); benignGases = new Dictionary <string, AtmosphericGasSD>(); oxygenGas = new AtmosphericGasSD(); //Separate all the gases into the lists above foreach (KeyValuePair <string, AtmosphericGasSD> kvp in _gasDictionary) { gasSym = kvp.Key; if (gasSym == "H2" || gasSym == "CH4" || gasSym == "NH3" || gasSym == "CO" || gasSym == "NO" || gasSym == "H2S" || gasSym == "NO2" || gasSym == "SO2") { lowToxicGases.Add(gasSym, kvp.Value); } else if (gasSym == "Cl2" || gasSym == "F2" || gasSym == "Br2" || gasSym == "I2") { highToxicGases.Add(gasSym, kvp.Value); } else if (gasSym == "O") { oxygenGas = kvp.Value; } else { benignGases.Add(gasSym, kvp.Value); } } // @todo: set up two nested loops - one for list of species, one for list of gases // test a large number of different inputs AtmosphereDB weirdAtmosphereDB; Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>(); // Test the "low" toxic gases (colony cost 2.0 minimum foreach (KeyValuePair <string, AtmosphericGasSD> kvp in lowToxicGases) { expectedCost = 2.0; gasSym = kvp.Key; atmoGasses.Clear(); atmoGasses.Add(_gasDictionary[gasSym], 0.1f); weirdAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure? _weirdatmosPlanet = setAtmosphere(weirdAtmosphereDB); Assert.AreEqual(expectedCost, SpeciesProcessor.ColonyCost(_weirdatmosPlanet, _humanSpecies.GetDataBlob <SpeciesDB>())); } // Test the "high" toxic gases (colony cost 3.0 minimum) foreach (KeyValuePair <string, AtmosphericGasSD> kvp in highToxicGases) { expectedCost = 3.0; gasSym = kvp.Key; atmoGasses.Clear(); atmoGasses.Add(_gasDictionary[gasSym], 0.1f); weirdAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure? _weirdatmosPlanet = setAtmosphere(weirdAtmosphereDB); Assert.AreEqual(expectedCost, SpeciesProcessor.ColonyCost(_weirdatmosPlanet, _humanSpecies.GetDataBlob <SpeciesDB>())); } // Test the "benign" toxic gases (no affect on colony cost, but no oxygen means 2.0) foreach (KeyValuePair <string, AtmosphericGasSD> kvp in lowToxicGases) { expectedCost = 2.0; gasSym = kvp.Key; atmoGasses.Clear(); atmoGasses.Add(_gasDictionary[gasSym], 0.1f); weirdAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure? _weirdatmosPlanet = setAtmosphere(weirdAtmosphereDB); Assert.AreEqual(expectedCost, SpeciesProcessor.ColonyCost(_weirdatmosPlanet, _humanSpecies.GetDataBlob <SpeciesDB>())); } // test with atmposheres composed of two toxic gases that have the same colony cost foreach (KeyValuePair <string, AtmosphericGasSD> kvp1 in lowToxicGases) { foreach (KeyValuePair <string, AtmosphericGasSD> kvp2 in lowToxicGases) { expectedCost = 2.0; string gasSym1 = kvp1.Key; string gasSym2 = kvp2.Key; if (gasSym1 == gasSym2) { continue; } atmoGasses.Clear(); atmoGasses.Add(lowToxicGases[gasSym1], 0.1f); atmoGasses.Add(lowToxicGases[gasSym2], 0.1f); weirdAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure? _weirdatmosPlanet = setAtmosphere(weirdAtmosphereDB); Assert.AreEqual(expectedCost, SpeciesProcessor.ColonyCost(_weirdatmosPlanet, _humanSpecies.GetDataBlob <SpeciesDB>())); } } // test with atmposheres composed of two toxic gases that have the same colony cost foreach (KeyValuePair <string, AtmosphericGasSD> kvp1 in highToxicGases) { foreach (KeyValuePair <string, AtmosphericGasSD> kvp2 in highToxicGases) { expectedCost = 3.0; string gasSym1 = kvp1.Key; string gasSym2 = kvp2.Key; if (gasSym1 == gasSym2) { continue; } atmoGasses.Clear(); atmoGasses.Add(highToxicGases[gasSym1], 0.1f); atmoGasses.Add(highToxicGases[gasSym2], 0.1f); weirdAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure? _weirdatmosPlanet = setAtmosphere(weirdAtmosphereDB); Assert.AreEqual(expectedCost, SpeciesProcessor.ColonyCost(_weirdatmosPlanet, _humanSpecies.GetDataBlob <SpeciesDB>())); } } // test with atmospheres composed of two toxic gases that have different colony costs foreach (KeyValuePair <string, AtmosphericGasSD> kvp1 in lowToxicGases) { foreach (KeyValuePair <string, AtmosphericGasSD> kvp2 in highToxicGases) { expectedCost = 3.0; string gasSym1 = kvp1.Key; string gasSym2 = kvp2.Key; if (gasSym1 == gasSym2) { continue; } atmoGasses.Clear(); atmoGasses.Add(lowToxicGases[gasSym1], 0.1f); atmoGasses.Add(highToxicGases[gasSym2], 0.1f); weirdAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure? _weirdatmosPlanet = setAtmosphere(weirdAtmosphereDB); Assert.AreEqual(expectedCost, SpeciesProcessor.ColonyCost(_weirdatmosPlanet, _humanSpecies.GetDataBlob <SpeciesDB>())); } } //Toxic Gasses(CC = 2): Hydrogen(H2), Methane(CH4), Ammonia(NH3), Carbon Monoxide(CO), Nitrogen Monoxide(NO), Hydrogen Sulfide(H2S), Nitrogen Dioxide(NO2), Sulfur Dioxide(SO2) //Toxic Gasses(CC = 3): Chlorine(Cl2), Florine(F2), Bromine(Br2), and Iodine(I2) //Toxic Gasses at 30% or greater of atm: Oxygen(O2) * Assert.AreEqual(1.0, SpeciesProcessor.ColonyCost(_earthPlanet, _humanSpecies.GetDataBlob <SpeciesDB>())); }
void SetIconFor(AtmosphereDB db) { short hydro = db.HydrosphereExtent; //float albedo = db.Albedo; }