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


C# SortedList.ContainsValue方法代码示例

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


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

示例1: ShortestPath

    public Stack ShortestPath(GameObject start, GameObject end)
    {
        InitializeNodesForShortestPath();
        start.GetComponent<NavpointScript>().SetDist(0f);

        SortedList nodes = new SortedList();

        nodes.Add (0f, start);

        while(nodes.Count > 0){
            if(end.Equals ((GameObject)nodes.GetByIndex (0))){
                break;
            }
            NavpointScript u = ((GameObject)nodes.GetByIndex (0)).GetComponent<NavpointScript>();
            nodes.RemoveAt (0);
            u.SetVisited();

            GameObject[] adj = u.GetAdjacentNodes();
            for(int i = 0; i < adj.Length; i++){
                NavpointScript v = adj[i].GetComponent<NavpointScript>();
                float alt = u.GetDistByIndex (i) + u.GetDist ();
                if(alt < v.GetDist () && !v.Visited ()){
                    v.SetDist(alt);
                    v.SetPrev(u.gameObject);
                    if(nodes.ContainsValue (v))
                        nodes.RemoveAt (nodes.IndexOfValue (v));
                    nodes.Add (alt, v.gameObject);
                }
            }
        }
        Stack s = new Stack();

        GameObject node = end;
        while(node != null){
            s.Push(node);
            node = node.GetComponent<NavpointScript>().GetPrev();
        }

        return s;
    }
开发者ID:RandomGuy928,项目名称:GD1P4_SeriousFix,代码行数:40,代码来源:NavmanagerScript.cs

示例2: TestContainsValueBasic

        public void TestContainsValueBasic()
        {
            StringBuilder sblMsg = new StringBuilder(99);

            SortedList sl2 = null;

            StringBuilder sbl3 = new StringBuilder(99);
            StringBuilder sbl4 = new StringBuilder(99);
            StringBuilder sblWork1 = new StringBuilder(99);

            String s1 = null;
            String s2 = null;
            int i = 0;
            //
            // 	Constructor: Create SortedList using this as IComparer and default settings.
            //
            sl2 = new SortedList(this);

            //  Verify that the SortedList is not null.
            Assert.NotNull(sl2);

            //  Verify that the SortedList is empty.
            Assert.Equal(0, sl2.Count);

            //   Testcase: No_Such_Key
            Assert.False(sl2.ContainsKey("No_Such_Val"));

            //   Testcase: add few key-val pairs
            for (i = 0; i < 100; i++)
            {
                sblMsg.Length = 0;
                sblMsg.Append("key_");
                sblMsg.Append(i);
                s1 = sblMsg.ToString();

                sblMsg.Length = 0;
                sblMsg.Append("val_");
                sblMsg.Append(i);
                s2 = sblMsg.ToString();

                sl2.Add(s1, s2);
            }
            //
            //   Testcase: test ContainsValue
            //
            for (i = 0; i < sl2.Count; i++)
            {
                sblMsg.Length = 0;
                sblMsg.Append("val_");
                sblMsg.Append(i);
                s2 = sblMsg.ToString();

                Assert.True(sl2.ContainsValue(s2));
            }

            //
            // Remove a key and then check
            //
            sblMsg.Length = 0;
            sblMsg.Append("key_50");
            s1 = sblMsg.ToString();

            sl2.Remove(s1); //removes "Key_50"

            sblMsg.Length = 0;
            sblMsg.Append("val_50");
            s2 = sblMsg.ToString();

            Assert.False(sl2.ContainsKey(s2));
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:70,代码来源:ContainsValueTests.cs

示例3: TestGetKeyListBasic

        public void TestGetKeyListBasic()
        {
            StringBuilder sblMsg = new StringBuilder(99);
            //

            SortedList sl2 = null;
            IEnumerator en = null;

            StringBuilder sbl3 = new StringBuilder(99);
            StringBuilder sbl4 = new StringBuilder(99);
            StringBuilder sblWork1 = new StringBuilder(99);

            int i3 = 0;
            int i = 0;
            int j = 0;

            //
            // 	Constructor: Create SortedList using this as IComparer and default settings.
            //
            sl2 = new SortedList(); //using default IComparable implementation from Integer4
            // which is used here as key-val elements.

            //  Verify that the SortedList is not null.
            Assert.NotNull(sl2);

            //  Verify that the SortedList is empty.
            Assert.Equal(0, sl2.Count);

            //   Testcase: Set - null key, ArgExc expected
            Assert.Throws<ArgumentNullException>(() =>
                {
                    sl2[null] = 0;
                });

            Assert.Equal(0, sl2.Count);

            //   Testcase: Set - null val
            sl2[(Object)100] = (Object)null;
            Assert.Equal(1, sl2.Count);

            //   Testcase: vanila Set
            sl2[(Object)100] = 1;
            Assert.Equal(1, sl2.Count);

            sl2.Clear();
            Assert.Equal(0, sl2.Count);

            //   Testcase: add key-val pairs
            for (i = 0; i < 100; i++)
            {
                sl2.Add(i + 100, i);
            }

            Assert.Equal(100, sl2.Count);

            for (i = 0; i < 100; i++)
            {
                j = i + 100;
                Assert.True(sl2.ContainsKey((int)j));
                Assert.True(sl2.ContainsValue(i));
            }

            //  testcase: GetKeyList
            //  first test the boundaries on the Remove method thru GetEnumerator implementation
            en = (IEnumerator)sl2.GetKeyList().GetEnumerator();

            //  Boundary for Current
            Assert.Throws<InvalidOperationException>(() =>
                             {
                                 Object objThrowAway = en.Current;
                             }
            );

            j = 100;
            //  go over the enumarator
            en = (IEnumerator)sl2.GetKeyList().GetEnumerator();
            while (en.MoveNext())
            {
                //  Current to see the order
                i3 = (int)en.Current;
                Assert.Equal(i3, j);

                //  Current again to see the same order
                i3 = (int)en.Current;
                Assert.Equal(i3, j);

                j++;
            }


            //  Boundary for Current
            Assert.Throws<InvalidOperationException>(() =>
                             {
                                 Object objThrowAway = en.Current;
                             }
            );

            //  Boundary for MoveNext: call MoveNext to make sure it returns false
            Assert.False((en.MoveNext()) || (j != 200));

//.........这里部分代码省略.........
开发者ID:noahfalk,项目名称:corefx,代码行数:101,代码来源:GetKeyListTests.cs

示例4: AddFamiliesToList

 private static void AddFamiliesToList(SortedList MVList, PluginType aType)
 {
     IList<Plugin> aList = PluginManager.GetPluginList(aType, true, false);
     string EntityAssemblyqualifiedName = (typeof(IAccount)).AssemblyQualifiedName;
     foreach (Plugin grp in aList)
     {
         string family = grp.Family;
         family = GroupInfo.GetEntityName(family);
         System.Type familytype = Type.GetType(EntityAssemblyqualifiedName.Replace("Account", family), false, true);
         if (familytype != null)
         {
             string famname = familytype.GetDisplayName();
             famname = string.IsNullOrEmpty(famname) ? family : famname;
             if (!MVList.ContainsKey(grp.Family) && !MVList.ContainsValue(famname))
             {
                 MVList.Add(grp.Family, famname);
             }
         }
     }
 }
开发者ID:pebre77,项目名称:PrxS2,代码行数:20,代码来源:GroupTabOptionsPage.ascx.cs

示例5: runTest


//.........这里部分代码省略.........
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_03rf! - Count == " );
                 sblMsg.Append( sl2.Count  );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             strLoc="Loc_141aa";
             for (i=0; i<100; i++) 
             {
                 ++iCountTestcases;
                 sl2.Add (i+100, i);
             }
             if (sl2.Count  != 100) 
             {
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_dhc3! - Count == " );
                 sblMsg.Append( sl2.Count  );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             for (i=0; i<100; i++) 
             {
                 ++iCountTestcases;
                 j = i+100;
                 if (!sl2.ContainsKey ((int)j)) 
                 { 
                     ++iCountErrors;
                     sblMsg.Length =  0 ;
                     sblMsg.Append( "POINTTOBREAK: Error Err_0dj! - ContainsKey failed at i == " );
                     sblMsg.Append( i );
                     Console.Error.WriteLine(  sblMsg.ToString()  );
                     break;
                 }
                 ++iCountTestcases;
                 if (!sl2.ContainsValue (i)) 
                 {
                     ++iCountErrors;
                     sblMsg.Length =  0 ;
                     sblMsg.Append( "POINTTOBREAK: Error Err_hd3! -ContainsValue failed at  i == " );
                     sblMsg.Append( i );
                     Console.Error.WriteLine(  sblMsg.ToString()  );
                     break;
                 }
             }
             strLoc="Loc_346aws";
             ++iCountTestcases;
             en = (IEnumerator) sl2.GetKeyList().GetEnumerator();
             ++iCountTestcases;
             try 
             {
                 Object objThrowAway = en.Current;
                 ++iCountErrors;
                 Console.WriteLine( "Err_002dt, Expected InvalidOperationException to be thrown but nothing was thrown" );
             }
             catch (InvalidOperationException) {}
             catch (Exception exc )
             {
                 ++iCountErrors;
                 Console.Error.WriteLine(  "POINTTOBREAK: Error Err_27dh! - "  + exc.ToString() );
             }
             j = 100;
             en = (IEnumerator) sl2.GetKeyList().GetEnumerator();
         while (en.MoveNext()) 
         {
             ++iCountTestcases;
             i3 = (int) en.Current;
             if (i3 != j) 
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:67,代码来源:co4339getkeylist.cs

示例6: Highlight

        public void Highlight(string[] entities, int qType, bool initQuestion = false, bool mapExploration = false)
        {
            if (initQuestion)
            {
                if (selectedCountries != null)
                    colorRegions(ColorRegionsMode.Reset);
                selectedCountries = new List<string>();
            }

            foreach (var ent in mapEntities)
            {
                ent.Value.Highlighted = false;
                if (initQuestion && (ent.Value.GeoType == GeoType.MarineArea || ent.Value.GeoType == GeoType.Country || ent.Value.GeoType == GeoType.City || ent.Value.GeoType == GeoType.Region || ent.Value.GeoType == GeoType.River || ent.Value.GeoType == GeoType.Lake))
                    ent.Value.Enabled = false;
            }

            if (entities == null)
                return;

            bool mapEntitiesExist = true;
            foreach (string mapEnt in entities)
                if (mapEntities.ContainsKey(mapEnt))
                {
                    if (qType != 2)
                    {
                        if (mapEntities[mapEnt].GeoType == GeoType.City && qType == -3)
                            mapEntities[mapEnt].Enabled = true;
                        else
                        {
                            if (mapEntities[mapEnt].GeoType == GeoType.River && qType == -3)
                                mapEntities[mapEnt].Enabled = true;
                            mapEntities[mapEnt].Highlighted = true;
                        }
                    }
                }
                else
                {
                    mapEntitiesExist = false;
                    break;
                }

            if (qType != -2 && entities != null && mapEntitiesExist)
            {
                this.qType = qType;
                qGeoType = mapEntities[entities[0]].GeoType;
                highlightedEntities.Clear();

                List<string> highlightedEntitiesNames = new List<string>(); //only used for Regions (to find out what country they belong to)
                highlightedEntitiesNames.Add(entities[0]);

                switch (qType)
                {
                    case 2:
                        //select five more random entities (from the nearest neighbors)
                        SortedList<float, string> neighbors = new SortedList<float, string>(); //key is the approximated distance to the region, value is the region's name

                        RectangleF entitiesBox = new RectangleF(mapEntities[entities[0]].Box.X, mapEntities[entities[0]].Box.Y, mapEntities[entities[0]].Box.Width, mapEntities[entities[0]].Box.Height);
                        for (int i = 1; i < entities.Length; i++)
                            addRectangles(ref entitiesBox, mapEntities[entities[i]].Box);

                        foreach (var ent in mapEntities)
                            if (!ArrayContainsString(entities, ent.Key) && !neighbors.ContainsValue(getBaseName(ent.Key)) && ent.Value.GeoType == qGeoType)
                            {
                                string entName = getBaseName(ent.Key);

                                float distance = 0;
                                if (qGeoType == GeoType.River || qGeoType == GeoType.Lake || qGeoType == GeoType.Region)
                                {
                                    //create a Box that includes all segments of the river/lake/region
                                    RectangleF riverBox = new RectangleF(ent.Value.Box.X, ent.Value.Box.Y, ent.Value.Box.Width, ent.Value.Box.Height);
                                    for (int i = 2; mapEntities.ContainsKey(entName + " " + i.ToString()); i++)
                                        addRectangles(ref riverBox, mapEntities[entName + " " + i.ToString()].Box);

                                    distance = distanceBetweenRegions(riverBox, entitiesBox);
                                }
                                else
                                    distance = distanceBetweenRegions(ent.Value.Box, entitiesBox);

                                //remember closest 20 regions
                                if (neighbors.Count < 20)
                                    neighbors.Add(distance, entName);
                                else if (distance < neighbors.Keys[19])
                                {
                                    neighbors.RemoveAt(19);

                                    while (neighbors.ContainsKey(distance)) //prevent two entries having the same distance
                                        distance += 0.000001f;

                                    neighbors.Add(distance, entName);
                                }
                            }

                        //choose 5 random neighbors
                        Random rand = new Random((int)DateTime.Now.Ticks);

                        for (int i = 0; i < 5 && neighbors.Count > 0; i++)
                        {
                            int index = rand.Next(neighbors.Count);

                            if (qGeoType == GeoType.River || qGeoType == GeoType.Lake || qGeoType == GeoType.Region)
//.........这里部分代码省略.........
开发者ID:Winterstark,项目名称:Alot-of-Knowledge,代码行数:101,代码来源:GeoData.cs

示例7: TestGetSyncRootBasic

        public void TestGetSyncRootBasic()
        {
            SortedList arrSon;
            SortedList arrMother;

            Task[] workers;
            Action ts1;
            Action ts2;
            Int32 iNumberOfWorkers = 4;

            SortedList hshPossibleValues;
            IDictionaryEnumerator idic;

            // Vanila test case - testing SyncRoot is not as simple as its implementation looks like. This is the working
            //scenrio we have in mind.
            //1) Create your Down to earth mother SortedList
            //2) Get a synchronized wrapper from it
            //3) Get a Synchronized wrapper from 2)
            //4) Get a synchronized wrapper of the mother from 1)
            //5) all of these should SyncRoot to the mother earth

            arrMother = new SortedList();
            for (int i = 0; i < _iNumberOfElements; i++)
            {
                arrMother.Add("Key_" + i, "Value_" + i);
            }

            Assert.Equal(arrMother.SyncRoot.GetType(), typeof(Object));

            arrSon = SortedList.Synchronized(arrMother);
            _arrGrandDaughter = SortedList.Synchronized(arrSon);
            _arrDaughter = SortedList.Synchronized(arrMother);

            Assert.Equal(arrSon.SyncRoot, arrMother.SyncRoot);

            Assert.Equal(arrSon.SyncRoot, arrMother.SyncRoot);

            Assert.Equal(_arrGrandDaughter.SyncRoot, arrMother.SyncRoot);

            Assert.Equal(_arrDaughter.SyncRoot, arrMother.SyncRoot);

            Assert.Equal(arrSon.SyncRoot, arrMother.SyncRoot);

            //we are going to rumble with the SortedLists with some threads

            workers = new Task[iNumberOfWorkers];
            ts2 = new Action(RemoveElements);
            for (int iThreads = 0; iThreads < iNumberOfWorkers; iThreads += 2)
            {
                var name = "Thread_worker_" + iThreads;
                ts1 = new Action(() => AddMoreElements(name));

                workers[iThreads] = Task.Run(ts1);
                workers[iThreads + 1] = Task.Run(ts2);
            }

            Task.WaitAll(workers);

            //checking time
            //Now lets see how this is done.
            //Either there are some elements or none
            hshPossibleValues = new SortedList();
            for (int i = 0; i < _iNumberOfElements; i++)
            {
                hshPossibleValues.Add("Key_" + i, "Value_" + i);
            }
            for (int i = 0; i < iNumberOfWorkers; i++)
            {
                hshPossibleValues.Add("Key_Thread_worker_" + i, "Thread_worker_" + i);
            }

            //lets check the values if
            idic = arrMother.GetEnumerator();
            while (idic.MoveNext())
            {
                Assert.True(hshPossibleValues.ContainsKey(idic.Key), "Error, Expected value not returned, " + idic.Key);
                Assert.True(hshPossibleValues.ContainsValue(idic.Value), "Error, Expected value not returned, " + idic.Value);
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:79,代码来源:PropertySyncRootTests.cs

示例8: TestGetEnumeratorBasic

        public void TestGetEnumeratorBasic()
        {
            StringBuilder sblMsg = new StringBuilder(99);
            //

            SortedList sl2 = null;

            IDictionaryEnumerator dicen = null;

            StringBuilder sbl3 = new StringBuilder(99);
            StringBuilder sbl4 = new StringBuilder(99);
            StringBuilder sblWork1 = new StringBuilder(99);

            int i3 = 0;
            int i2 = 0;

            int i = 0;
            int j = 0;

            //
            // 	Constructor: Create SortedList using this as IComparer and default settings.
            //
            sl2 = new SortedList(this);

            //  Verify that the SortedList is not null.
            Assert.NotNull(sl2);

            //  Verify that the SortedList is empty.
            Assert.Equal(0, sl2.Count);

            //   Testcase: Set - null key, ArgExc expected
            Assert.Throws<ArgumentNullException>(() =>
                {
                    sl2[null] = 0;
                });

            Assert.Equal(0, sl2.Count);

            //   Testcase: Set - null val
            sl2[(object)100] = (object)null;
            Assert.Equal(1, sl2.Count);

            //   Testcase: vanila Set
            sl2[(object)100] = 1;
            Assert.Equal(1, sl2.Count);

            sl2.Clear();
            Assert.Equal(0, sl2.Count);

            //   Testcase: add key-val pairs
            for (i = 0; i < 100; i++)
            {
                sl2.Add(i + 100, i);
            }

            Assert.Equal(100, sl2.Count);

            for (i = 0; i < 100; i++)
            {
                j = i + 100;

                Assert.True(sl2.ContainsKey((int)j));
                Assert.True(sl2.ContainsValue(i));

                object o2 = sl2[(object)(j)]; //need to cast: Get (object key)
                Assert.NotNull(o2);
                i2 = (int)o2;

                i3 = (int)sl2.GetByIndex(i); //Get (index i)
                Assert.False((i3 != i) || (i2 != i));

                //  testcase: GetEnumerator
                dicen = (IDictionaryEnumerator)sl2.GetEnumerator();

                //  Boundary for Current
                Assert.Throws<InvalidOperationException>(() =>
                                 {
                                     object throwaway = dicen.Current;
                                 }
                );

                j = 0;
                //  go over the enumarator
                while (dicen.MoveNext())
                {
                    //  Current to see the order
                    i3 = (int)dicen.Value;
                    Assert.True(j.Equals(i3));

                    //  Current again to see the same order
                    i3 = (int)dicen.Value;
                    Assert.Equal(i3, j);

                    j++;
                }

                //  Boundary for Current
                Assert.Throws<InvalidOperationException>(() =>
                                 {
                                     object throwaway = dicen.Current;
//.........这里部分代码省略.........
开发者ID:er0dr1guez,项目名称:corefx,代码行数:101,代码来源:GetEnumeratorTests.cs

示例9: GetActiveSubspaces

 public List<int> GetActiveSubspaces()
 {
     SortedList<double, int> sortedList = new SortedList<double, int>();
     sortedList.Add(TimeSyncer.fetch.GetUniverseTime(), TimeSyncer.fetch.currentSubspace);
     foreach (KeyValuePair<string, int> clientSubspace in clientSubspaceList)
     {
         if (!sortedList.ContainsValue(clientSubspace.Value))
         {
             //Normal subspace
             sortedList.Add(TimeSyncer.fetch.GetUniverseTime(clientSubspace.Value), clientSubspace.Value);
         }
     }
     List<int> returnList = new List<int>();
     foreach (KeyValuePair<double, int> subspaceID in sortedList)
     {
         returnList.Add(subspaceID.Value);
     }
     returnList.Reverse();
     return returnList;
 }
开发者ID:GrantTaylor,项目名称:DarkMultiPlayer,代码行数:20,代码来源:WarpWorker.cs

示例10: Dijkstra


//.........这里部分代码省略.........

                                curve.Type = CurveType.Bus;
                                curve.Route = r;

                                // We calculate with 60 seconds of switch over to the bus.
                                r.Time += 60;

                                graph.AddWay(start.ID, curve);
                                graph.AddWay(end.ID, curve);

                                e.Route = r;
                                e.Type = CurveType.Bus;

                                // Take busroute if better
                                if (mode == RouteMode.Fastest && time > e.Route.Time || mode == RouteMode.Shortest && distance > e.Route.Length)
                                {
                                    distance = e.Route.Length;
                                    time = e.Route.Time;
                                    v = Vehicle.Foot;

                                    foreach (Vehicle vehicle in vehicles)
                                        if (vehicle != Vehicle.Foot)
                                            forbiddenVehicles.Insert(current.ID, vehicle);
                                }
                            }

                            graph.RemoveAbstractBus(e);
                            abstractBusses.Remove(e);
                        }

                        time += times.Get(current.ID);
                        double trueDist = distances.Get(current.ID) + distance;

                        if (!solved.ContainsValue(end) && current != end)
                        {
                            if (end.Latitude != 0 && end.Longitude != 0)
                            {
                                if (times.Get(end.ID) == 0 || distances.Get(end.ID) == 0)
                                {
                                    times.Insert(end.ID, double.PositiveInfinity);
                                    distances.Insert(end.ID, double.PositiveInfinity);
                                    vehicleUse.Insert(end.ID, v);
                                }

                                if ((mode == RouteMode.Fastest &&
                                    times.Get(end.ID) > time) ||
                                    (mode == RouteMode.Shortest &&
                                    distances.Get(end.ID) > trueDist))
                                {
                                    times.GetNode(end.ID).Content = time;
                                    distances.GetNode(end.ID).Content = trueDist;
                                    vehicleUse.GetNode(end.ID).Content = v;

                                    if (prevs.GetNode(end.ID).Content == null)
                                        prevs.Insert(end.ID, current);
                                    else
                                        prevs.GetNode(end.ID).Content = current;

                                    if (!unsolved.ContainsValue(end))
                                    {
                                        if (mode == RouteMode.Fastest)
                                        {
                                            // Very bad solution but I couldn't think of a simple better one.
                                            while (unsolved.ContainsKey(times.Get(end.ID)))
                                            {
                                                times.GetNode(end.ID).Content += 0.0000000001;
开发者ID:CPutz,项目名称:MyMap,代码行数:67,代码来源:RouteFinder.cs

示例11: runTest

 public virtual bool runTest()
 {
     Console.Error.WriteLine( "Co4327ContainsValue  runTest() started." );
     String strLoc="Loc_000oo";
     StringBuilder sblMsg = new StringBuilder( 99 );
     int iCountErrors = 0;
     int iCountTestcases = 0;
     SortedList sl2 = null;
     StringBuilder sbl3 = new StringBuilder( 99 );
     StringBuilder sbl4 = new StringBuilder( 99 );
     StringBuilder sblWork1 = new StringBuilder( 99 );
     String str5 = null;
     String str6 = null;
     String str7 = null;
     String s1 = null;
     String s2 = null;
     int[] in4a = new int[9];
     int nCapacity = 100;
     bool bol = false;
     int i = 0;
     try
     {
     LABEL_860_GENERAL:
         do
         {
             strLoc="100cc";
             iCountTestcases++;
             sl2 = new SortedList( this );
             iCountTestcases++;
             if ( sl2 == null )
             {
                 Console.WriteLine( strTest+ "E_101" );
                 Console.WriteLine( strTest+ "SortedList creation failure" );
                 ++iCountErrors;
                 break;
             }
             iCountTestcases++;
             if ( sl2.Count  != 0 )
             {
                 Console.WriteLine( strTest+ "E_102" );
                 Console.WriteLine( strTest+ "New SortedList is not empty" );
                 ++iCountErrors;
             }
             strLoc="Loc_110aa";
             ++iCountTestcases;
             bol = sl2.ContainsKey ("No_Such_Val");
             if (bol) 
             {
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_101bc! - bol == " );
                 sblMsg.Append( bol );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             strLoc="Loc_141aa";
             for (i=0; i<100; i++) 
             {
                 ++iCountTestcases;
                 sblMsg.Length =  0 ;
                 sblMsg.Append("key_");
                 sblMsg.Append(i);
                 s1 = sblMsg.ToString();
                 sblMsg.Length =  0 ;
                 sblMsg.Append("val_");
                 sblMsg.Append(i);
                 s2 = sblMsg.ToString();
                 sl2.Add (s1, s2);
             }
             for (i=0; i < sl2.Count ; i++) 
             {
                 ++iCountTestcases;
                 sblMsg.Length =  0 ;
                 sblMsg.Append("val_");
                 sblMsg.Append(i);
                 s2 = sblMsg.ToString();
                 bol = sl2.ContainsValue (s2);
                 if (!bol) 
                 {
                     ++iCountErrors;
                     sblMsg.Length =  0 ;
                     sblMsg.Append( "POINTTOBREAK: Error Err_1032bc! - bol == " );
                     sblMsg.Append( bol );
                     sblMsg.Append( "; Loop broke at == " );
                     sblMsg.Append( i );
                     Console.Error.WriteLine(  sblMsg.ToString()  );
                 }
             }
             ++iCountTestcases;
             sblMsg.Length =  0 ;
             sblMsg.Append("key_50");
             s1 = sblMsg.ToString();
             sl2.Remove (s1); 
             sblMsg.Length =  0 ;
             sblMsg.Append("val_50");
             s2 = sblMsg.ToString();
             bol = sl2.ContainsKey (s2); 
             if (bol) 
             {
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co4327containsvalue.cs

示例12: runTest


//.........这里部分代码省略.........
                 sblMsg.Append( "POINTTOBREAK: Error Err_03rf! - Count == " );
                 sblMsg.Append( sl2.Count  );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             strLoc="Loc_141aa";
             for (i=0; i<100; i++) 
             {
                 ++iCountTestcases;
                 sl2.Add (i+100, i);
             }
             if (sl2.Count  != 100) 
             {
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_dhc3! - Count == " );
                 sblMsg.Append( sl2.Count  );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             strLoc = "Loc_02tgr";
             for (i=0; i<100; i++) 
             {
                 ++iCountTestcases;
                 j = i+100;
                 if (!sl2.ContainsKey ((int)j)) 
                 { 
                     ++iCountErrors;
                     sblMsg.Length =  0 ;
                     sblMsg.Append( "POINTTOBREAK: Error Err_0dj! - ContainsKey failed at i == " );
                     sblMsg.Append( i );
                     Console.Error.WriteLine(  sblMsg.ToString()  );
                     break;
                 }
                 ++iCountTestcases;
                 if (!sl2.ContainsValue (i)) 
                 {
                     ++iCountErrors;
                     sblMsg.Length =  0 ;
                     sblMsg.Append( "POINTTOBREAK: Error Err_hd3! -ContainsValue failed at  i == " );
                     sblMsg.Append( i );
                     Console.Error.WriteLine(  sblMsg.ToString()  );
                     break;
                 }
                 ++iCountTestcases;
                 try 
                 {
                     Object o2 = sl2[(Object)(j)]; 
                     if (o2 != null)
                         i2 = (int) o2;
                     else 
                     {
                         ++iCountErrors;
                         sblMsg.Length =  0 ;
                         sblMsg.Append( "POINTTOBREAK: Error Err_9dsh! -Get (Object) failed at i == " );
                         sblMsg.Append( i );
                         Console.Error.WriteLine(  sblMsg.ToString()  );
                         break;
                     }
                 }
                 catch (Exception exc) 
                 {
                     Console.Error.WriteLine (exc);
                 }
                 strLoc = "Loc_t02hf";
                 i3 = (int)sl2.GetByIndex(i); 
                 ++iCountTestcases;
                 if ((i3 != i) || (i2 != i)) 
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:67,代码来源:co4338getenumerator.cs

示例13: runTest


//.........这里部分代码省略.........
             iCountTestcases++;
             if(arrSon.SyncRoot != arrMother.SyncRoot) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_874520bdf! Expected value not returned, " + (arrSon.SyncRoot==arrMother.SyncRoot));
             }
             iCountTestcases++;
             if(arrSon.SyncRoot!=arrMother) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_8230fvbd! Expected value not returned, " + (arrSon.SyncRoot==arrMother));
             }
             iCountTestcases++;
             if(arrGrandDaughter.SyncRoot!=arrMother) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_4927fd0fd! Expected value not returned, " + (arrGrandDaughter.SyncRoot==arrMother));
             }
             iCountTestcases++;
             if(arrDaughter.SyncRoot!=arrMother) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_85390gfg! Expected value not returned, " + (arrDaughter.SyncRoot==arrMother));
             }
             iCountTestcases++;
             if(arrSon.SyncRoot != arrMother.SyncRoot) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_234dnvf! Expected value not returned, " + (arrSon.SyncRoot==arrMother.SyncRoot));
             }
             strLoc = "Loc_845230fgdg";
             workers = new Thread[iNumberOfWorkers];
             ts1 = new ThreadStart(AddMoreElements);
             ts2 = new ThreadStart(RemoveElements);
             for(int iThreads=0; iThreads<iNumberOfWorkers;iThreads+=2)
             {
                 strLoc = "Loc_74329fd_" + iThreads;
                 workers[iThreads] = new Thread(ts1);
                 workers[iThreads].Name = "Thread_worker_" + iThreads;
                 workers[iThreads+1] = new Thread(ts2);
                 workers[iThreads+1].Name = "Thread_worker_" + iThreads + 1;
                 workers[iThreads].Start();
                 workers[iThreads+1].Start();
             }
         while(true)
         {
             fLoopExit=false;
             for(int i=0; i<iNumberOfWorkers;i++)
             {
                 if(workers[i].IsAlive)
                     fLoopExit=true;
             }
             if(!fLoopExit)
                 break;
         }
             strLoc = "Loc_7539vfdg";
             iCountTestcases++;
             hshPossibleValues = new SortedList();
             for(int i=0; i<iNumberOfElements; i++)
             {
                 hshPossibleValues.Add("Key_" + i, "Value_" + i);
             }
             for(int i=0; i<iNumberOfWorkers; i++)
             {
                 hshPossibleValues.Add("Key_Thread_worker_" + i, "Thread_worker_" + i);
             }
             if(arrMother.Count>0)
                 Console.WriteLine("Loc_7428fdsg! Adds have it");
             idic = arrMother.GetEnumerator();
         while(idic.MoveNext())
         {
             if(!hshPossibleValues.ContainsKey(idic.Key))
             {
                 iCountErrors++;
                 Console.WriteLine("Err_7429dsf! Expected value not returned, " + idic.Key);
             }
             if(!hshPossibleValues.ContainsValue(idic.Value))
             {
                 iCountErrors++;
                 Console.WriteLine("Err_2487dsf! Expected value not returned, " + idic.Value);
             }
         }
         } while (false);
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co3948get_syncroot.cs

示例14: GetSyncRootBasic

        public void GetSyncRootBasic()
        {
            // Testing SyncRoot is not as simple as its implementation looks like. This is the working
            // scenario we have in mind.
            // 1) Create your Down to earth mother SortedList
            // 2) Get a synchronized wrapper from it
            // 3) Get a Synchronized wrapper from 2)
            // 4) Get a synchronized wrapper of the mother from 1)
            // 5) all of these should SyncRoot to the mother earth

            var sortListMother = new SortedList();
            for (int i = 0; i < NumberOfElements; i++)
            {
                sortListMother.Add("Key_" + i, "Value_" + i);
            }

            Assert.Equal(sortListMother.SyncRoot.GetType(), typeof(object));

            SortedList sortListSon = SortedList.Synchronized(sortListMother);
            _sortListGrandDaughter = SortedList.Synchronized(sortListSon);
            _sortListDaughter = SortedList.Synchronized(sortListMother);

            Assert.Equal(sortListSon.SyncRoot, sortListMother.SyncRoot);
            Assert.Equal(sortListMother.SyncRoot, sortListSon.SyncRoot);

            Assert.Equal(_sortListGrandDaughter.SyncRoot, sortListMother.SyncRoot);
            Assert.Equal(_sortListDaughter.SyncRoot, sortListMother.SyncRoot);
            Assert.Equal(sortListSon.SyncRoot, sortListMother.SyncRoot);

            //we are going to rumble with the SortedLists with some threads
            
            var workers = new Task[4];
            for (int i = 0; i < workers.Length; i += 2)
            {
                var name = "Thread_worker_" + i;
                var action1 = new Action(() => AddMoreElements(name));
                var action2 = new Action(RemoveElements);

                workers[i] = Task.Run(action1);
                workers[i + 1] = Task.Run(action2);
            }

            Task.WaitAll(workers);

            // Checking time
            // Now lets see how this is done.
            // Either there are some elements or none
            var sortListPossible = new SortedList();
            for (int i = 0; i < NumberOfElements; i++)
            {
                sortListPossible.Add("Key_" + i, "Value_" + i);
            }
            for (int i = 0; i < workers.Length; i++)
            {
                sortListPossible.Add("Key_Thread_worker_" + i, "Thread_worker_" + i);
            }

            //lets check the values if
            IDictionaryEnumerator enumerator = sortListMother.GetEnumerator();
            while (enumerator.MoveNext())
            {
                Assert.True(sortListPossible.ContainsKey(enumerator.Key));
                Assert.True(sortListPossible.ContainsValue(enumerator.Value));
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:65,代码来源:SortedListTests.cs

示例15: AddFamiliesToList

 private static void AddFamiliesToList(ref SortedList MVList, PluginType aType)
 {
     System.Collections.Generic.IList<Plugin> aList = PluginManager.GetPluginList(aType, true, false);
     string EntityAssemblyqualifiedName = (typeof(Sage.SalesLogix.Entities.Account)).AssemblyQualifiedName;
     foreach (Plugin grp in aList)
     {
         string family = grp.Family;
         family = GroupInfo.GetEntityName(family);
         System.Type familytype = Type.GetType(EntityAssemblyqualifiedName.Replace("Account", family), false, true);
         if (familytype != null)
         {
             string famname = familytype.GetDisplayName();
             if (!MVList.ContainsKey(grp.Family) && !MVList.ContainsValue(famname))
             {
                 MVList.Add(grp.Family, famname);
             }
         }
     }
 }
开发者ID:RyanTest,项目名称:SalesLogix_Eval,代码行数:19,代码来源:GroupTabOptionsPage.ascx.cs


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