public void NetworkSerializeAndDeserialize() { var savedNetwork = new PandaSocialNetwork(); var ivo = new Panda("Ivo", "*****@*****.**", GenderType.Male); var rado = new Panda("Rado", "*****@*****.**", GenderType.Male); var tony = new Panda("Tony", "*****@*****.**", GenderType.Female); savedNetwork.AddPanda(ivo); savedNetwork.AddPanda(rado); savedNetwork.AddPanda(tony); savedNetwork.MakeFriends(ivo, rado); savedNetwork.MakeFriends(rado, tony); var pandaSerializer = new PandaSocialNetworkBinarySerializer("unitTest.dat"); pandaSerializer.Save(savedNetwork); var loadedNetwork = pandaSerializer.Load(); Assert.IsTrue( savedNetwork.HasPanda(ivo) == loadedNetwork.HasPanda(ivo) && savedNetwork.HasPanda(rado) == loadedNetwork.HasPanda(rado) && savedNetwork.HasPanda(tony) == loadedNetwork.HasPanda(tony) && savedNetwork.HasPanda(new Panda("a", "*****@*****.**", GenderType.Male)) == loadedNetwork.HasPanda(new Panda("a", "*****@*****.**", GenderType.Male)) && savedNetwork.ConnectionLevel(ivo, rado) == loadedNetwork.ConnectionLevel(ivo, rado) && savedNetwork.ConnectionLevel(ivo, tony) == loadedNetwork.ConnectionLevel(ivo, tony) && savedNetwork.HowManyGenderInNetwork(2, ivo, GenderType.Female) == loadedNetwork.HowManyGenderInNetwork(2, ivo, GenderType.Female) ); }
public void IfThereIsPanda() { var thereIsPanda = new PandaSocialNetwork(); var panda = new Panda("Kostadin", "*****@*****.**", GenderType.Male); thereIsPanda.AddPanda(panda); thereIsPanda.AddPanda(panda); }
public void hasPandaInTheNetwork() { var panda = new Panda("Stefan", "*****@*****.**", GenderType.Male); var network = new PandaSocialNetwork(); bool hasPanda = false; network.AddPanda(panda); if (network.HasPanda(panda)) { hasPanda = true; } Assert.IsTrue(hasPanda); }
public static void Main() { Console.WriteLine("WELCOME TO THE PANDA SOCIAL NETWORK!"); PandaSocialNetwork pandaSocialNetwork = new PandaSocialNetwork(); List<string> help = new List<string>(); help.Add("<--------------!!!----------------->"); help.Add("help: display the useful commands"); help.Add("addPanda: creata a panda and add it to the social network"); help.Add("hasPanda: check if the panda is in the social network"); help.Add("makeFriends: make pandas friends "); help.Add("areFriends: check if pandas are friends"); help.Add("friendsOf: display the given panda's friends"); help.Add("connectionLevel: display the connection level between pandas"); help.Add("areConnected: check if pandas are connected"); help.Add("how many gender in network: display the number of gender pandas"); help.Add("<--------------!!!----------------->"); Console.WriteLine("Type help to begin!"); do { string input = Console.ReadLine(); string[] commands = input.Split(' '); switch (commands[0]) { case "help": Console.WriteLine(); foreach (var helpCommand in help) { Console.WriteLine(helpCommand); } Console.WriteLine(); break; case "addPanda": { Panda panda = null; if (commands[3].ToLower() == "male") { panda = new Panda(commands[1], commands[2], GenderType.Male); } else if (commands[3].ToLower() == "female") { panda = new Panda(commands[1], commands[2], GenderType.Female); } else { throw new ArgumentException("gender must be male or female"); } pandaSocialNetwork.AddPanda(panda); break; } case "hasPanda": { Panda panda = null; if (commands[3].ToLower() == "male") { panda = new Panda(commands[1], commands[2], GenderType.Male); } else if (commands[3].ToLower() == "female") { panda = new Panda(commands[1], commands[2], GenderType.Female); } else { throw new ArgumentException("gender must be male or female"); } Console.WriteLine(pandaSocialNetwork.HasPanda(panda)); break; } default: Console.WriteLine("ERROR: Invalid command!"); break; } } while (true); }