예제 #1
0
        public bool AreConnected(Panda panda1, Panda panda2)
        {
            if (ConnectionLevel(panda1, panda2) > 0)
            {
                return true;
            }

            return false;
        }
예제 #2
0
        public bool AreFriends(Panda panda1, Panda panda2)
        {
            if (container[panda1].Contains(panda2))
            {
                return true;
            }

            return false;
        }
예제 #3
0
        public bool HasPanda(Panda panda)
        {
            if(container.ContainsKey(panda))
            {
                return true;
            }

            return false;
        }
예제 #4
0
		public void GetHashCodeTest()
		{
			Panda a = new Panda("Gosho", "*****@*****.**", GenderType.Male);
			Panda b = new Panda("Penka", "*****@*****.**", GenderType.Female);

			if (a.GetHashCode() == b.GetHashCode())
			{
				Assert.Fail();
			}
		}
예제 #5
0
		public void GetDifferentHashCodeTest()
		{
			Panda a = new Panda("Gosho", "*****@*****.**", GenderType.Male);
			Panda b = new Panda("Gosho", "*****@*****.**", GenderType.Male);

			if (a.GetHashCode() != b.GetHashCode())
			{
				Assert.Fail();
			}
		}
예제 #6
0
		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)));
		}
예제 #7
0
        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);
        }
예제 #8
0
 public int ConnectionLevel(Panda panda1, Panda panda2)
 {
     if (AreFriends(panda1, panda2))
     {
         return 1;
     }
     else
     {
         return FindConnectionLevel(panda1, panda2);
     }
 }
예제 #9
0
 public List<Panda> FriendsOf(Panda panda)
 {
     if (!container.ContainsKey(panda))
     {
         return null;
     }
     else
     {
         return container[panda];
     }
 }
예제 #10
0
 public void AddPanda(Panda panda)
 {
     if (container.ContainsKey(panda))
     {
         throw new PandaAlreadyThereException();
     }
     else
     {
         container.Add(panda, new List<Panda>());
     }
 }
예제 #11
0
		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();
			}
		}
예제 #12
0
		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();
			}

		}
예제 #13
0
        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);
            }
        }
예제 #14
0
        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();

        }
예제 #15
0
		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();
			}
		}
예제 #16
0
        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;
        }
예제 #17
0
        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;
        }