public bool AreConnected(Panda panda1, Panda panda2) { if (ConnectionLevel(panda1, panda2) > 0) { return true; } return false; }
public bool AreFriends(Panda panda1, Panda panda2) { if (container[panda1].Contains(panda2)) { return true; } return false; }
public bool HasPanda(Panda panda) { if(container.ContainsKey(panda)) { return true; } return false; }
public void GetHashCodeTest() { Panda a = new Panda("Gosho", "*****@*****.**", GenderType.Male); Panda b = new Panda("Penka", "*****@*****.**", GenderType.Female); if (a.GetHashCode() == b.GetHashCode()) { Assert.Fail(); } }
public void GetDifferentHashCodeTest() { Panda a = new Panda("Gosho", "*****@*****.**", GenderType.Male); Panda b = new Panda("Gosho", "*****@*****.**", GenderType.Male); if (a.GetHashCode() != b.GetHashCode()) { Assert.Fail(); } }
public void AddPandaTest() { PandaSocialNetwork b = new PandaSocialNetwork(); //Panda, List<Panda>>();<Panda, List<Panda>> testcontainer = new Dictionary<Panda, List<Panda>>(); Panda a = new Panda("Gosho", "*****@*****.**", GenderType.Male); b.AddPanda(a); Assert.IsTrue((b.HasPanda(a))); }
public override bool Equals(object obj) { Panda p = obj as Panda; if (p == null) { return(false); } return((this.Name == p.Name && this.Email == p.Email && this.Gender == p.Gender) ? true : false); }
public int ConnectionLevel(Panda panda1, Panda panda2) { if (AreFriends(panda1, panda2)) { return 1; } else { return FindConnectionLevel(panda1, panda2); } }
public List<Panda> FriendsOf(Panda panda) { if (!container.ContainsKey(panda)) { return null; } else { return container[panda]; } }
public void AddPanda(Panda panda) { if (container.ContainsKey(panda)) { throw new PandaAlreadyThereException(); } else { container.Add(panda, new List<Panda>()); } }
public void ToStringTest() { Panda a = new Panda("Gosho", "*****@*****.**", GenderType.Male); Panda b = new Panda("Penka", "*****@*****.**",GenderType.Female); var result = a.ToString(); //"Panda name: " + Name + ", email:" + Email + "gender: " + Gender.ToString() if (result != "Panda name: Gosho, email: [email protected] gender: Male") // && b.ToString() != "Panda name: Penka, email: [email protected] gender: Female") { Assert.Fail(); } }
public void CompareToTest() { Panda a = new Panda("Gosho", "*****@*****.**", GenderType.Male); Panda b = new Panda("Penka", "*****@*****.**", GenderType.Female); Panda c = new Panda("Gosho", "*****@*****.**", GenderType.Male); if (c.CompareTo(a) != 0) { Assert.Fail(); } if (c.CompareTo(b) != -1) { Assert.Fail(); } }
public void MakeFriends(Panda panda1, Panda panda2) { if(!HasPanda(panda1)) { AddPanda(panda1); } if(!HasPanda(panda2)) { AddPanda(panda2); } if(container[panda1].Contains(panda2)) { throw new PandasAlreadyFriendsException(); } else { container[panda1].Add(panda2); container[panda2].Add(panda1); } }
static void Main(string[] args) { Panda panda1 = new Panda("Pesho", "*****@*****.**", GenderType.Male); Panda panda2 = new Panda("Mariika", "*****@*****.**", GenderType.Female); Panda panda3 = new Panda("Stoyanka", "*****@*****.**", GenderType.Female); Panda panda4 = new Panda("Ivancho", "*****@*****.**", GenderType.Male); PandaSocialNetwork a = new PandaSocialNetwork(); a.MakeFriends(panda1, panda2); a.MakeFriends(panda1, panda3); a.MakeFriends(panda2, panda3); a.MakeFriends(panda3, panda4); Console.WriteLine(a.HowManyGenderInNetwork(2, panda1, GenderType.Male)); JSONPandaSerializer serializer = new JSONPandaSerializer(); serializer.Save(a); PandaSocialNetwork deserializedNetwork = serializer.Load(); //BinaryPandaSerializer binSerializer = new BinaryPandaSerializer(); //binSerializer.Save(a); //PandaSocialNetwork temp = binSerializer.Load(); }
public void EqualsTest() { Panda a = new Panda("Gosho", "*****@*****.**",GenderType.Male); Panda b = new Panda("Penka", "*****@*****.**", GenderType.Female); Panda c = new Panda("Gosho", "*****@*****.**", GenderType.Male); if (!(a.Equals(c))) { Assert.Fail(); } }
private int FindConnectionLevel(Panda startPanda, Panda endPanda) { List<Panda> visited = new List<Panda>(); Queue<PandaWithLevel> queue = new Queue<PandaWithLevel>(); visited.Add(startPanda); queue.Enqueue(new PandaWithLevel() { Panda = startPanda, Level = 0 }); while (queue.Count > 0) { PandaWithLevel temp = queue.Dequeue(); if (temp.Panda.Equals(endPanda)) { return temp.Level; } foreach (Panda panda in FriendsOf(temp.Panda)) { if (!visited.Contains(panda)) { visited.Add(panda); queue.Enqueue(new PandaWithLevel() { Panda = panda, Level = temp.Level + 1 }); } } } return -1; }
public int HowManyGenderInNetwork(int level, Panda panda, GenderType gender) { List<Panda> visited = new List<Panda>(); Queue<PandaWithLevel> queue = new Queue<PandaWithLevel>(); int counter = 0; visited.Add(panda); queue.Enqueue(new PandaWithLevel() { Panda = panda, Level = 0 }); while (queue.Count > 0) { PandaWithLevel temp = queue.Dequeue(); if ((temp.Level == level) && (temp.Panda.Gender == gender)) { counter++; } foreach (Panda p in FriendsOf(temp.Panda)) { if (!visited.Contains(p)) { visited.Add(p); queue.Enqueue(new PandaWithLevel() { Panda = p, Level = temp.Level + 1 }); } } } return counter; }