/// <summary> /// Creates a random Employee array /// </summary> /// <returns>An employee array</returns> public static RWEmployee[] CreateEmployees(int numEmployees = 100) { string[] names = { "María", "Juan", "Pepe", "Luis", "Carlos", "Miguel", "Cristina" }; string[] surnames = { "Díaz", "Pérez", "Hevia", "García", "Rodríguez", "Pérez", "Sánchez" }; RWEmployee[] listing = new RWEmployee[numEmployees]; Random random = new Random(); for (int i = 0; i < numEmployees; i++) { listing[i] = new RWEmployee { Name = names[random.Next(0, names.Length)], FirstSurname = surnames[random.Next(0, surnames.Length)], SecondSurname = surnames[random.Next(0, surnames.Length)], NIF = random.Next(9000000, 90000000) + "-" + (char)random.Next('A', 'Z'), NumberOfHours = i % 2 == 0 ? ContractType.Full : ContractType.Partial, ID = i, BirthDate = RandomDate(), Comments = RAWordGenerator.GenerateRandomText() } } ; return(listing); } }
public void AddTest() { // Checking that we begin the test with empty lists. Assert.AreEqual(0, intList.Count); Assert.AreEqual(0, stringList.Count); // Testing the base case of adding one single element. intList.Add(1); Assert.AreEqual(1, intList.Count); Assert.AreEqual(true, intList.Contains(1)); Assert.AreEqual(0, intList.IndexOf(1)); // Testing the base case of adding one single element that is a variable. var t = 2; intList.Add(t); Assert.AreEqual(2, intList.Count); Assert.AreEqual(true, intList.Contains(2)); Assert.AreEqual(1, intList.IndexOf(2)); Assert.AreEqual(true, intList.Contains(t)); Assert.AreEqual(1, intList.IndexOf(t)); // Testing the base case of adding a repeated element as fas a 1 already belongs to the intList. intList.Add(1); Assert.AreEqual(3, intList.Count); Assert.AreEqual(true, intList.Contains(1)); Assert.AreEqual(0, intList.IndexOf(1)); // Same for strings but checking the nullable condition. // Testing the base case of adding one single element. stringList.Add("a"); Assert.AreEqual(1, stringList.Count); Assert.AreEqual(true, stringList.Contains("a")); Assert.AreEqual(0, stringList.IndexOf("a")); // Testing the base case of adding one single element that is a variable. var s = "b"; stringList.Add(s); Assert.AreEqual(2, stringList.Count); Assert.AreEqual(true, stringList.Contains(s)); Assert.AreEqual(1, stringList.IndexOf(s)); // Testing the base case for nullable objects of adding a null value to the list. stringList.Add(null); Assert.AreEqual(3, stringList.Count); Assert.AreEqual(true, stringList.Contains(null)); Assert.AreEqual(2, stringList.IndexOf(null)); // Testing the base case of adding a repeated element as fas a 's' already belongs to the stringList. stringList.Add(s); Assert.AreEqual(4, stringList.Count); Assert.AreEqual(true, stringList.Contains(s)); Assert.AreEqual(1, stringList.IndexOf(s)); // Testing for open lists that accept any kind of object. var objectList = new NSList <object>(); // Adding an int to a object type list. objectList.Add(1); Assert.AreEqual(1, objectList.Count); Assert.AreEqual(true, objectList.Contains(1)); Assert.AreEqual(0, objectList.IndexOf(1)); // Ading an string to an object type list that already contains an int. objectList.Add("a"); Assert.AreEqual(2, objectList.Count); Assert.AreEqual(true, objectList.Contains("a")); Assert.AreEqual(1, objectList.IndexOf("a")); // Adding a null value to an object list type. objectList.Add(null); Assert.AreEqual(3, objectList.Count); Assert.AreEqual(true, objectList.Contains(null)); Assert.AreEqual(2, objectList.IndexOf(null)); // Adding a repeated element to an object list type. Notice that the repeated element it's also null. objectList.Add(null); Assert.AreEqual(4, objectList.Count); Assert.AreEqual(true, objectList.Contains(null)); Assert.AreEqual(2, objectList.IndexOf(null)); // Clearing our list to some performance test. intList.Clear(); stringList.Clear(); // Adding some values to our lists to check that can add multiple values with no problem. for (int i = 0; i < 100000; i++) { intList.Add(i); stringList.Add(RAWordGenerator.GenerateRandomWord()); Assert.AreEqual(i + 1, intList.Count); Assert.AreEqual(i + 1, stringList.Count); } }