/// <summary> /// Path - path to input file. isRand checks real or nor real random. /// </summary> /// <param name="path"></param> /// <param name="isRand"></param> public Network(string path, Computer.RandomDelegate rand) { StreamReader file = new System.IO.StreamReader(path); file.ReadLine(); this.NumberOfComputers = file.Read() - 48; if (this.NumberOfComputers < 1) throw new IncorrectInputException(); this.Graph = new Graph(this.NumberOfComputers); file.ReadLine(); file.ReadLine(); this.ListOfComputers = new Computer[this.NumberOfComputers]; for (int i = 0; i < this.NumberOfComputers; ++i) { string[] temp = file.ReadLine().Split(' '); char os = temp[0][0]; int isInfect = temp[1][0] - 48; if ((os != 'w' && os != 'l' && os != 'm') || (isInfect != 0 && isInfect != 1)) throw new IncorrectInputException(); this.ListOfComputers[i] = new Computer(os, isInfect, rand); } file.ReadLine(); while (!file.EndOfStream) { string[] temp = file.ReadLine().Split(' '); if (((temp[0][0] - 48) < 0) || ((temp[1][0] - 48) < 0) || ((temp[1][0] - 48) > (this.Graph.NumberOfVertex - 1)) || ((temp[0][0] - 48) > (this.Graph.NumberOfVertex - 1))) throw new IncorrectInputException(); this.Graph.AddEdge(temp[0][0] - 48, temp[1][0] - 48); } }
public void TestInfectAndConstructor() { Computer c = new Computer('w', 0, RandNext); Assert.AreEqual(c.OperationSystem, Computer.OS.Windows); Assert.IsFalse(c.Virus); c.Infection(); c.Infection(); c.Infection(); Assert.IsTrue(c.Virus); }