Пример #1
0
        protected void CheckEnums(string name, int expectedTypes, string[] expected, string[] notExpected)
        {
            C5.HashSet <string> valsToFind = new C5.HashSet <string>( );
            valsToFind.AddAll(expected);
            C5.HashSet <string> valsNotToFind = new C5.HashSet <string>( );
            valsNotToFind.AddAll(notExpected);

            AssemblyHelper.CheckAssembly(name, expectedTypes,
                                         delegate(TypeDefinition typeDef) { return(typeDef.BaseType.FullName == "System.Enum"); },
                                         delegate(TypeDefinition typeDef)
            {
                // num expected + num unexpected + field storage
                int totalValues = expected.Length + notExpected.Length + 1;
                Assert.AreEqual(totalValues, typeDef.Fields.Count,
                                String.Format("Type should have {0} values.", totalValues));

                foreach (FieldDefinition field in typeDef.Fields)
                {
                    Assert.IsFalse(valsNotToFind.Contains(field.Name), String.Format(
                                       "Did not expect to find event '{0}'.", field.Name));

                    valsToFind.Remove(field.Name);
                }

                Assert.IsFalse(valsToFind.Count > 0, "Failed to find all expected values.");
            });
        }
Пример #2
0
		public static void CheckAssembly( string name, int expectedTypes, string[] expectedMethods, string[] notExpectedMethods,
			Predicate<TypeDefinition> isType, Action<TypeDefinition> checkType )
		{
			C5.HashSet<string> methodsToFind = new C5.HashSet<string>( );
			methodsToFind.AddAll( expectedMethods );
			C5.HashSet<string> methodsNotToFind = new C5.HashSet<string>( );
			methodsNotToFind.AddAll( notExpectedMethods );

			CheckAssembly( name, expectedTypes, isType,
				delegate( TypeDefinition typeDef )
				{
					// make sure we have enough methods...
					Assert.AreEqual( expectedMethods.Length + notExpectedMethods.Length, typeDef.Methods.Count,
						"Some of the methods for the type are missing." );

					foreach ( MethodDefinition method in typeDef.Methods )
					{
						Assert.IsFalse( methodsNotToFind.Contains( method.Name ), String.Format(
							"Did not expect to find method '{0}'.", method.Name ) );

						methodsToFind.Remove( method.Name );
					}

					if ( checkType != null )
						checkType( typeDef );
				} );

			Assert.IsFalse( methodsToFind.Count > 0, "Failed to find all expected methods." );
		}
Пример #3
0
		protected void CheckEnums( string name, int expectedTypes, string[] expected, string[] notExpected )
		{
			C5.HashSet<string> valsToFind = new C5.HashSet<string>( );
			valsToFind.AddAll( expected );
			C5.HashSet<string> valsNotToFind = new C5.HashSet<string>( );
			valsNotToFind.AddAll( notExpected );

			AssemblyHelper.CheckAssembly( name, expectedTypes,
				delegate( TypeDefinition typeDef ) { return typeDef.BaseType.FullName == "System.Enum"; },
				delegate( TypeDefinition typeDef )
				{
					// num expected + num unexpected + field storage
					int totalValues = expected.Length + notExpected.Length + 1;
					Assert.AreEqual( totalValues, typeDef.Fields.Count,
						String.Format( "Type should have {0} values.", totalValues ) );

					foreach ( FieldDefinition field in typeDef.Fields )
					{
						Assert.IsFalse( valsNotToFind.Contains( field.Name ), String.Format(
							"Did not expect to find event '{0}'.", field.Name ) );

						valsToFind.Remove( field.Name );
					}

					Assert.IsFalse( valsToFind.Count > 0, "Failed to find all expected values." );
				} );
		}
Пример #4
0
        public static void CheckAssembly(string name, int expectedTypes, string[] expectedMethods, string[] notExpectedMethods,
                                         Predicate <TypeDefinition> isType, Action <TypeDefinition> checkType)
        {
            C5.HashSet <string> methodsToFind = new C5.HashSet <string>( );
            methodsToFind.AddAll(expectedMethods);
            C5.HashSet <string> methodsNotToFind = new C5.HashSet <string>( );
            methodsNotToFind.AddAll(notExpectedMethods);

            CheckAssembly(name, expectedTypes, isType,
                          delegate(TypeDefinition typeDef)
            {
                // make sure we have enough methods...
                Assert.AreEqual(expectedMethods.Length + notExpectedMethods.Length, typeDef.Methods.Count,
                                "Some of the methods for the type are missing.");

                foreach (MethodDefinition method in typeDef.Methods)
                {
                    Assert.IsFalse(methodsNotToFind.Contains(method.Name), String.Format(
                                       "Did not expect to find method '{0}'.", method.Name));

                    methodsToFind.Remove(method.Name);
                }

                if (checkType != null)
                {
                    checkType(typeDef);
                }
            });

            Assert.IsFalse(methodsToFind.Count > 0, "Failed to find all expected methods.");
        }
        public static Dictionary <Point, List <LineSegment> > IntersectionsBentleyOttmann(List <LineSegment> segments)
        {
            var hsSegments = new C5.HashSet <LineSegmentFr>();

            hsSegments.AddAll(segments.Select(s => new LineSegmentFr(
                                                  new PointFr(new Fraction(s.StartPoint.X), new Fraction(s.StartPoint.Y)),
                                                  new PointFr(new Fraction(s.EndPoint.X), new Fraction(s.EndPoint.Y)), true)).ToList());

            Dictionary <PointFr, LineFr> sweepLinesFr;
            var result = IntersectionsBentleyOttmann(hsSegments, out sweepLinesFr);

            return(result.ToDictionary(kvp => new Point(kvp.Key.X.ToDouble(), kvp.Key.Y.ToDouble()),
                                       kvp => kvp.Value.Select(s => new LineSegment(
                                                                   new Point(s.StartPoint.X.ToDouble(), s.StartPoint.Y.ToDouble()),
                                                                   new Point(s.EndPoint.X.ToDouble(), s.EndPoint.Y.ToDouble()))).ToList()));
        }
Пример #6
0
        protected void CheckProperties(string name, int expectedTypes, string[] expected, string[] notExpected)
        {
            C5.HashSet <string> propsToFind = new C5.HashSet <string> ();
            propsToFind.AddAll(expected);
            C5.HashSet <string> propsNotToFind = new C5.HashSet <string> ();
            propsNotToFind.AddAll(notExpected);

            string[] expectedMethods = new string[expected.Length * 2];
            for (int i = 0; i < expected.Length; i++)
            {
                expectedMethods [i * 2 + 0] = "get_" + expected [i];
                expectedMethods [i * 2 + 1] = "set_" + expected [i];
            }

            string[] notExpectedMethods = new string[notExpected.Length * 2];
            for (int i = 0; i < notExpected.Length; i++)
            {
                notExpectedMethods [i * 2 + 0] = "get_" + notExpected [i];
                notExpectedMethods [i * 2 + 1] = "set_" + notExpected [i];
            }

            AssemblyHelper.CheckAssembly(name, expectedTypes, expectedMethods, notExpectedMethods,
                                         delegate(TypeDefinition typeDef) {
                return(true);
            },
                                         delegate(TypeDefinition typeDef) {
                Assert.AreEqual(expected.Length, typeDef.Properties.Count,
                                expected.Length == 1 ? "Type should have 1 property (others dropped by default)." :
                                String.Format("Type should have {0} properties (others dropped by default).", expected.Length));

                foreach (PropertyDefinition prop in typeDef.Properties)
                {
                    Assert.IsFalse(propsNotToFind.Contains(prop.Name), String.Format(
                                       "Did not expect to find property '{0}'.", prop.Name));

                    propsToFind.Remove(prop.Name);
                }

                Assert.IsFalse(propsToFind.Count > 0, "Failed to find all expected properties.");
            });
        }
Пример #7
0
		protected void CheckProperties( string name, int expectedTypes, string[] expected, string[] notExpected )
		{
			C5.HashSet<string> propsToFind = new C5.HashSet<string>( );
			propsToFind.AddAll( expected );
			C5.HashSet<string> propsNotToFind = new C5.HashSet<string>( );
			propsNotToFind.AddAll( notExpected );

			string[] expectedMethods = new string[expected.Length * 2];
			for ( int i = 0; i < expected.Length; i ++ )
			{
				expectedMethods[i * 2 + 0] = "get_" + expected[i];
				expectedMethods[i * 2 + 1] = "set_" + expected[i];
			}

			string[] notExpectedMethods = new string[notExpected.Length * 2];
			for ( int i = 0; i < notExpected.Length; i ++ )
			{
				notExpectedMethods[i * 2 + 0] = "get_" + notExpected[i];
				notExpectedMethods[i * 2 + 1] = "set_" + notExpected[i];
			}

			AssemblyHelper.CheckAssembly( name, expectedTypes, expectedMethods, notExpectedMethods,
				delegate( TypeDefinition typeDef ) { return true; },
				delegate( TypeDefinition typeDef )
				{
					Assert.AreEqual( expected.Length, typeDef.Properties.Count,
						expected.Length == 1 ? "Type should have 1 property (others dropped by default)." :
						String.Format( "Type should have {0} properties (others dropped by default).", expected.Length ) );

					foreach ( PropertyDefinition prop in typeDef.Properties )
					{
						Assert.IsFalse( propsNotToFind.Contains( prop.Name ), String.Format(
							"Did not expect to find property '{0}'.", prop.Name ) );

						propsToFind.Remove( prop.Name );
					}

					Assert.IsFalse( propsToFind.Count > 0, "Failed to find all expected properties." );
				} );
		}
        public static Dictionary <Point, List <LineSegment> > IntersectionsBentleyOttmann(List <LineSegment> segments, out LineSegment[] sweepLines)
        {
            var hsSegments = new C5.HashSet <LineSegmentFr>();

            hsSegments.AddAll(segments.Select(s => new LineSegmentFr(
                                                  new PointFr(new Fraction(s.StartPoint.X), new Fraction(s.StartPoint.Y)),
                                                  new PointFr(new Fraction(s.EndPoint.X), new Fraction(s.EndPoint.Y)), true)).ToList());

            var result = IntersectionsBentleyOttmann(hsSegments, out var sweepLinesFr);

            var endpoints = result.Values.SelectMany(s => s).Select(s => new [] { s.StartPoint, s.EndPoint })
                            .SelectMany(p => p).ToList();
            var minY = endpoints.MinBy(p => p.Y).First().Y;
            var maxY = endpoints.MaxBy(p => p.Y).First().Y;

            sweepLines = sweepLinesFr.Keys.Select(key => new LineSegment(
                                                      new Point(key.X.ToDouble(), minY.ToDouble()),
                                                      new Point(key.X.ToDouble(), maxY.ToDouble()))).ToArray();

            return(result.ToDictionary(kvp => new Point(kvp.Key.X.ToDouble(), kvp.Key.Y.ToDouble()),
                                       kvp => kvp.Value.Select(s => new LineSegment(
                                                                   new Point(s.StartPoint.X.ToDouble(), s.StartPoint.Y.ToDouble()),
                                                                   new Point(s.EndPoint.X.ToDouble(), s.EndPoint.Y.ToDouble()))).ToList()));
        }
Пример #9
0
 public void AddAll(IEnumerable <string> range)
 {
     names.AddAll(range);
 }
Пример #10
0
        protected void CheckEvents(string name, int expectedTypes, string[] expected, string[] notExpected)
        {
            C5.HashSet <string> eventsToFind = new C5.HashSet <string>( );
            eventsToFind.AddAll(expected);
            C5.HashSet <string> eventsNotToFind = new C5.HashSet <string>( );
            eventsNotToFind.AddAll(notExpected);

            C5.HashSet <string> methodsToFind = new C5.HashSet <string>( );
            for (int i = 0; i < expected.Length; i++)
            {
                methodsToFind.Add("add_" + expected[i]);
                methodsToFind.Add("remove_" + expected[i]);
            }

            C5.HashSet <string> methodsNotToFind = new C5.HashSet <string>( );
            for (int i = 0; i < notExpected.Length; i++)
            {
                methodsNotToFind.Add("add_" + notExpected[i]);
                methodsNotToFind.Add("remove_" + notExpected[i]);
            }

            bool foundDelType = false;

            AssemblyHelper.CheckAssembly(name, expectedTypes,
                                         delegate(TypeDefinition typeDef)
            {
                if (typeDef.BaseType.FullName == "System.MulticastDelegate")
                {
                    foundDelType = true;
                    return(false);
                }
                else
                {
                    return(true);
                }
            },
                                         delegate(TypeDefinition typeDef)
            {
                // make sure we have enough methods...
                // 2 methods / event + a method to fire them
                Assert.AreEqual(methodsToFind.Count + methodsNotToFind.Count + 1, typeDef.Methods.Count,
                                "Some of the methods for the type are missing.");

                foreach (MethodDefinition method in typeDef.Methods)
                {
                    Assert.IsFalse(methodsNotToFind.Contains(method.Name), String.Format(
                                       "Did not expect to find method '{0}'.", method.Name));

                    methodsToFind.Remove(method.Name);
                }

                Assert.AreEqual(expected.Length, typeDef.Events.Count,
                                expected.Length == 1 ? "Type should have 1 event (others dropped by default)." :
                                String.Format("Type should have {0} events (others dropped by default).", expected.Length));

                foreach (EventDefinition evt in typeDef.Events)
                {
                    Assert.IsFalse(eventsNotToFind.Contains(evt.Name), String.Format(
                                       "Did not expect to find event '{0}'.", evt.Name));

                    eventsToFind.Remove(evt.Name);
                }

                Assert.IsFalse(methodsToFind.Count > 0, "Failed to find all expected methods.");
                Assert.IsFalse(eventsToFind.Count > 0, "Failed to find all expected events.");
            });

            Assert.IsTrue(foundDelType, "Should have found the delegate type.");
        }
Пример #11
0
		protected void CheckEvents( string name, int expectedTypes, string[] expected, string[] notExpected )
		{
			C5.HashSet<string> eventsToFind = new C5.HashSet<string>( );
			eventsToFind.AddAll( expected );
			C5.HashSet<string> eventsNotToFind = new C5.HashSet<string>( );
			eventsNotToFind.AddAll( notExpected );

			C5.HashSet<string> methodsToFind = new C5.HashSet<string>( );
			for ( int i = 0; i < expected.Length; i++ )
			{
				methodsToFind.Add( "add_" + expected[i] );
				methodsToFind.Add( "remove_" + expected[i] );
			}

			C5.HashSet<string> methodsNotToFind = new C5.HashSet<string>( );
			for ( int i = 0; i < notExpected.Length; i++ )
			{
				methodsNotToFind.Add( "add_" + notExpected[i] );
				methodsNotToFind.Add( "remove_" + notExpected[i] );
			}

			bool foundDelType = false;

			AssemblyHelper.CheckAssembly( name, expectedTypes,
				delegate( TypeDefinition typeDef )
				{
					if ( typeDef.BaseType.FullName == "System.MulticastDelegate" )
					{
						foundDelType = true;
						return false;
					}
					else
						return true;
				},
				delegate( TypeDefinition typeDef )
				{
					// make sure we have enough methods...
					// 2 methods / event + a method to fire them
					Assert.AreEqual( methodsToFind.Count + methodsNotToFind.Count + 1, typeDef.Methods.Count,
						"Some of the methods for the type are missing." );

					foreach ( MethodDefinition method in typeDef.Methods )
					{
						Assert.IsFalse( methodsNotToFind.Contains( method.Name ), String.Format(
							"Did not expect to find method '{0}'.", method.Name ) );

						methodsToFind.Remove( method.Name );
					}

					Assert.AreEqual( expected.Length, typeDef.Events.Count,
						expected.Length == 1 ? "Type should have 1 event (others dropped by default)." :
						String.Format( "Type should have {0} events (others dropped by default).", expected.Length ) );

					foreach ( EventDefinition evt in typeDef.Events )
					{
						Assert.IsFalse( eventsNotToFind.Contains( evt.Name ), String.Format(
							"Did not expect to find event '{0}'.", evt.Name ) );

						eventsToFind.Remove( evt.Name );
					}

					Assert.IsFalse( methodsToFind.Count > 0, "Failed to find all expected methods." );
					Assert.IsFalse( eventsToFind.Count > 0, "Failed to find all expected events." );
				} );

			Assert.IsTrue( foundDelType, "Should have found the delegate type." );
		}
Пример #12
0
 ///<summary>Gets a set of facet names</summary>
 ///<returns> set of facet names </returns>
 public virtual IEnumerable<string> GetFacetNames()
 {
     Dictionary<string, FacetHandler>.KeyCollection runtimeFacetNames = runtimeFacetHandlerMap.Keys;
     IEnumerable<string> installedFacetNames = reader.GetFacetNames();
     if (runtimeFacetNames.Count > 0)
     {
         C5.HashSet<string> names = new C5.HashSet<string>();
         names.AddAll(reader.GetFacetNames());
         names.AddAll(runtimeFacetHandlerMap.Keys);
         return names;
     }
     else
     {
         return installedFacetNames;
     }
 }
Пример #13
0
 public void C5_HashSet() => c5_hashset.AddAll(Items);