コード例 #1
0
        public void AddPhone_WorksWithDuplicatedNumbersInList()
        {
            Phonebook book = new Phonebook();

            List<string> phones = new List<string>();
            phones.Add("+359222111");
            phones.Add("+3593484374");
            phones.Add("+359222111");

            book.AddPhone("John", phones);

            int phonesCount = book.NamesDictionary["john"].PhoneNumbers.Count;

            Assert.AreEqual(2, phonesCount);
        }
コード例 #2
0
        public void AddPhone_WorksWithDuplicatedNewNumber()
        {
            Phonebook book = new Phonebook();

            List<string> phones = new List<string>();
            phones.Add("+359222111");
            phones.Add("+3593484374");
            phones.Add("+35992738278");

            book.AddPhone("John", phones);

            phones.Clear();

            phones.Add("+359222111");

            book.AddPhone("John", phones);

            int phonesCount = book.NamesDictionary["john"].PhoneNumbers.Count;

            bool exists = book.AddPhone("JoHn", phones);

            Assert.AreEqual(true, exists);
            Assert.AreEqual(3, phonesCount);
        }
コード例 #3
0
        public void ChangePhone_OldBeingReplacedWithExisting()
        {
            Phonebook book = new Phonebook();

            List<string> phones = new List<string>();
            phones.Add("+3592221431");
            phones.Add("+3593484374");
            phones.Add("+3598438748");

            book.AddPhone("John", phones);

            int oldPhonesCount = book.NamesDictionary["john"].PhoneNumbers.Count;

            book.ChangePhone("+3592221431", "+3593484374");

            int newPhonesCount = book.NamesDictionary["john"].PhoneNumbers.Count;

            Assert.AreEqual(3, oldPhonesCount);
            Assert.AreEqual(2, newPhonesCount); // instead of 3 with 2 being duplicated (+3593484374)
        }
コード例 #4
0
        public void ChangePhone_WorksOnMultipleChanges()
        {
            Phonebook book = new Phonebook();

            List<string> phones = new List<string>();

            phones.Add("+35988199283");
            phones.Add("+359848374");
            phones.Add("+3599033874");

            book.AddPhone("Test", phones);

            int changes = book.ChangePhone("+359848374", "+4839474387");
            Assert.AreEqual(1, changes);

            changes = book.ChangePhone("+4839474387", "+359848374");
            Assert.AreEqual(1, changes);
        }
コード例 #5
0
        public void ChangePhone_WorksOnEqualOldAndNewNumbers()
        {
            Phonebook book = new Phonebook();

            List<string> phones = new List<string>();
            phones.Add("+3592221431");
            phones.Add("+3593484374");
            phones.Add("+3598438748");

            book.AddPhone("John", phones);

            int phonesChanged = book.ChangePhone("+359222111", "+359222111");

            Assert.AreEqual(0, phonesChanged);
        }
コード例 #6
0
        public void ListEntries_WorksOnCountLessThanActualAndIsSorted()
        {
            Phonebook book = new Phonebook();

            List<string> phones = new List<string>();
            phones.Add("+3592221431");
            phones.Add("+3593484374");
            phones.Add("+3598438748");

            book.AddPhone("John", phones);

            List<string> davePhones = new List<string>();

            davePhones.Add("+3593484374"); // equal to John's second
            davePhones.Add("+35932378439");
            davePhones.Add("+3590034884");

            List<string> adamPhones = new List<string>();

            adamPhones.Add("+3593484374"); // equal to John's second
            adamPhones.Add("+35932378439");
            adamPhones.Add("+3590034884");

            book.AddPhone("Adam", davePhones);

            PhonebookEntry[] entries = book.ListEntries(0, 1);

            string name = entries[0].Name;
            int count = entries.Length;

            Assert.AreEqual(1, count);
            Assert.AreEqual("Adam", name);
        }
コード例 #7
0
        public void ListEntries_WorksOnCountEqualToCurrentPhonebookCount()
        {
            Phonebook book = new Phonebook();

            List<string> phones = new List<string>();
            phones.Add("+3592221431");
            phones.Add("+3593484374");
            phones.Add("+3598438748");

            book.AddPhone("John", phones);

            List<string> davePhones = new List<string>();

            davePhones.Add("+3593484374"); // equal to John's second
            davePhones.Add("+35932378439");
            davePhones.Add("+3590034884");

            book.AddPhone("Dave", davePhones);

            int entriesCount = book.ListEntries(0, 2).Length;

            Assert.AreEqual(2, entriesCount);
        }
コード例 #8
0
        public void ListEntries_ThrowsExceptionOnCountBiggerThanActual()
        {
            Phonebook book = new Phonebook();

            List<string> phones = new List<string>();
            phones.Add("+3592221431");
            phones.Add("+3593484374");
            phones.Add("+3598438748");

            book.AddPhone("John", phones);

            List<string> davePhones = new List<string>();

            davePhones.Add("+3593484374"); // equal to John's second
            davePhones.Add("+35932378439");
            davePhones.Add("+3590034884");

            book.AddPhone("Dave", davePhones);

            int entriesCount = book.ListEntries(0, 10).Length;
        }