public void TestSerializeDemographic() { Demographic demographic = new Demographic(20, Categories.Food, 10, 8, 1); Serializer serializer = new Serializer(); string json = serializer.Serialize(demographic); Assert.IsTrue(json.Contains("\"rank\":1")); }
/** The demographics database contains one "turn" key that contains the turn number for the saved demographics and the rest of the keys are in the "[category]-[property]" format (e.g. "food-average", "production-rank", "literacy-value") */ protected override void ParseDatabaseEntries(Dictionary<string, string> pairs) { int turn = 0; if (pairs.ContainsKey("turn")) turn = int.Parse(pairs["turn"]); List<string> categories = new List<string>(); foreach (string key in pairs.Keys) { if (key == "turn") continue; string category = key.Split('-')[0]; if (!categories.Contains(category)) categories.Add(category); } foreach (string category in categories) { Categories cat; Enum.TryParse(category, true, out cat); float val = float.Parse(pairs[category + "-value"]); float ave = float.Parse(pairs[category + "-average"]); int rank = int.Parse(pairs[category + "-rank"]); demographics[category] = new Demographic(turn, cat, val, ave, rank); } }