Ejemplo n.º 1
0
		/**
		 * correlates the data based on timestamps
		 * handling just 2 lists right now.
		 * TODO: eventually we would want to handle all the lists in the directory
		 */

		public List<TransponderData> sendData (List<TransponderData>  dataList )  
		{
			var listToSend = new List<TransponderData> ();
			listToSend.Add (dataList [0]);

			for (int i = 1; i<dataList.Count; i++) 
			{
				if((dataList [0].Timestamp).Equals (dataList [i].Timestamp))
				{
					listToSend.Add (dataList[i]);
					dataList.RemoveAt(i);
				}
				else
				{
					break;
				}
			}

			dataList.RemoveAt(0);

			BroadcastDataEvent (listToSend);
			System.Threading.Thread.Sleep (200);

			return dataList;
		}
 public void TestRandomAllocation()
 {
     int repeatCount = 10000;
     int range = 100;
     IList<int> allocated = new List<int>();
     IntAllocator intAllocator = new IntAllocator(0, range);
     Random rand = new Random();
     while (repeatCount-- > 0)
     {
         if (rand.Next(2) == 0)
         {
             int a = intAllocator.Allocate();
             if (a > -1)
             {
                 Assert.False(allocated.Contains(a));
                 allocated.Add(a);
             }
         }
         else if (allocated.Count > 0)
         {
             int a = allocated[0];
             intAllocator.Free(a);
             allocated.RemoveAt(0);
         }
     }
 }
Ejemplo n.º 3
0
		public void UniqueTreeTest ()
		{
			// Unique tree
			var expectedRemain = new List<double>();
			var tree = new Tree<double, string>(
				new TreeMemoryNodeManager<double, string>(2, Comparer<double>.Default)
			);

			// Insert random numbers
			for (var i = 0; i < 1000; i++) {
				tree.Insert (i, i.ToString());
				expectedRemain.Add (i);
			}

			// Start deleting randomly
			var rnd = new Random ();
			for (var i = 0; i < 1000; i++) {
				var deleteAt = rnd.Next (0, expectedRemain.Count);
				var keyToDelete = expectedRemain[deleteAt];
				expectedRemain.RemoveAt (deleteAt);
				tree.Delete (keyToDelete);
				var remain = (from entry in tree.LargerThanOrEqualTo(0) select entry.Item1).ToArray();
				Assert.IsTrue (remain.SequenceEqual (expectedRemain));
			}

			Assert.Throws<InvalidOperationException>(delegate {
				tree.Delete (888, "888");
			});
		}
Ejemplo n.º 4
0
        public void ListBasics()
        {
            var names =  new List<string>();
            names.Add("fred");
            Assert.AreEqual("fred", names[0]);

            Assert.AreEqual(1, names.Count);
            names.Add("betty");
            Assert.AreEqual(2, names.Count);

            names.RemoveAt(0); // After we remove Fred, we have Bett
            Assert.AreEqual(1, names.Count);
            Assert.AreEqual("betty", names[0]);

            names[0] = "barney";

            //foreach (string name in names)
            //{
            //    Console.WriteLine(name);
            //}

            //var integers = new List<int>(50) {10, 20};
            //Equivalent to:
            var tmp = new List<int>(50);
            tmp.Add(10);
            tmp.Add(20);
            var integers = tmp;

            integers = new List<int>() { integers.Count };
            Assert.AreEqual(2, integers[0]);
        }
Ejemplo n.º 5
0
 public void FindTop10VideoFriends_CountOfListVideoLess10()
 {
     List<Video> listVideo = new List<Video>();
     listVideo = FillingListVideo(listVideo);
     listVideo.RemoveAt(9);
     Assert.AreEqual(listVideo, control.FindTop10Video(listVideo));
 }
        public void GetSiblings()
        {
            var a = new List<IPAddress> {
                new IPAddress(Ba(192, 168, 178, 0)),
                new IPAddress(Ba(192, 168, 178, 1)),
                new IPAddress(Ba(192, 168, 178, 2)),
                new IPAddress(Ba(192, 168, 178, 3)),
                new IPAddress(Ba(192, 168, 178, 4)),
                new IPAddress(Ba(192, 168, 178, 5)),
                new IPAddress(Ba(192, 168, 178, 6)),
                new IPAddress(Ba(192, 168, 178, 7))
            };
            var ip = new IPAddress(Ba(192, 168, 178, 5));
            var mask = new NetMask(255, 255, 255, 248);

            TestSiblings(a, ip, mask);

            a = new List<IPAddress> {
                new IPAddress(Ba(10, 20, 3, 192)),
             // new IPAddress(Ba(10, 20, 3, 193)),
                new IPAddress(Ba(10, 20, 3, 194)),
                new IPAddress(Ba(10, 20, 3, 195)),
                new IPAddress(Ba(10, 20, 3, 196)),
                new IPAddress(Ba(10, 20, 3, 197)),
                new IPAddress(Ba(10, 20, 3, 198)),
                new IPAddress(Ba(10, 20, 3, 199)),
                new IPAddress(Ba(10, 20, 3, 200)),
                new IPAddress(Ba(10, 20, 3, 201)),
                new IPAddress(Ba(10, 20, 3, 202)),
                new IPAddress(Ba(10, 20, 3, 203)),
                new IPAddress(Ba(10, 20, 3, 204)),
                new IPAddress(Ba(10, 20, 3, 205)),
                new IPAddress(Ba(10, 20, 3, 206)),
                new IPAddress(Ba(10, 20, 3, 207))
            };
            ip = new IPAddress(Ba(10, 20, 3, 193));
            mask = new NetMask(255, 255, 255, 240);

            TestSiblings(a, ip, mask, SiblingOptions.IncludeNetworkIdentifier | SiblingOptions.IncludeBroadcast);

            a.RemoveAt(a.Count - 1);
            TestSiblings(a, ip, mask, SiblingOptions.IncludeNetworkIdentifier);

            a.RemoveAt(0);
            TestSiblings(a, ip, mask, SiblingOptions.ExcludeAll);
        }
Ejemplo n.º 7
0
 public void HasSameContentsAs()
 {
     var listA = new List<string> { "a", "z", "alpha" };
     var listB = new List<string> { "alpha", "a", "z",  };
     Assert.IsTrue(listA.HasSameContentsAs(listB), "same content, diff order");
     listA.RemoveAt(0);
     Assert.IsFalse(listA.HasSameContentsAs(listB), "not the same content");
     listA.Add("b");
     Assert.IsFalse(listA.HasSameContentsAs(listB), "not the same content");
 }
Ejemplo n.º 8
0
        public virtual void TestMultipleWriterReader()
        {
            Counter bytesUsed = Util.Counter.NewCounter();
            IntBlockPool pool = new IntBlockPool(new ByteTrackingAllocator(bytesUsed));
            for (int j = 0; j < 2; j++)
            {
                IList<StartEndAndValues> holders = new List<StartEndAndValues>();
                int num = AtLeast(4);
                for (int i = 0; i < num; i++)
                {
                    holders.Add(new StartEndAndValues(Random().Next(1000)));
                }
                IntBlockPool.SliceWriter writer = new IntBlockPool.SliceWriter(pool);
                IntBlockPool.SliceReader reader = new IntBlockPool.SliceReader(pool);

                int numValuesToWrite = AtLeast(10000);
                for (int i = 0; i < numValuesToWrite; i++)
                {
                    StartEndAndValues values = holders[Random().Next(holders.Count)];
                    if (values.ValueCount == 0)
                    {
                        values.Start = writer.StartNewSlice();
                    }
                    else
                    {
                        writer.Reset(values.End);
                    }
                    writer.WriteInt(values.NextValue());
                    values.End = writer.CurrentOffset;
                    if (Random().Next(5) == 0)
                    {
                        // pick one and reader the ints
                        AssertReader(reader, holders[Random().Next(holders.Count)]);
                    }
                }

                while (holders.Count > 0)
                {
                    int randIndex = Random().Next(holders.Count);
                    StartEndAndValues values = holders[randIndex];
                    holders.RemoveAt(randIndex);
                    AssertReader(reader, values);
                }
                if (Random().NextBoolean())
                {
                    pool.Reset(true, false);
                    Assert.AreEqual(0, bytesUsed.Get());
                }
                else
                {
                    pool.Reset(true, true);
                    Assert.AreEqual(IntBlockPool.INT_BLOCK_SIZE * RamUsageEstimator.NUM_BYTES_INT, bytesUsed.Get());
                }
            }
        }
Ejemplo n.º 9
0
        public void TestModifyMaster()
        {
            List<string> strings = new List<string>(new string[] { "a", "b", "c" });
            ReadOnlyList<String> read = new ReadOnlyList<string>(strings, false);

            Assert.AreEqual(3, read.Count);
            strings.RemoveAt(2);
            Assert.AreEqual(2, read.Count);
            Assert.AreEqual("a", read[0]);
            Assert.AreEqual("b", read[1]);

            Assert.AreEqual("a,b", String.Join(",", read.Clone().ToArray()));
        }
        public void List_Has_Dynamic_Size()
        {
            var names = new List<string>();

            names.Add("fred");
            Assert.That(names.Count, Is.EqualTo(1));

            names.Add("betty");
            Assert.That(names.Count, Is.EqualTo(2));

            names.RemoveAt(0);
            Assert.That(names.Count, Is.EqualTo(1));
        }
Ejemplo n.º 11
0
        public void TestExecute()
        {
            var list = new List<int> ();
            Action<int,int> exeAction = (i, v) => list.Insert (i, v);
            Action<int,int> undoAction = (i, v) => list.RemoveAt (i);

            var command = new Command<int,int>(0,4,exeAction, undoAction);
            command.Execute ();
            Assert.AreEqual (1, list.Count);
            Assert.AreEqual (list[0],4);

            command.Undo ();
            Assert.AreEqual (0, list.Count);
        }
        public void Test()
        {
            var rand = new Random(3);

            List<string> list1 = new List<string>();
            WeakList<string> list2 = new WeakList<string>();

            for (int x = 0; x < 1000; x++)
            {
                var str = x.ToString();
                list1.Add(str);
                list2.Add(str);

                if (!list1.SequenceEqual(list2))
                    throw new Exception("Lists are not the same.");
            }

            for (int x = 1000; x < 2000; x++)
            {
                var str = x.ToString();
                var removeItem = list1[rand.Next(list1.Count)];
                list1.Remove(removeItem);
                list2.Remove(removeItem);

                if (!list1.SequenceEqual(list2))
                    throw new Exception("Lists are not the same.");

                list1.Add(str);
                list2.Add(str);

                if (!list1.SequenceEqual(list2))
                    throw new Exception("Lists are not the same.");
            }

            for (int x = 0; x < 100; x++)
            {
                list1.RemoveAt(rand.Next(list1.Count));
                GC.Collect();

                if (!list1.SequenceEqual(list2))
                    throw new Exception("Lists are not the same.");
            }


            list2.Clear();
            foreach (var data in list2)
                throw new Exception();
        }
Ejemplo n.º 13
0
        public void Matches_ActualMoreThanExpectation_Failure()
        {
            var discovery = new DiscoveryRequestFactory().BuildDirect(
                        ConnectionStringReader.GetAdomd()
                        , DiscoveryTarget.Perspectives
                        , new List<IFilter>());

            var expectedStrings = new string[] { "Adventure Works", "Channel Sales", "Direct Sales", "Finance", "Sales Summary", "Sales Targets" };
            var expected = new List<string>();
            expected.AddRange(expectedStrings);
            expected.RemoveAt(0);
            var ctr = new EquivalentToConstraint(expected);

            //Method under test
            Assert.That(ctr.Matches(discovery), Is.False);
        }
        public ListNode MergeKLists(ListNode[] lists)
        {
            if (lists == null || lists.Length == 0) return null;
            if (lists.Length == 1) return lists[0];

            ListNode head = null;
            ListNode current = null;

            var toManipulate = new List<ListNode>(lists.Where(l => l != null));
            while (toManipulate.Count > 0)
            {
                int lowestValue = int.MaxValue;
                int lowestIdx = 0;
                for (var idx = 0; idx < toManipulate.Count; ++idx)
                {
                    if (toManipulate[idx].val < lowestValue)
                    {
                        lowestValue = toManipulate[idx].val;
                        lowestIdx = idx;
                    }
                }

                if (head == null)
                {
                    head = toManipulate[lowestIdx];
                    current = head;
                }
                else
                {
                    current.next = toManipulate[lowestIdx];
                    current = current.next;
                }

                var next = toManipulate[lowestIdx].next;
                if (next == null)
                {
                    toManipulate.RemoveAt(lowestIdx);
                }
                else
                {
                    toManipulate[lowestIdx] = next;
                }
            }

            return head;
        }
Ejemplo n.º 15
0
        public void AllNodesAreCoveredDuringIteration()
        {
            var nodeArray = new List<Node>();
            for (var i = 0; i < 5; ++i)
            {
                var node = new MockNode();
                nodeArray.Add(node);
                _nodes.Add(node);
            }

            for (var node = _nodes.Head; node != null; node = node.Next)
            {
                var index = nodeArray.IndexOf(node);
                nodeArray.RemoveAt(index);
            }
            Assert.AreEqual(0, nodeArray.Count);
        }
Ejemplo n.º 16
0
 public static IEnumerable<int> MakeRandomInsertList(int count)
 {
     List<int> ret = new List<int>(count);
     List<int> sorted = new List<int>(count);
     var rng = new Random();
     for (int i = 0; i < count; i++)
     {
         sorted.Add(i);
     }
     while (sorted.Count > 0)
     {
         var sampleIx = rng.Next(sorted.Count);
         ret.Add(sorted[sampleIx]);
         sorted.RemoveAt(sampleIx);
     }
     return ret;
 }
		public void Insert()
		{
			List<string> applied = new List<string> { "foo", "bar", "baz" };

			Action reset = () => Assert.Fail ("Reset should not be called");
			Action<object, int, bool> insert = (o, i, create) => {
				Assert.That (create, Is.True);
				applied.Insert (i, (string) o);
			};
			Action<object, int> removeAt = (o, i) => applied.RemoveAt (i);

			var items = new ObservableCollection<string> (applied);
			items.CollectionChanged += (s, e) => e.Apply (insert, removeAt, reset);

			items.Insert (1, "monkey");

			CollectionAssert.AreEqual (items, applied);
		}
Ejemplo n.º 18
0
        public void Matches_ActualMoreThanExpectation_Failure()
        {
            var provider = new StructureDiscoveryFactoryProvider();
            var factory = provider.Instantiate(ConnectionStringReader.GetAdomd());
            var discovery = factory.Instantiate(
                        Target.Perspectives
                        , TargetType.Object
                        , new CaptionFilter[] { });

            var expectedStrings = new string[] { "Adventure Works", "Channel Sales", "Direct Sales", "Finance", "Mined Customers", "Sales Summary", "Sales Targets" };
            var expected = new List<string>();
            expected.AddRange(expectedStrings);
            expected.RemoveAt(0);
            var ctr = new SubsetOfConstraint(expected);

            //Method under test
            Assert.That(ctr.Matches(discovery), Is.False);
        }
        public void NodeListContainsAllMatchingEntities()
        {
            var entities = new List<EntityBase>();
            for (var i = 0; i < 5; ++i)
            {
                var entity = new EntityBase();
                entity.Add(new Vector2());
                entities.Add(entity);
                _family.NewEntity(entity);
                _family.NewEntity(new EntityBase());
            }

            var nodes = _family.NodeList;
            for (var node = nodes.Head; node != null; node = node.Next)
            {
                entities.RemoveAt(entities.IndexOf(node.Entity));
            }
            Assert.AreEqual(0, entities.Count);
        }
Ejemplo n.º 20
0
        public void FamilyContainsAllMatchingEntities()
        {
            var entities = new List<Entity>();
            for (var i = 0; i < 5; ++i)
            {
                var entity = new Entity();
                entity.Add(new Vector2());
                entity.Add(new Matrix4x4());
                entities.Add(entity);
                _game.AddEntity(entity);
            }

            var nodes = _game.GetNodeList<MockNode>();
            for (var node = nodes.Head; node != null; node = node.Next)
            {
                var index = entities.IndexOf(node.Entity);
                entities.RemoveAt(index);
            }
            Assert.AreEqual(0, entities.Count);
        }
Ejemplo n.º 21
0
    public void IsFunctional() {
      List<float> list = new List<float>();

      for (int i = 0; i < 1000; i++) {
        float newValue = Random.value;

        _slidingMax.AddValue(newValue);

        list.Add(newValue);
        while (list.Count > MAX_HISTORY) {
          list.RemoveAt(0);
        }

        float max = list[0];
        for (int j = 1; j < list.Count; j++) {
          max = Mathf.Max(max, list[j]);
        }

        Assert.That(max, Is.EqualTo(_slidingMax.Max));
      }
    }
Ejemplo n.º 22
0
        public void test_concurrent_modification_retains_cache()
        {
            var list = new List<int> {
                1,
                2,
                3,
                4
            };

            var buffer = new Buffer<int>(list);
            Assert.That(buffer[0], Is.EqualTo(1));
            Assert.That(buffer[3], Is.EqualTo(4));
            Assert.That(buffer.Count, Is.EqualTo(4));

            // Underlying enumeration is concurrently modified
            list.RemoveAt(0);

            Assert.That(buffer[0], Is.EqualTo(2));
            Assert.That(buffer[2], Is.EqualTo(4));
            Assert.That(buffer.Count, Is.EqualTo(3));
        }
Ejemplo n.º 23
0
        public void RemovingCurrentNodeDuringIterationIsValid()
        {
            var nodeArray = new List<Node>();
            for (var i = 0; i < 5; ++i)
            {
                var node = new MockNode();
                nodeArray.Add(node);
                _nodes.Add(node);
            }
			
            var count = 0;
            for (var node = _nodes.Head; node != null; node = node.Next)
            {
                var index = nodeArray.IndexOf(node);
                nodeArray.RemoveAt(index);
                if (++count == 2)
                {
                    _nodes.Remove(node);
                }
            }
            Assert.AreEqual(0, nodeArray.Count);
        }
Ejemplo n.º 24
0
        public void TestRemove()
        {
            BinaryHeap<int> heap = new BinaryHeap<int>();
            int[] testData = new int[10] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

            List<int> sortedList = new List<int>();
            sortedList.AddRange(testData);

            Random r = new Random();

            int randomIndex = 0;
            while (sortedList.Count > 0) {
                randomIndex = r.Next(0, sortedList.Count);
                heap.Add(sortedList[randomIndex]);

                sortedList.RemoveAt(randomIndex);
            }

            for (int i = 0; i < testData.Length; i++) {
                Assert.AreEqual(i, heap.Remove());
            }
        }
Ejemplo n.º 25
0
        public void ExtensiveAllocationTest()
        {
            var pool = CreateTestPool();
            var objs = new List<MyTestObj>(1000);
            var expectedLive = 0;

            for (var i = 0; i < 1000; i++)
            {
                objs.Add(pool.Acquire());
                expectedLive++;
            }

            Assert.AreEqual(expectedLive, pool.LiveObjects);

            for (var i = 250; i < 150; i -= 2)
            {
                pool.Free(objs[i]);
                objs.RemoveAt(i);
                expectedLive--;
            }

            Assert.AreEqual(expectedLive, pool.LiveObjects);

            for (var i = 0; i < 50; i += 2)
            {
                objs.Add(pool.Acquire());
                expectedLive++;
            }

            Assert.AreEqual(expectedLive, pool.LiveObjects);

            foreach (var obj in objs)
            {
                pool.Free(obj);
            }

            Assert.AreEqual(0, pool.LiveObjects);
        }
        public void testEqualsAndHashCode()
        {
            var vertices = new List<S2Point>();
            vertices.Add(new S2Point(1, 0, 0));
            vertices.Add(new S2Point(0, 1, 0));
            vertices.Add(S2Point.Normalize(new S2Point(0, 1, 1)));
            vertices.Add(new S2Point(0, 0, 1));


            var line1 = new S2Polyline(vertices);
            var line2 = new S2Polyline(vertices);

            checkEqualsAndHashCodeMethods(line1, line2, true);

            var moreVertices = new List<S2Point>(vertices);
            moreVertices.RemoveAt(0);

            var line3 = new S2Polyline(moreVertices);

            checkEqualsAndHashCodeMethods(line1, line3, false);
            checkEqualsAndHashCodeMethods(line1, null, false);
            checkEqualsAndHashCodeMethods(line1, "", false);
        }
Ejemplo n.º 27
0
		public void CreateAndMoveAnchors()
		{
			List<TextAnchor> anchors = new List<TextAnchor>();
			List<int> expectedOffsets = new List<int>();
			document.Text = new string(' ', 1000);
			for (int t = 0; t < 250; t++) {
				//Console.Write("t = " + t + " ");
				int c = rnd.Next(50);
				switch (rnd.Next(5)) {
					case 0:
						//Console.WriteLine("Add c=" + c + " anchors");
						for (int i = 0; i < c; i++) {
							int offset = rnd.Next(document.TextLength);
							TextAnchor anchor = document.CreateAnchor(offset);
							if (rnd.Next(2) == 0)
								anchor.MovementType = AnchorMovementType.BeforeInsertion;
							else
								anchor.MovementType = AnchorMovementType.AfterInsertion;
							anchor.SurviveDeletion = rnd.Next(2) == 0;
							anchors.Add(anchor);
							expectedOffsets.Add(offset);
						}
						break;
					case 1:
						if (c <= anchors.Count) {
							//Console.WriteLine("Remove c=" + c + " anchors");
							anchors.RemoveRange(0, c);
							expectedOffsets.RemoveRange(0, c);
							GC.Collect();
						}
						break;
					case 2:
						int insertOffset = rnd.Next(document.TextLength);
						int insertLength = rnd.Next(1000);
						//Console.WriteLine("insertOffset=" + insertOffset + " insertLength="+insertLength);
						document.Insert(insertOffset, new string(' ', insertLength));
						for (int i = 0; i < anchors.Count; i++) {
							if (anchors[i].MovementType == AnchorMovementType.BeforeInsertion) {
								if (expectedOffsets[i] > insertOffset)
									expectedOffsets[i] += insertLength;
							} else {
								if (expectedOffsets[i] >= insertOffset)
									expectedOffsets[i] += insertLength;
							}
						}
						break;
					case 3:
						int removalOffset = rnd.Next(document.TextLength);
						int removalLength = rnd.Next(document.TextLength - removalOffset);
						//Console.WriteLine("RemovalOffset=" + removalOffset + " RemovalLength="+removalLength);
						document.Remove(removalOffset, removalLength);
						for (int i = anchors.Count - 1; i >= 0; i--) {
							if (expectedOffsets[i] > removalOffset && expectedOffsets[i] < removalOffset + removalLength) {
								if (anchors[i].SurviveDeletion) {
									expectedOffsets[i] = removalOffset;
								} else {
									Assert.IsTrue(anchors[i].IsDeleted);
									anchors.RemoveAt(i);
									expectedOffsets.RemoveAt(i);
								}
							} else if (expectedOffsets[i] > removalOffset) {
								expectedOffsets[i] -= removalLength;
							}
						}
						break;
					case 4:
						int replaceOffset = rnd.Next(document.TextLength);
						int replaceRemovalLength = rnd.Next(document.TextLength - replaceOffset);
						int replaceInsertLength = rnd.Next(1000);
						//Console.WriteLine("ReplaceOffset=" + replaceOffset + " RemovalLength="+replaceRemovalLength + " InsertLength=" + replaceInsertLength);
						document.Replace(replaceOffset, replaceRemovalLength, new string(' ', replaceInsertLength));
						for (int i = anchors.Count - 1; i >= 0; i--) {
							if (expectedOffsets[i] > replaceOffset && expectedOffsets[i] < replaceOffset + replaceRemovalLength) {
								if (anchors[i].SurviveDeletion) {
									if (anchors[i].MovementType == AnchorMovementType.AfterInsertion)
										expectedOffsets[i] = replaceOffset + replaceInsertLength;
									else
										expectedOffsets[i] = replaceOffset;
								} else {
									Assert.IsTrue(anchors[i].IsDeleted);
									anchors.RemoveAt(i);
									expectedOffsets.RemoveAt(i);
								}
							} else if (expectedOffsets[i] > replaceOffset) {
								expectedOffsets[i] += replaceInsertLength - replaceRemovalLength;
							} else if (expectedOffsets[i] == replaceOffset && replaceRemovalLength == 0 && anchors[i].MovementType == AnchorMovementType.AfterInsertion) {
								expectedOffsets[i] += replaceInsertLength - replaceRemovalLength;
							}
						}
						break;
				}
				Assert.AreEqual(anchors.Count, expectedOffsets.Count);
				for (int j = 0; j < anchors.Count; j++) {
					Assert.AreEqual(expectedOffsets[j], anchors[j].Offset);
				}
			}
			GC.KeepAlive(anchors);
		}
 /// <summary>
 /// 
 /// </summary>
 private void SetRootPathProject()
 {
     var list = new List<string>(Directory.GetCurrentDirectory().Split('\\'));
     list.RemoveAt(list.Count - 1);
     list.RemoveAt(list.Count - 1);
     list.Add(string.Empty);
     this.rootPathProject = string.Join("\\", list.ToArray());
 }
        public void CheckManagedFilters()
        {
            List<string> filters = new List<string> (CIFilter.FilterNamesInCategories (null));
            var nspace = CIFilterType.Namespace;
            var types = CIFilterType.Assembly.GetTypes ();
            foreach (Type t in types) {
                if (t.Namespace != nspace)
                    continue;

                if (t.IsAbstract || !CIFilterType.IsAssignableFrom (t))
                    continue;

                // we need to skip the filters that are not supported by the executing version of iOS
                if (Skip (t))
                    continue;

                var ctor = t.GetConstructor (Type.EmptyTypes);
                if ((ctor == null) || ctor.IsAbstract)
                    continue;

                NSObject obj = ctor.Invoke (null) as NSObject;
                Assert.That (obj.Handle, Is.Not.EqualTo (IntPtr.Zero), t.Name + ".Handle");
            #if false
                // check base type - we might have our own base type or different names, so it's debug only (not failure)
                var super = new Class (obj.Class.SuperClass).Name;
                var bt = t.BaseType.Name;
                if ((super != bt) && (bt == "CIFilter")) // check if we should (like Apple) use a non-default base type for filters
                    Console.WriteLine ("[WARN] {0}.SuperClass == {1} (native) and {2} managed", t.Name, super, bt);
            #endif
                int result = filters.RemoveAll (s => StringComparer.OrdinalIgnoreCase.Compare (t.Name, s) == 0);
                Assert.That (result, Is.GreaterThan (0), t.Name);
            }
            // in case it's a buggy filter we need to try to remove it from the list too
            for (int i = filters.Count - 1; i >= 0; i--) {
                if (Skip (filters [i]))
                    filters.RemoveAt (i);
            }
            Assert.That (filters.Count, Is.EqualTo (0), "Managed filters not found for {0}", String.Join (", ", filters));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Test removing customers.
        /// </summary>
        public void DoTestRemove()
        {
            // create a new empty route.
            const int count = 100;
            IRoute route = this.BuildRoute(0, true);
            var customers = new List<int>();
            if (route != null)
            { // this part needs testing!
                customers.Add(0);
                for (int customer = 1; customer < count; customer++)
                {
                    route.InsertAfter(customer - 1, customer);
                    //route.InsertAfterAndRemove(customer - 1, customer, -1);
                    customers.Add(customer);
                }

                // remove customers.
                while (customers.Count > 0)
                {
                    int customerIdx = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(
                        customers.Count);
                    int customer = customers[customerIdx];
                    customers.RemoveAt(customerIdx);

                    route.Remove(customer);

                    Assert.AreEqual(customers.Count, route.Count);
                    Assert.AreEqual(customers.Count == 0, route.IsEmpty);
                    Assert.AreEqual(true, route.IsRound);
                    Assert.AreEqual(route.Last, route.First);
                }
            }

            route = this.BuildRoute(true);
            customers = new List<int>();
            if (route != null)
            { // this part needs testing!
                for (int customer = 0; customer < count; customer++)
                {
                    route.InsertAfter(customer - 1, customer);
                    //route.InsertAfterAndRemove(customer - 1, customer, -1);
                    customers.Add(customer);
                }

                // remove customers.
                while (customers.Count > 0)
                {
                    int customerIdx = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(
                        customers.Count);
                    int customer = customers[customerIdx];
                    customers.RemoveAt(customerIdx);

                    route.Remove(customer);

                    Assert.AreEqual(customers.Count, route.Count);
                    Assert.AreEqual(customers.Count == 0, route.IsEmpty);
                    Assert.AreEqual(true, route.IsRound);
                    Assert.AreEqual(route.Last, route.First);
                }
            }
        }