Esempio n. 1
0
		public static void RunSpaceTests()
		{
			//test IsSubSpace
			Space FirstSpace = new Space();
			Space SecondSpace = new Space();

			for (int i = 0; i < 100; i++)
			{
					FirstSpace.Add(new BitmapPoint(i, i));
				if (i >= 25 && i <= 50)
					SecondSpace.Add(new BitmapPoint(i, i));
			}

			if (SecondSpace.IsSubsetOf(FirstSpace))
				Console.WriteLine("Test IsSubSpace passed!");
			else Console.WriteLine("Test IsSubSpace failed!");

			//test !IsSubSpace
			FirstSpace = new Space();
			SecondSpace = new Space();

			for (int i = 0; i < 100; i++)
			{
				if (i >= 50)
					FirstSpace.Add(new BitmapPoint(i, i));
				if (i <= 25)
					SecondSpace.Add(new BitmapPoint(i, i));
			}

			if (!SecondSpace.IsSubsetOf(FirstSpace))
				Console.WriteLine("Test !IsSubSpace passed!");
			else Console.WriteLine("Test !IsSubSpace failed!");

			//test Contains
			FirstSpace = new Space();
			SecondSpace = new Space();

			for (int i = 0; i < 100; i++)
			{
				FirstSpace.Add(new BitmapPoint(i, i));
				if (i >= 25 && i <= 50)
					SecondSpace.Add(new BitmapPoint(i, i));
			}

			if (FirstSpace.Contains(SecondSpace))
				Console.WriteLine("Test Contains passed!");
			else Console.WriteLine("Test Contains failed!");

			//test !Contains
			FirstSpace = new Space();
			SecondSpace = new Space();

			for (int i = 0; i < 100; i++)
			{
				if( i <= 50)
				FirstSpace.Add(new BitmapPoint(i, i));
				if (i >= 75)
					SecondSpace.Add(new BitmapPoint(i, i));
			}

			if (!FirstSpace.Contains(SecondSpace))
				Console.WriteLine("Test !Contains passed!");
			else Console.WriteLine("Test !Contains failed!");

			//test IsSupersetOf
			FirstSpace = new Space();
			SecondSpace = new Space();

			for (int i = 0; i < 100; i++)
			{
				FirstSpace.Add(new BitmapPoint(i, i));
				if (i >= 75)
					SecondSpace.Add(new BitmapPoint(i, i));
			}

			if (FirstSpace.IsSupersetOf(SecondSpace))
				Console.WriteLine("Test IsSupersetOf passed!");
			else Console.WriteLine("Test IsSupersetOf failed!");

			//test !IsSupersetOf
			FirstSpace = new Space();
			SecondSpace = new Space();

			for (int i = 0; i < 100; i++)
			{
				if( i <= 25)
					FirstSpace.Add(new BitmapPoint(i, i));
				if (i >= 75)
					SecondSpace.Add(new BitmapPoint(i, i));
			}

			if (!FirstSpace.IsSupersetOf(SecondSpace))
				Console.WriteLine("Test !IsSupersetOf passed!");
			else Console.WriteLine("Test !IsSupersetOf failed!");

			//test GetUnion(Space s1, Space s2)_1
			FirstSpace = new Space();
			SecondSpace = new Space();

			for (int i = 0; i < 100; i++)
			{
				if (i <= 25)
					FirstSpace.Add(new BitmapPoint(i, i));
				if (i >= 75)
					SecondSpace.Add(new BitmapPoint(i, i));
			}

			Space UnionSpace = new Space();

			UnionSpace = Space.Union(FirstSpace, SecondSpace);

			if ( UnionSpace == FirstSpace + SecondSpace )
				Console.WriteLine("Test GetUnion(Space s1, Space s2)_1 passed!");
			else Console.WriteLine("Test GetUnion(Space s1, Space s2)_1 failed!");

			//test GetUnion(Space s1, Space s2)_2
			FirstSpace = new Space();
			SecondSpace = new Space();

			FirstSpace.Add(new BitmapPoint(1, 1));

			SecondSpace.Add(new BitmapPoint(2, 2));

			UnionSpace = new Space();

			UnionSpace = Space.Union(FirstSpace, SecondSpace);

			if (UnionSpace == FirstSpace + SecondSpace)
				Console.WriteLine("Test GetUnion(Space s1, Space s2)_2 passed!");
			else Console.WriteLine("Test GetUnion(Space s1, Space s2)_2 failed!");

			//test GetUnion(Space s1, Space s2)_3
			FirstSpace = new Space();
			SecondSpace = new Space();

			FirstSpace.Add(new BitmapPoint(1, 1));

			FirstSpace.Add(new BitmapPoint(2, 2));

			SecondSpace.Add(new BitmapPoint(2, 2));

			UnionSpace = new Space();

			UnionSpace = Space.Union(FirstSpace, SecondSpace);

			if (UnionSpace == FirstSpace + SecondSpace)
				Console.WriteLine("Test GetUnion(Space s1, Space s2)_3 passed!");
			else Console.WriteLine("Test GetUnion(Space s1, Space s2)_3 failed!");

			//test GetUnion(Space s1, Space s2)_4
			FirstSpace = new Space();
			SecondSpace = new Space();

			FirstSpace.Add(new BitmapPoint(1, 1));

			FirstSpace.Add(new BitmapPoint(2, 2));

			UnionSpace = new Space();

			UnionSpace = Space.Union(FirstSpace, SecondSpace);

			if (UnionSpace == FirstSpace + SecondSpace)
				Console.WriteLine("Test GetUnion(Space s1, Space s2)_4 passed!");
			else Console.WriteLine("Test GetUnion(Space s1, Space s2)_4 failed!");

			//test IntersectWith(Space s)
			FirstSpace = new Space();
			SecondSpace = new Space();

			FirstSpace.Add(new BitmapPoint(1, 1));

			SecondSpace.Add(new BitmapPoint(2, 2));

			SecondSpace.Add(new BitmapPoint(1, 1));

			FirstSpace = Space.Intersect(FirstSpace, SecondSpace);

			if (FirstSpace.Size == 1 && FirstSpace.ElementAt(0).x == 1 && FirstSpace.ElementAt(0).y == 1)
				Console.WriteLine("Test IntersectWith(Space s) passed!");
			else Console.WriteLine("Test IntersectWith(Space s) failed!");

			//test IntersectWith(List<Space> s)
			FirstSpace = new Space(new List<BitmapPoint>() { new BitmapPoint(1, 1) });
			List<Space> Spaces = new List<Space>();

			for (int i = 2; i < 100; i++)
			{
				List<BitmapPoint> points = new List<BitmapPoint>();
				points.Add(new BitmapPoint(1, 1));
				points.Add(new BitmapPoint(i, i));
				Spaces.Add(new Space(points));
			}

			FirstSpace = Space.Intersect(FirstSpace,Spaces);

			if (FirstSpace.Size == 1 && FirstSpace.ElementAt(0).x == 1 && FirstSpace.ElementAt(0).y == 1)
				Console.WriteLine("Test IntersectWith(List<Space> s) passed!");
			else Console.WriteLine("Test IntersectWith(List<Space> s) failed!");

			//test GetEdge(Space s1, Space s2)
			FirstSpace = new Space();
			SecondSpace = new Space();

			FirstSpace.Add(new BitmapPoint(0, 0));
			FirstSpace.Add(new BitmapPoint(1, 0));
			FirstSpace.Add(new BitmapPoint(1, 1));
			FirstSpace.Add(new BitmapPoint(0, 1));

			SecondSpace.Add(new BitmapPoint(1, 1));
			SecondSpace.Add(new BitmapPoint(1, 2));
			SecondSpace.Add(new BitmapPoint(2, 1));
			SecondSpace.Add(new BitmapPoint(2, 2));

			Space Edge = Space.GetEdge(FirstSpace, SecondSpace);

			Console.WriteLine("Test for GetEdge(Space s1, Space s2) not implemented.");
			
		}