예제 #1
0
        public void Set_should_throw_ArgumentException_if_key_does_not_exist()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            //Act & Assert
            Assert.Throws <ArgumentException>(() => table[1] = "1");
        }
예제 #2
0
        public void Add_should_throw_ArgumentException_if_key_exists()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");

            //Act & Assert
            Assert.Throws <ArgumentException>(() => table.Add(1, "2"));
        }
예제 #3
0
        public void Count_should_return_0_if_table_is_empty()
        {
            //Arrange
            var table         = new Structures.HashTable <int, string>();
            int expectedCount = 0;

            //Act
            var count = table.Count;

            //Assert
            Assert.AreEqual(expectedCount, count);
        }
예제 #4
0
        public void TryGet_should_return_true_if_key_exists()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");

            //Act
            var result = table.TryGet(1, out var value);

            //Assert
            Assert.True(result);
        }
예제 #5
0
        public void TryGet_should_return_null_object_if_key_does_not_exist()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");

            //Act
            var result = table.TryGet(2, out var value);

            //Assert
            Assert.Null(value);
        }
예제 #6
0
        public void Contains_should_return_false_if_key_does_not_exist()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");

            //Act
            var result = table.Contains(2);

            //Assert
            Assert.False(result);
        }
예제 #7
0
        public void Contains_should_return_true_if_key_exists()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");

            //Act
            var result = table.Contains(1);

            //Assert
            Assert.True(result);
        }
예제 #8
0
        public void TryGet_should_return_value_if_key_exists()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "2");

            //Act
            var result = table.TryGet(1, out var outValue);

            //Assert
            Assert.AreEqual("2", outValue);
        }
예제 #9
0
        public void Set_should_remove_entry_by_key_if_value_is_null()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");

            //Act
            table[1] = null;

            //Act & Assert
            Assert.False(table.Contains(1));
        }
예제 #10
0
        public void Get_should_return_value_by_index_if_key_exists()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");

            //Act
            var result = table[1];

            //Act & Assert
            Assert.AreEqual("1", result);
        }
예제 #11
0
        public void Count_should_return_count_of_items_if_table_is_not_empty()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");
            int expectedCount = 1;

            //Act
            var count = table.Count;

            //Assert
            Assert.AreEqual(expectedCount, count);
        }
예제 #12
0
        public void Set_should_replace_entry_by_key_if_value_is_not_null()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "2");
            var value         = "3";
            var expectedValue = value;

            //Act
            table[1] = value;

            //Act & Assert
            Assert.AreEqual(expectedValue, table[1]);
        }
예제 #13
0
        public void Add_should_add_item_if_key_does_not_exist()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");
            int expectedCount = 2;

            //Act
            table.Add(2, "1");
            var count = table.Count;

            //Assert
            Assert.AreEqual(expectedCount, count);
        }
예제 #14
0
        public void Clear_should_remove_all_items()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");
            var expectedCount = 0;

            //Act
            table.Clear();
            var count = table.Count;

            //Assert
            Assert.AreEqual(expectedCount, count);
        }
예제 #15
0
        public void Remove_should_decrease_count_if_success()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");
            var expectedCount = 0;

            //Act
            table.Remove(1);
            var count = table.Count;

            //Assert
            Assert.AreEqual(expectedCount, count);
        }
예제 #16
0
        public void Remove_should_remove_item_if_key_exists()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");
            var expectedCount = 0;

            //Act
            table.Remove(1);
            var count = table.Count;

            //Assert
            Assert.AreEqual(expectedCount, count);
        }
예제 #17
0
        public void Add_should_increase_count_if_success()
        {
            //Arrange
            var table = new Structures.HashTable <int, string>();

            table.Add(1, "1");
            int expectedCount = table.Count + 1;

            //Act
            table.Add(2, "1");
            var count = table.Count;

            //Assert
            Assert.AreEqual(expectedCount, count);
        }
예제 #18
0
        public void GetEnumerator_should_return_all_values()
        {
            //Arrange
            var expectedValues = new List <string>()
            {
                "2", "4", "6", "8"
            };
            var values = new List <string>();
            var table  = new Structures.HashTable <int, string>();

            table.Add(1, "2");
            table.Add(2, "4");
            table.Add(3, "6");
            table.Add(4, "8");

            //Act
            foreach (var el in table)
            {
                values.Add(el);
            }

            //Assert
            Assert.AreEqual(expectedValues, values);
        }