Beispiel #1
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);
        }
Beispiel #2
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));
        }
Beispiel #3
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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }
Beispiel #11
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);
        }
Beispiel #12
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);
        }
Beispiel #13
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]);
        }