当前位置: 首页>>代码示例>>C#>>正文


C# HashSet.SetEquals方法代码示例

本文整理汇总了C#中HashSet.SetEquals方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.SetEquals方法的具体用法?C# HashSet.SetEquals怎么用?C# HashSet.SetEquals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HashSet的用法示例。


在下文中一共展示了HashSet.SetEquals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SingletonEqualitySane

        public void SingletonEqualitySane()
        {
            var a = SmallSet<string>.Create("A");
            var b = SmallSet<string>.Create(new HashSet<string> {"A"});
            var c = SmallSet<string>.Create(new[] { "A" });
            var d = new HashSet<string> {"A"};

            Assert.IsType(typeof(SmallSet<string>), a);
            Assert.IsType(typeof(SmallSet<string>), b);
            Assert.IsType(typeof(SmallSet<string>), c);
            Assert.IsNotType(typeof(SmallSet<string>), d);

            var diff = SmallSet<string>.Create("B");

            Assert.Equal(a, b);
            Assert.True(a.SetEquals(b));
            Assert.Equal(a, c);
            Assert.Equal(b, c);
            Assert.True(a.SetEquals(d));
            Assert.True(d.SetEquals(a));
            Assert.True(d.SetEquals(b));
            Assert.True(d.SetEquals(c));

            Assert.NotEqual(a, diff);
            Assert.NotEqual(b, diff);
            Assert.NotEqual(c, diff);

            Assert.False(diff.SetEquals(a));
            Assert.False(a.SetEquals(diff));
            Assert.False(diff.SetEquals(b));
            Assert.False(diff.SetEquals(c));
            Assert.False(diff.SetEquals(d));
        }
开发者ID:BietteMaxime,项目名称:OG-DotNet,代码行数:33,代码来源:SmallSetTests.cs

示例2: AddTest

        public void AddTest()
        {
            var tree = new ShieldedTree<int, object>();

            Assert.Throws<InvalidOperationException>(() =>
                tree.Add(1, new object()));
            Assert.Throws<InvalidOperationException>(() =>
                ((ICollection<KeyValuePair<int, object>>)tree).Add(
                    new KeyValuePair<int, object>(1, new object())));

            var objectA = new object();
            var objectB = new object();
            Shield.InTransaction(() => {
                tree.Add(1, objectA);
                ((ICollection<KeyValuePair<int, object>>)tree).Add(
                    new KeyValuePair<int, object>(2, objectB));
                Assert.AreEqual(2, tree.Count);
                Assert.AreEqual(objectA, tree[1]);
                Assert.AreEqual(objectB, tree[2]);
            });
            Assert.AreEqual(2, tree.Count);
            Assert.AreEqual(objectA, tree[1]);
            Assert.AreEqual(objectB, tree[2]);

            var objectA2 = new object();
            var expectedValues = new HashSet<object>(new object[] { objectA, objectA2 });
            Shield.InTransaction(() => {
                tree.Add(1, objectA2);
                Assert.AreEqual(3, tree.Count);
                Assert.IsTrue(expectedValues.SetEquals(tree.Range(1, 1).Select(kvp => kvp.Value)));
            });
            Assert.AreEqual(3, tree.Count);
            Shield.InTransaction(
                () => Assert.IsTrue(expectedValues.SetEquals(tree.Range(1, 1).Select(kvp => kvp.Value))));
        }
开发者ID:jbakic,项目名称:Shielded,代码行数:35,代码来源:TreeTests.cs

示例3: BigSetSane

        public void BigSetSane()
        {
            var values = new[] { "A", "B" };
            var a = SmallSet<string>.Create(values);
            var b = new HashSet<string>(values);
            var c = SmallSet<string>.Create(b);

            Assert.IsNotType(typeof(SmallSet<string>), a);
            Assert.IsNotType(typeof(SmallSet<string>), c);
            Assert.True(a.SetEquals(b));
            Assert.True(b.SetEquals(a));
            Assert.True(b.SetEquals(c));
        }
开发者ID:BietteMaxime,项目名称:OG-DotNet,代码行数:13,代码来源:SmallSetTests.cs

示例4: GetPrefixSuffixSetCount

        public int GetPrefixSuffixSetCount(int[] set)
        {
            int output = 0;

            var prefixesNumbersUsed = new HashSet<int>();
            var suffixNumbersUsed = new HashSet<int>();

            foreach (var rangePair in GetPrefixSuffixIndexRanges(set))
            {
                var prefixRange = rangePair.Prefix;
                var suffixRange = rangePair.Suffix;

                prefixesNumbersUsed.Add(prefixRange.Number);
                suffixNumbersUsed.Add(suffixRange.Number);

                if (prefixesNumbersUsed.SetEquals(suffixNumbersUsed))
                {
                    //No need to keep comparing values that worked already
                    prefixesNumbersUsed.Clear();
                    suffixNumbersUsed.Clear();
                    output += (prefixRange.Range * suffixRange.Range);
                }

                if (output > TOO_LARGE)
                    return TOO_LARGE;
            }

            return output;
        }
开发者ID:reifnir,项目名称:CodingProblems,代码行数:29,代码来源:PrefixSuffixSets.cs

示例5: ShuffleRange

        public void ShuffleRange()
        {
            var set = new HashSet<int>(Enumerable.Range(0, 100));
            var result = RandomHelper.ShuffleRange(100).ToArray();

            Assert.IsTrue(set.SetEquals(result));
        }
开发者ID:sakapon,项目名称:Bellona.Analysis,代码行数:7,代码来源:RandomHelperTest.cs

示例6: ScanForTestClasses

        public void ScanForTestClasses()
        {
            Assembly assembly = Assembly.GetAssembly(typeof(AssemblyTestMock1));

            HashSet<Type> expectedTestClasses = new HashSet<Type> {typeof(AssemblyTestMock1), typeof(AssemblyTestMock2)};
            AssertEx.That(expectedTestClasses.SetEquals(AssemblyScanner.GetTestClassesIn(assembly)), Is.True());
        }
开发者ID:LennartH,项目名称:JUUT,代码行数:7,代码来源:TestAssemblyScanner.cs

示例7: Main

        static void Main(string[] args)
        {
            var one = new HashSet<MailAddress> { new MailAddress("[email protected]"), new MailAddress("[email protected]hurf.com") };
            var two = new HashSet<MailAddress> { new MailAddress("[email protected]"), new MailAddress("[email protected]"), };

            var equal = one.SetEquals(two);

            var sink = Observable
                .FromEventPattern<NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>(x => oc.CollectionChanged += x, y => oc.CollectionChanged -= y)
                .Where(e => e.EventArgs.Action == NotifyCollectionChangedAction.Add);

            var window = sink.Window(10).Subscribe(x => { if(oc.Count >= 10) Send("window"); });
            var throttle = sink.Throttle(TimeSpan.FromSeconds(2)).Subscribe(x => Send("throttle"));

            unchecked
            {
                for(int i = 1; i <= 3; i++)
                    Seed(i * 1000, i.ToString());
            }

            Console.WriteLine("Press any key to exit..");
            Console.ReadKey(true);

            window.Dispose();
            throttle.Dispose();
        }
开发者ID:kylejwolff,项目名称:TestProjects,代码行数:26,代码来源:Program.cs

示例8: Add

        public bool Add(Vertex[] Edge1, Vertex[] Edge2)
        {
            PointF[] edge1 = new PointF[2];
            PointF[] edge2 = new PointF[2];

            edge1 = VertToPoint(Edge1);
            edge2 = VertToPoint(Edge2);

            HashSet<PointF> crossing = new HashSet<PointF>();
            crossing.Add(edge1[0]);
            crossing.Add(edge1[1]);
            crossing.Add(edge2[0]);
            crossing.Add(edge2[1]);

            foreach (HashSet<PointF> storedCrossing in set)
            {
                if (crossing.SetEquals(storedCrossing))
                // Crossing already exists in set, so return false and don't add
                {
                    return false;
                }
            }

            set.Add(crossing);
            return true;
        }
开发者ID:michielvh1995,项目名称:OMI,代码行数:26,代码来源:QualityTest.cs

示例9: Main

        static void Main(string[] args)
        {
            var bigCities = new HashSet<string>
            {
                "New York",
                "Manchester",
                "Sheffield",
                "Paris"
            };

            var citiesInUK = new HashSet<string>
            {
                "Sheffield",
                "Ripon",
                "Truro",
                "Manchester"
            };

            var bigCitiesArray = new string[]
            {
                "New York",
                "Manchester",
                "Sheffield",
                "Paris"
            };

            // The order in the array or the set does not matter since a set does not know the position of the values.
            bool areEqual = bigCities.SetEquals(bigCitiesArray);
            Console.WriteLine("bigcities = bigCitiesArray ? {0}", areEqual);

            bool areEqualUK = citiesInUK.SetEquals(bigCitiesArray);
            Console.WriteLine("citiesInUK = BigCitiesArray? {0}", areEqualUK);
        }
开发者ID:johanvergeer,项目名称:ps-c-sharp-collection-fundamentals,代码行数:33,代码来源:Program.cs

示例10: LookupService

		public async Task LookupService() {
			Exception lastFailure = new Exception("No reference source URLs defined");
			foreach (var url in urls) {
				string assemblyList;
				try {
					using (var http = new HttpClient(new HttpClientHandler { UseDefaultCredentials = true }))
						assemblyList = await http.GetStringAsync(url + "/assemblies.txt");
					// Format:
					// AssemblyName; ProjectIndex; DependentAssemblies
					var assemblies = new HashSet<string>(
						assemblyList.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
									.Select(s => s.Remove(s.IndexOf(';')))
					);

					// If nothing changed, don't spam the log
					if (assemblies.SetEquals(this.AvailableAssemblies) && url == this.baseUrl)
						return;
					AvailableAssemblies = assemblies;
					baseUrl = url;
					logger.Log("Using reference source from " + url + " with " + AvailableAssemblies.Count + " assemblies");
					return;
				} catch (Exception ex) {
					lastFailure = ex;
					continue;
				}
			}
			logger.Log("Errors occurred while trying all reference URLs; Ref12 will not work", lastFailure);
			AvailableAssemblies = new HashSet<string>();
		}
开发者ID:jerriclynsjohn,项目名称:Ref12,代码行数:29,代码来源:ReferenceSourceProvider.cs

示例11: GetShortTestResult

 public ShortTestResultEntity GetShortTestResult(TestCompletedEntity testCompletedEntity)
 {
     ShortTestResultEntity shortTestResult = new ShortTestResultEntity()
     {
         TestName = testCompletedEntity.Test.Name,
         DateTimeStart = testCompletedEntity.DateTimeStart,
         DateTimeFinish = testCompletedEntity.DateTimeFinish,
         User = testCompletedEntity.User
     };
     foreach (var questionEntity in testCompletedEntity.Test.Questions)
     {
         QuestionResultEntity questionResult = new QuestionResultEntity()
         {
             Text = questionEntity.Text
         };
         var answersSet = new HashSet<int>(questionEntity.Options.Where(m => m.IsAnswer).Select(m => m.Id));
         var pickedSet =
             new HashSet<int>(testCompletedEntity.Answers.Where(m => m.QuestionId == questionEntity.Id).Select(m => m.Id));
         questionResult.IsAnsweredCorrectly = answersSet.SetEquals(pickedSet);
         shortTestResult.QuestionResults.Add(questionResult);
     }
     shortTestResult.Questions = testCompletedEntity.Test.Questions.Count;
     shortTestResult.RightAnsweredQuestions = shortTestResult.QuestionResults.Count(m => m.IsAnsweredCorrectly);
     return shortTestResult;
 }
开发者ID:eugeni96,项目名称:TestingSystem,代码行数:25,代码来源:TestCompletedService.cs

示例12: GetApiDescription

        public static ApiDescription GetApiDescription(HttpConfiguration config, string controllerName, string actionName, params string[] parameterNames)
        {
            if (config == null)
            {
                config = new HttpConfiguration();
                config.Formatters.Clear();
                config.Formatters.Add(new XmlMediaTypeFormatter());
                config.Formatters.Add(new JsonMediaTypeFormatter());
                config.Routes.MapHttpRoute("Default", "{controller}");
            }
            HashSet<string> parameterSet = new HashSet<string>(parameterNames, StringComparer.OrdinalIgnoreCase);
            foreach (var apiDescription in config.Services.GetApiExplorer().ApiDescriptions)
            {
                HttpActionDescriptor actionDescriptor = apiDescription.ActionDescriptor;
                if (String.Equals(actionDescriptor.ControllerDescriptor.ControllerName, controllerName, StringComparison.OrdinalIgnoreCase) &&
                    String.Equals(actionDescriptor.ActionName, actionName, StringComparison.OrdinalIgnoreCase))
                {
                    HashSet<string> actionParameterSet = new HashSet<string>(actionDescriptor.GetParameters().Select(p => p.ParameterName), StringComparer.OrdinalIgnoreCase);
                    if (parameterSet.SetEquals(actionParameterSet))
                    {
                        return apiDescription;
                    }
                }
            }

            return null;
        }
开发者ID:huyq2002,项目名称:aspnetwebstack,代码行数:27,代码来源:ApiDescriptionHelpers.cs

示例13: Permissions_ReturnsExpectedValues

        public void Permissions_ReturnsExpectedValues()
        {
            string[] permissions = new[] { "email", "user_likes", "friends_likes" };
            FacebookAuthorizeAttribute authorizeAttribute = new FacebookAuthorizeAttribute(permissions);
            HashSet<string> permissionSet = new HashSet<string>(permissions);

            Assert.True(permissionSet.SetEquals(authorizeAttribute.Permissions));
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:8,代码来源:FacebookAuthorizeAttributeTest.cs

示例14: Test_DynamicProperty_NewDP_Pass

        public void Test_DynamicProperty_NewDP_Pass(string expression, string[] expectedResult)
        {
            var kb = TestFactory.PopulatedTestMemory();
            kb.RegistDynamicProperty((Name)"Concat", Test_Concat_Dynamic_Property);

            var results = new HashSet<Name>(kb.AskPossibleProperties((Name)expression, Name.SELF_SYMBOL, null).Select(r => r.Item1));
            var expected = new HashSet<Name>(expectedResult.Select(s => (Name) s));
            Assert.True(results.SetEquals(expected));
        }
开发者ID:GAIPS-INESC-ID,项目名称:FAtiMA-Toolkit,代码行数:9,代码来源:KBTests.cs

示例15: GetProductName

        /// <summary>
        /// Gets the product which contains exactly the given set of modules.
        /// </summary>
        /// <param name="modules">A set of modules</param>
        /// <returns>Name of the matching product, or <c>null</c></returns>
        public string GetProductName(IEnumerable<Module> modules)
        {
            var set1 = new HashSet<Module>(modules);

            return (
                from product in suite.Products 
                let set2 = new HashSet<Module>(product.Modules) 
                where set1.SetEquals(set2) 
                select product.Name).FirstOrDefault();
        }
开发者ID:zvrana,项目名称:bari,代码行数:15,代码来源:DefaultSuiteContentsAnalyzer.cs


注:本文中的HashSet.SetEquals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。