/// <summary> /// Reads a run from the phone list, starting at "index". Index is incremented once for each phone read. /// </summary> /// <param name="phones">List of phones to read from</param> /// <param name="index">Index to start at</param> /// <returns></returns> public static Run ReadFromPhoneList(IList <Phone> phones, ref int index) { List <Phone> matchingPhones = new(); if (index < 0 || index >= phones.Count) { throw new ArgumentOutOfRangeException(nameof(index)); } RunCategory initialCategory = phones[index].Category(); while (true) { Phone nextPhone = phones[index]; if (nextPhone.Category() != initialCategory) { break; } matchingPhones.Add(nextPhone); index++; if (index == phones.Count) { break; } } return(new Run(matchingPhones)); }
public void TestCategory(string code, RunCategory expectedCategory) { Phone phone = new Phone(code); Assert.AreEqual(expectedCategory, phone.Category()); }