Add() публичный Метод

public Add ( int value ) : CustomSet,
value int
Результат CustomSet,
Пример #1
0
        public void AddWithDuplicateTest()
        {
            // ARRANGE
            var set = new CustomSet <int>();

            // ACT
            set.Add(1);
            set.Add(1);

            // ASSERT
            Assert.AreEqual(1, set.Count);
        }
Пример #2
0
        public void Add_NormalConditions_Test()
        {
            CustomSet <string> testSet     = new CustomSet <string>();
            CustomSet <string> expectedSet = new CustomSet <string> {
                "Test", "Test2"
            };

            testSet.Add("Test");
            testSet.Add("Test");
            testSet.Add("Test2");
            CollectionAssert.AreEqual(testSet, expectedSet);
        }
Пример #3
0
    public void Adding_an_existing_element_does_not_change_the_set()
    {
        var element = 3;
        var sut     = new CustomSet(new[] { 1, 2, 3 });

        Assert.Equal(new CustomSet(new[] { 1, 2, 3 }), sut.Add(element));
    }
Пример #4
0
    public void Add_to_non_empty_set()
    {
        var element = 3;
        var sut     = new CustomSet(new[] { 1, 2, 4 });

        Assert.Equal(new CustomSet(new[] { 1, 2, 3, 4 }), sut.Add(element));
    }
        public IEnumerable <Book> Open()
        {
            CustomSet <Book> books = new CustomSet <Book>();

            try
            {
                using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
                {
                    while (reader.BaseStream.Position != reader.BaseStream.Length)
                    {
                        string title   = reader.ReadString();
                        string authors = "";
                        while (true)
                        {
                            string author = reader.ReadString();
                            if (author == "-")
                            {
                                break;
                            }
                            authors += author + "|";
                        }
                        string publisher      = reader.ReadString();
                        int    publishingYear = reader.ReadInt32();
                        Book   book           = new Book(title, publisher, publishingYear, authors.Split('|'));
                        books.Add(book);
                    }
                }
            }
            catch (Exception)
            {
                logger.Error("Exception during downloading from file");
            }
            return(books);
        }
Пример #6
0
        public void Add_ArgumentNullException_Test()
        {
            CustomSet <string> testSet = new CustomSet <string> {
                "Test", "Test3", "Test4", "Test5"
            };

            Assert.Throws <ArgumentNullException>(() => testSet.Add(null));
        }
Пример #7
0
 public void AddBook(Book newBook)
 {
     if (newBook == null)
     {
         throw new ArgumentNullException();
     }
     books.Add(newBook);
     logger.Debug(newBook + " added");
 }
Пример #8
0
        public void CustomSet_TestForAdd(List <string> expectedValue, params string[] values)
        {
            var actual = new CustomSet <string>();

            foreach (var value in values)
            {
                actual.Add(value);
            }

            Assert.AreEqual(expectedValue, new List <string>(actual));
        }
Пример #9
0
        public void RemoveTest()
        {
            // ARRANGE
            var set = new CustomSet <int>();

            set.Add(1);

            // ACT
            set.Remove(1);

            // ASSERT
            Assert.AreEqual(0, set.Count);
        }
Пример #10
0
    public CustomSet Union(CustomSet right)
    {
        if (this.values.Length == 0 && right.values.Length == 0)
        {
            return(new CustomSet());
        }
        else if (this.values.Length == 0)
        {
            return(right);
        }
        else if (right.values.Length == 0)
        {
            return(this);
        }
        CustomSet retVal = new CustomSet(this.values);

        foreach (int i in right.values)
        {
            retVal = retVal.Add(i);
        }
        return(retVal);
    }
Пример #11
0
    public CustomSet Difference(CustomSet right)
    {
        if (right.values.Length == 0)
        {
            return(new CustomSet(this.values));
        }
        if (this.values.Length == 0)
        {
            return(new CustomSet());
        }

        CustomSet tmpSet = this.Intersection(right);
        CustomSet retVal = new CustomSet();

        foreach (int i in this.values)
        {
            if (Array.IndexOf(tmpSet.values, i) == -1)
            {
                retVal = retVal.Add(i);
            }
        }
        return(retVal);
    }
Пример #12
0
        static void Main(string[] args)
        {
            try
            {
                var binarySearch = new BinarySearch();

                int[] searchExpression = { 1, 2, 3, 4, 6 };

                var resultBinarySearch = binarySearch.Find(searchExpression, 4);

                var funcFibonacci = new FuncFibonacci();

                Console.WriteLine("Fibonacci result: ");


                var result = funcFibonacci.GetSequence(-5);


                foreach (var s in funcFibonacci.GetSequence(15))
                {
                    Console.WriteLine(s);
                }

                var stack = new CustomStack <int>();
                stack.Push(4);
                stack.Push(5);

                var myStackCount = stack.Count;
                var myStackPeek  = stack.Peek();
                stack.Pop();
                stack.Push(34);

                var queue = new CustomQueue <int>();
                queue.Enqueue(2);
                queue.Enqueue(3);
                queue.Enqueue(5);
                queue.Enqueue(12);

                var myQueueCount = queue.Count;
                var peek         = queue.Peek();
                var deQueue      = queue.Dequeue();

                var set1 = new CustomSet <int>();

                set1.Add(1);
                set1.Add(2);
                set1.Add(56);

                var set2 = new CustomSet <int>();

                set2.Add(2);
                set2.Add(4);
                set2.Add(6);

                var difference = set1.Difference(set2);

                var intersection = set1.Intersection(set2);
                var union        = set1.Union(set2);

                Console.WriteLine("\nStack:");
                foreach (var s in stack)
                {
                    Console.WriteLine(s);
                }

                Console.WriteLine("\nQueue: ");
                foreach (var s in queue)
                {
                    Console.WriteLine(s);
                }

                Console.WriteLine("\nSet: ");
                foreach (var s in set1)
                {
                    Console.WriteLine(s);
                }

                Console.ReadLine();
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine(e.Message);
            }

            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine();
            }
        }
        public bool Add_PassedElement_ExpectedPositiveTests(string[] array, string element)
        {
            CustomSet <string> set = new CustomSet <string>(array);

            return(set.Add(element));
        }