public void HabitatTest() { // Initialize a habitat int[] habitatTypeCounters = new int[13]; habitatTypeCounters[3] = 11; habitatTypeCounters[8] = 5; habitatTypeCounters[4] = 3; habitatTypeCounters[2] = 1; Habitat testHabitat = new Habitat(habitatTypeCounters, 0f); // Test the public variables and the initializer methods indirectly Assert.AreEqual(testHabitat.dominantType, "boreal"); Assert.AreEqual(testHabitat.typePercents[2], .05); Assert.AreEqual(testHabitat.typePercents[3], .55); Assert.AreEqual(testHabitat.typePercents[4], .15); Assert.AreEqual(testHabitat.typePercents[8], .25); // Test the public static methods Assert.AreEqual(Habitat.DetermineTemp(5, 60), "artic"); Assert.AreEqual(Habitat.DetermineTemp(25, 60), "temperate"); Assert.AreEqual(Habitat.DetermineTemp(5, 33), "temperate"); Assert.AreEqual(Habitat.DetermineTemp(50, 60), "temperate"); Assert.AreEqual(Habitat.DetermineTemp(50, 8), "tropical"); Assert.AreEqual(Habitat.DetermineWetness(15), "dry"); Assert.AreEqual(Habitat.DetermineWetness(28), "moderate"); Assert.AreEqual(Habitat.DetermineWetness(46), "wet"); Assert.AreEqual(Habitat.DetermineWetness(70), "very wet"); Assert.AreEqual(Habitat.DetermineHabitatFavored("moderate", "artic"), 2); Assert.AreEqual(Habitat.DetermineHabitatFavored("moderate", "tropical"), 10); Assert.AreEqual(Habitat.DetermineHabitatFavored("dry", "artic"), 1); Assert.AreEqual(Habitat.DetermineHabitatFavored("wet", "artic"), 3); Assert.AreEqual(Habitat.DetermineHabitatFavored("wet", "temperate"), 7); Assert.AreEqual(Habitat.DetermineHabitatFavored("very wet", "temperate"), 8); Assert.AreEqual(Habitat.DetermineHabitatFavored("very wet", "tropical"), 12); // Test the toString method string expected = "Habitats: " + "\n" + "5% tundra" + "\n" + "55% boreal" + "\n" + "15% artic marsh" + "\n" + "25% swamp"; Assert.AreEqual(expected, testHabitat.ToString()); // Test the Update Habitat Method System.Random randy = new System.Random(); testHabitat.UpdateHabitatYear(50, 9, 32.4f, 2.4f, false, randy); Debug.Log(testHabitat); Assert.AreEqual(.01, testHabitat.typePercents[10]); }
// Create the habitat initialization counters private int[, ][] CreateInitHabCounters() { int[, ][] habitatTypeCounters = new int[WorldX, WorldZ][]; int index; string wetness; string temperateness; // Do this for twenty years for (int year = 0; year < 20; year++) { // Generate a new year TempAndRainNewYear(); // Create arrays with the relevant data for calcluating the habitats for (int x = 0; x < WorldX; x++) { for (int z = 0; z < WorldZ; z++) { // If the tile is 100% ocean initialize habitat counters to an empty array if (oceanPer.worldArray[x, z] != 1f) { // initialize the habitattype counter with an empty array the first time round if (year == 0) { habitatTypeCounters[x, z] = new int[13]; } // Get the index of the expected habitat for each tile that year wetness = Habitat.DetermineWetness(rainfallTotal.worldArray[x, z] + River.AverageRiverLevel(x, z)); temperateness = Habitat.DetermineTemp(temps[x, z].Count70DegreeDays(), temps[x, z].Count32DegreeDays()); index = Habitat.DetermineHabitatFavored(wetness, temperateness); // Add a counter for that habitat to that tiles counter array habitatTypeCounters[x, z][index] += 1; } else { if (year == 0) { habitatTypeCounters[x, z] = new int[13]; } } } } } return(habitatTypeCounters); }