Ejemplo n.º 1
0
        public void GetHashCode_SameHashCodeIsReturnedEveryTimeTheMethodIsCalled_AsLongAsTheObjectDoesNotChange()
        {
            // Arrange
            var processorUtilizationInPercent = 50.0d;
            var object1 = new ProcessorUtilizationInformation {
                ProcessorUtilizationInPercent = processorUtilizationInPercent
            };

            int expectedHashcode = object1.GetHashCode();

            for (var i = 0; i < 100; i++)
            {
                // Act
                object1.ProcessorUtilizationInPercent = processorUtilizationInPercent;
                int generatedHashCode = object1.GetHashCode();

                // Assert
                Assert.AreEqual(expectedHashcode, generatedHashCode);
            }
        }
Ejemplo n.º 2
0
        public void GetHashCode_TwoIdenticalObjects_BothUninitialized_HashCodesAreEqual()
        {
            // Arrange
            var package1 = new ProcessorUtilizationInformation();
            var package2 = new ProcessorUtilizationInformation();

            // Act
            int hashCodeObject1 = package1.GetHashCode();
            int hashCodeObject2 = package2.GetHashCode();

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
Ejemplo n.º 3
0
        public void GetHashCode_TwoDistinctObjects_HashCodesAreDifferent()
        {
            // Arrange
            var object1 = new ProcessorUtilizationInformation {
                ProcessorUtilizationInPercent = 90.0d
            };
            var object2 = new ProcessorUtilizationInformation {
                ProcessorUtilizationInPercent = 10.0d
            };

            // Act
            int hashCodeObject1 = object1.GetHashCode();
            int hashCodeObject2 = object2.GetHashCode();

            // Assert
            Assert.AreNotEqual(hashCodeObject1, hashCodeObject2);
        }
Ejemplo n.º 4
0
        public void GetHashCode_TwoIdenticalObjects_BothInitialized_HashCodesAreEqual()
        {
            // Arrange
            var object1 = new ProcessorUtilizationInformation {
                ProcessorUtilizationInPercent = 50.0d
            };
            var object2 = new ProcessorUtilizationInformation {
                ProcessorUtilizationInPercent = 50.0d
            };

            // Act
            int hashCodeObject1 = object1.GetHashCode();
            int hashCodeObject2 = object2.GetHashCode();

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
Ejemplo n.º 5
0
        public void GetHashCode_ForAllUniqueObject_AUniqueHashCodeIsReturned()
        {
            var hashCodes = new Dictionary <int, ProcessorUtilizationInformation>();

            for (var i = 0; i < 100; i++)
            {
                // Act
                var object1 = new ProcessorUtilizationInformation {
                    ProcessorUtilizationInPercent = i
                };

                int generatedHashCode = object1.GetHashCode();

                // Assert
                Assert.IsFalse(hashCodes.ContainsKey(generatedHashCode));
                hashCodes.Add(generatedHashCode, object1);
            }
        }