예제 #1
0
        public void TestParameterSetEquality()
        {
            LongParameterValue   value1       = new LongParameterValue(nameof(value1), 1);
            LongParameterValue   value2       = new LongParameterValue(nameof(value2), 2);
            StringParameterValue stringValue1 = new StringParameterValue(nameof(value1), "1");

            var parameterSet = new ParameterSet(new[] { value1 });

            Assert.False(parameterSet.Equals(null));

            // Verify Equals for sets with different hash codes
            var parameterSetNewHash = new ParameterSet(new IParameterValue[] { value1 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode() + 1);

            Assert.NotEqual(parameterSet.GetHashCode(), parameterSetNewHash.GetHashCode());
            Assert.False(parameterSet.Equals(parameterSetNewHash));

            // Verify Equals for sets with the same hash code, but different number of values
            var parameterSetMoreValues = new ParameterSet(new IParameterValue[] { value1, value2 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode());

            Assert.Equal(parameterSet.GetHashCode(), parameterSetMoreValues.GetHashCode());
            Assert.False(parameterSet.Equals(parameterSetMoreValues));

            // Verify Equals for sets with the same hash and item counts, but one of the items has a different name
            var parameterSetDifferentName = new ParameterSet(new IParameterValue[] { value2 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode());

            Assert.Equal(parameterSet.GetHashCode(), parameterSetDifferentName.GetHashCode());
            Assert.False(parameterSet.Equals(parameterSetDifferentName));

            // Verify Equals for sets with the same hash and item names, but one of the items has a different value
            var parameterSetDifferentValue = new ParameterSet(new IParameterValue[] { stringValue1 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode());

            Assert.Equal(parameterSet.GetHashCode(), parameterSetDifferentValue.GetHashCode());
            Assert.False(parameterSet.Equals(parameterSetDifferentValue));

            // Verify Equals for sets with the same hash and items
            var parameterSetSameHash = new ParameterSet(new IParameterValue[] { value1 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode());

            Assert.Equal(parameterSet.GetHashCode(), parameterSetSameHash.GetHashCode());
            Assert.True(parameterSet.Equals(parameterSetSameHash));
        }