Пример #1
0
    public void SortTest ()
    {            
      IChannel fakeIChannel = Isolate.Fake.Instance<IChannel>();

      Card fakeCard1 =  Isolate.Fake.Instance<Card>();
      Isolate.WhenCalled(() => fakeCard1.Priority).WillReturn(3);

      Card fakeCard2 = Isolate.Fake.Instance<Card>();
      Isolate.WhenCalled(() => fakeCard2.Priority).WillReturn(2);

      Card fakeCard3 = Isolate.Fake.Instance<Card>();
      Isolate.WhenCalled(() => fakeCard3.Priority).WillReturn(1);

      var cardDetails = new List<CardDetail>();
      var card = new CardDetail(1, fakeCard1, fakeIChannel, false, 0);
      cardDetails.Add(card);
      card = new CardDetail(2, fakeCard2, fakeIChannel, false, 0);
      cardDetails.Add(card);
      card = new CardDetail(3, fakeCard3, fakeIChannel, true, 1);
      cardDetails.Add(card);

      cardDetails.Sort();

      List<CardDetail> freeCards =
          cardDetails.Where(t => t.NumberOfOtherUsers == 0 || (t.NumberOfOtherUsers > 0 && t.SameTransponder)).ToList();
      List<CardDetail> availCards = cardDetails.Where(t => t.NumberOfOtherUsers > 0 && !t.SameTransponder).ToList();
    }
Пример #2
0
        /// <summary>
        /// Gets list of all test classes obtained by inspecting all the test assemblies.
        /// </summary>
        private Dictionary<string, List<string>> DiscoverAllTestClasses()
        {
            var assemblies = GetTestAssemblies();

            var testsByAssembly = new Dictionary<string, List<string>>();
            foreach (var assembly in assemblies)
            {
                var testClasses = new List<string>();
                foreach (var t in assembly.GetTypes())
                {
                    foreach (var m in t.GetMethods())
                    {
                        var attributes = m.GetCustomAttributes(typeof(NUnit.Framework.TestAttribute), true);
                        if (attributes.Length > 0)
                        {
                            testClasses.Add(t.FullName);
                            break;
                        }

                    }
                }
                testClasses.Sort();
                testsByAssembly.Add(assembly.GetName().Name, testClasses);
            }
            return testsByAssembly;
        }
Пример #3
0
        public void AllFiltersHaveTests()
        {
            List<Type> tests = this.GetTestClasses();
            List<Type> filters = this.GetFilters();
            List<string> missingTests = new List<string>();

            foreach ( Type filter in filters ) {

                string name = filter.Name + "Tests";

                Type testType = tests.Find( t => t.Name == name );
                if ( testType == null ) {
                    // Test is missing
                    missingTests.Add( filter.Name );

                } else {
                    // Is it testing the right type?
                    FilterBaseTest test = (FilterBaseTest)Activator.CreateInstance( testType );
                    Assert.AreEqual( filter.FullName, test.TestType.FullName );
                }
            }

            missingTests.Sort();

            Assert.AreEqual( 0, missingTests.Count, "Missing tests for these filters: " + string.Join( ", ", missingTests.ToArray() ) );
        }
Пример #4
0
        public void Full()
        {
            Console.WriteLine("Full");
            Init();

            List<string> files = new List<string>(Directory.GetFiles(basePath, "*.rc", SearchOption.AllDirectories));
            files.AddRange(Directory.GetFiles(basePath, "*.red", SearchOption.AllDirectories));
            files.Sort();
            bool allOK = true;
            int c = 0;
            for (int i = 0; i < files.Count; i++)
            {
                for (int j = 0; j < files.Count; j++)
                {
                    try
                    {
                        LoadRunPair(files[i], files[j], c);
                        c++;
                    }
                    catch (EngineDifferException)
                    {
                        Console.WriteLine("\nFailed");
                        allOK = false;
                    }
                    catch (ParserException)
                    {
                        //swallow
                    }
                }
            }
            Console.WriteLine("\nDone");
            if (!allOK)
                throw new EngineDifferException("Some warriors failed.", null);
        }
Пример #5
0
    public void TestSort()
    {
      IdentifiedSpectrum sp1 = new IdentifiedSpectrum();
      sp1.Query.FileScan.LongFileName = "YEAST_0612_G1_SAX_080806_09.17702.17702.2.out";
      new IdentifiedPeptide(sp1) { Sequence = "K.GFFSFATQK.L" };

      IdentifiedSpectrum sp2 = new IdentifiedSpectrum();
      sp2.Query.FileScan.LongFileName = "YEAST_0612_G1_SAX_080806_09.17707.17708.1.out";
      new IdentifiedPeptide(sp2) { Sequence = "K.GFFSFATQK.L" };

      IdentifiedSpectrum sp3 = new IdentifiedSpectrum();
      sp3.Query.FileScan.LongFileName = "YEAST_0612_G1_SAX_080806_09.7707.7708.2.out";
      new IdentifiedPeptide(sp3) { Sequence = "K.GFFSFATQK.L" };

      IdentifiedSpectrum sp4 = new IdentifiedSpectrum();
      sp4.Query.FileScan.LongFileName = "YEAST_0612_G1_SAX_080806_09.7707.7708.2.out";
      new IdentifiedPeptide(sp4) { Sequence = "K.AAAAAAAK.L" };

      List<IIdentifiedSpectrum> spectra = new List<IIdentifiedSpectrum>();
      spectra.Add(sp2);
      spectra.Add(sp1);
      spectra.Add(sp3);
      spectra.Add(sp4);

      spectra.Sort();

      Assert.AreSame(sp4, spectra[0]);
      Assert.AreSame(sp3, spectra[1]);
      Assert.AreSame(sp1, spectra[2]);
      Assert.AreSame(sp2, spectra[3]);
    }
Пример #6
0
        public void Sort_Should_Return_Promotions_OrderedBy_Date_Descending()
        {
            List<Promotion> promotions = new List<Promotion>
            {

                new Promotion
                {
                    RankDate = new System.DateTime(2011, 2, 2, 0, 0, 0, 0)
                },
                new Promotion
                {
                    RankDate = new System.DateTime(2001, 2, 2, 0, 0, 0, 0)
                },
                new Promotion
                {
                    RankDate = new System.DateTime(2009, 2, 2, 0, 0, 0, 0)
                },

                new Promotion
                {
                    RankDate = new System.DateTime(2003, 2, 2, 0, 0, 0, 0)
                },
                new Promotion
                {
                    RankDate = new System.DateTime(2015, 2, 2, 0, 0, 0, 0)
                }
            };

            promotions.Sort();
            Assert.AreEqual( 2015, promotions[0].RankDate.Value.Year);
        }
Пример #7
0
        public void TestStdOutput()
        {
            using (ProcessRunner runner = new ProcessRunner("cmd.exe"))
            {
                StringWriter wtr = new StringWriter();
                StringWriter err = new StringWriter();
                ProcessOutputEventHandler handler =
                        delegate(object o, ProcessOutputEventArgs e)
                        { if (e.Error) err.WriteLine(e.Data); else wtr.WriteLine(e.Data); };

                runner.OutputReceived += handler;

                Assert.AreEqual(0, runner.Run("/C", "dir", "/b", "/on", "/ad-h-s", "c:\\"));
                Assert.AreEqual(String.Empty, err.ToString());

                Assert.AreNotEqual(0, runner.PID);

                StringReader rdr = new StringReader(wtr.ToString());
                List<DirectoryInfo> rootdirs = new List<DirectoryInfo>(new DirectoryInfo("C:\\").GetDirectories());
                rootdirs.Sort(delegate(DirectoryInfo x, DirectoryInfo y) { return StringComparer.OrdinalIgnoreCase.Compare(x.Name, y.Name); });
                foreach (DirectoryInfo di in rootdirs)
                {
                    if ((di.Attributes & (FileAttributes.Hidden | FileAttributes.System)) != 0)
                        continue;
                    Assert.AreEqual(di.Name, rdr.ReadLine());
                }

                Assert.AreEqual(null, rdr.ReadLine());
            }
        }
        public override void SetUp()
        {
            base.SetUp();
            Dir = NewDirectory();
            FieldName = Random().NextBoolean() ? "field" : ""; // sometimes use an empty string as field name
            RandomIndexWriter writer = new RandomIndexWriter(Random(), Dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.KEYWORD, false)).SetMaxBufferedDocs(TestUtil.NextInt(Random(), 50, 1000)));
            Document doc = new Document();
            Field field = NewStringField(FieldName, "", Field.Store.NO);
            doc.Add(field);
            List<string> terms = new List<string>();
            int num = AtLeast(200);
            for (int i = 0; i < num; i++)
            {
                string s = TestUtil.RandomUnicodeString(Random());
                field.StringValue = s;
                terms.Add(s);
                writer.AddDocument(doc);
            }

            if (VERBOSE)
            {
                // utf16 order
                terms.Sort();
                Console.WriteLine("UTF16 order:");
                foreach (string s in terms)
                {
                    Console.WriteLine("  " + UnicodeUtil.ToHexString(s));
                }
            }

            Reader = writer.Reader;
            Searcher1 = NewSearcher(Reader);
            Searcher2 = NewSearcher(Reader);
            writer.Dispose();
        }
Пример #9
0
        public void Test_GetAllFiles_SanityCheck()
        {
            _fileData = TestUtils.GetAnyFileData (FileSize.SMALL_FILE_SIZE);

            int numFilesToSave = TYPICAL_MULTI_VALUE;

            List<ulong> fileIDs = new List<ulong> ();
            for (int i = 0; i < numFilesToSave; ++i) {
                string fileName = TestUtils.GetAnyFileName ();
                DateTime when = DateTime.Now.AddYears (i - numFilesToSave / 2);
                ulong fileID = SaveFileToMfs (ref _mfsOperations, _fileName, _fileNarration, _fileData, when, false);

                fileIDs.Add (fileID);
            }

            List<ulong> allFileIDs = _mfsOperations.File.GetAll ();
            Assert.AreEqual (TYPICAL_MULTI_VALUE, allFileIDs.Count, "Incorrect number of files retrieved.");

            fileIDs.Sort ();
            allFileIDs.Sort ();

            for (int i = 0; i < fileIDs.Count; ++i) {
                Assert.AreEqual (fileIDs[i], allFileIDs[i], "Incorrect file retrieved.");
            }

            foreach (ulong fileID in fileIDs) {
                _mfsOperations.File.Delete (fileID);
            }
        }
		public void LoadAndReplay()
		{
			var dir = new DirectoryInfo(@"C:\Code\AIGames.Challenger\games\texas-hold-em");

			var bot = new ACDCBot();
			bot.Actor.Nodes.Clear();

			foreach (var file in dir.GetFiles("*.log"))
			{
				using (var platform = new ConsolePlatformTester(file))
				{
					platform.DoRun(bot);
				}
			}
			var nodes = new List<Node>(bot.Actor.Nodes);
			nodes.Sort();
			nodes.Save(new FileInfo(@"C:\temp\data.bin"));
			using (var writer = new StreamWriter(@"C:\temp\data.log"))
			{
				foreach (var node in nodes)
				{
					writer.WriteLine(node);
				}
			}
		}
 public void Setup(int maxTasksInPool, int tasksToFork)
 {
     AtomicInteger atomicVal = new AtomicInteger();
     IExecutorService execService = new LimitedTaskExecutorService(maxTasksInPool);
     ICollection<IFuture<int>> futures = new List<IFuture<int>>(tasksToFork);
     for (int i = 0; i < tasksToFork; i++)
     {
         var task = new FutureTask<int>(CallableUtils.FromFunc(() =>
         {
             Thread.Yield();
             Thread.Sleep(7);
             int value = atomicVal.IncrementAndGet();
             Thread.Yield();
             return value;
         }));
         IFuture<int> future = execService.submit(task);
         futures.Add(future);
     }
     var results = new List<int>();
     foreach (IFuture<int> future in futures)
     {
         int value = future.get();
         results.Add(value);
     }
     results.Sort();
     int prevValue = results[0];
     Console.WriteLine(prevValue);
     for (int i = 1; i < results.Count; i++)
     {
         Console.WriteLine(results[i]);
         Assert.AreEqual(prevValue + 1, results[i]);
         prevValue = results[i];
     }
     Assert.AreEqual(atomicVal.Get(), tasksToFork);
 }
Пример #12
0
    /// <summary>Returns at most the 4 closest addresses in order.</summary>
    protected List<Connection> GetClosest(List<Connection> cons)
    {
      List<Connection> closest = new List<Connection>(cons);

      // Since MeasuredLatency could change the duration of our sorting we make
      // a copy as necessary
      Dictionary<Connection, double> latencies = new Dictionary<Connection, double>();

      Comparison<Connection> comparer = delegate(Connection x, Connection y) {
        double lat_x, lat_y;
        if(!latencies.TryGetValue(x, out lat_x)) {
          lat_x = _ncservice.GetMeasuredLatency(x.Address);
          latencies[x] = lat_x;
        }
        if(!latencies.TryGetValue(y, out lat_y)) {
          lat_y = _ncservice.GetMeasuredLatency(y.Address);
          latencies[y] = lat_y;
        }

        // Remember that smaller is better but -1 is bad...
        // If either is smaller than 0 invert the comparison..
        if(lat_x < 0 || lat_y < 0) {
          return lat_y.CompareTo(lat_x);
        } else {
          return lat_x.CompareTo(lat_y);
        }
      };

      closest.Sort(comparer);
      if(closest.Count > 4) {
        closest.RemoveRange(4, closest.Count - 4);
      }
      return closest;
    }
        public void SignatureParameterShouldSortByNameAndValueUsingAscendingByteValueOrdering()
        {
            List<BaseStringParameter> sortedParameters = new List<BaseStringParameter>()
            {
                new BaseStringParameter("a2", "r%20b"),
                new BaseStringParameter("a3", "2%20q"),
                new BaseStringParameter("a3", "a"),
                new BaseStringParameter("b5", "%3D%253D"),
                new BaseStringParameter("c%40", ""),
                new BaseStringParameter("c2", ""),
                new BaseStringParameter("oauth_consumer_key", "9djdj82h48djs9d2"),
                new BaseStringParameter("oauth_nonce", "7d8f3e4a"),
                new BaseStringParameter("oauth_signature_method", "HMAC-SHA1"),
                new BaseStringParameter("oauth_timestamp", "137131201"),
                new BaseStringParameter("oauth_token", "kkk9d7dh3k39sjv7")
            };

            List<BaseStringParameter> parameters = new List<BaseStringParameter>(sortedParameters);
            parameters.Shuffle();

            parameters.Sort(new BaseStringParameterComparer());

            // Since version 2.2, NUnit has been able to compare two single-dimensioned arrays.
            // Two arrays or collections will be treated as equal by Assert.AreEqual if they
            // have the same dimensions and if each of the corresponding elements is equal.
            Assert.That(parameters, Is.EqualTo(sortedParameters));
        }
Пример #14
0
    public void TestSort()
    {
      var mph1 = new IdentifiedSpectrum();
      var peptide1 = new IdentifiedPeptide(mph1);

      var mph2 = new IdentifiedSpectrum();
      var peptide2 = new IdentifiedPeptide(mph2);

      var mpro1 = new IdentifiedProtein("Protein1");
      mpro1.Peptides.Add(peptide1);
      mpro1.Peptides.Add(peptide2);

      var mpro2 = new IdentifiedProtein("Protein2");
      mpro2.Peptides.Add(peptide1);

      var mpro3 = new IdentifiedProtein("Protein3");
      mpro3.Peptides.Add(peptide2);

      var mpros = new List<IdentifiedProtein>();
      mpros.Add(mpro3);
      mpros.Add(mpro2);
      mpros.Add(mpro1);

      mpros.Sort();

      Assert.AreEqual(mpro1, mpros[0]);
      Assert.AreEqual(mpro2, mpros[1]);
      Assert.AreEqual(mpro3, mpros[2]);
    }
        public void AutomaticallyFindRegistryFromAssembly()
        {
            var container = new Container(x =>
            {
                x.Scan(s =>
                {
                    s.AssemblyContainingType<RedGreenRegistry>();
                    s.LookForRegistries();
                });
            });

            var colors = new List<string>();
            foreach (var widget in container.GetAllInstances<IWidget>())
            {
                if (!(widget is ColorWidget))
                {
                    continue;
                }

                var color = (ColorWidget) widget;
                colors.Add(color.Color);
            }

            colors.Sort();
            colors.ShouldHaveTheSameElementsAs("Black", "Blue", "Brown", "Green", "Red", "Yellow");
        }
        public void GetSortedDateTimes_ReturnsCorrectList()
        {
            DateTime dateNow = DateTime.Now;

            var orderedDateIntervals = new List<DateInterval>();
            orderedDateIntervals.Add( new DateInterval( dateNow, dateNow.AddMinutes( 100 )));             // +-----------------------------------------------+
            orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(10), dateNow.AddMinutes(10)));   //   +
            orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(10), dateNow.AddMinutes(10)));   //   +
            orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(10), dateNow.AddMinutes(20)));   //   +---+
            orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(10), dateNow.AddMinutes(30)));   //   +-------+
            orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(20), dateNow.AddMinutes(60)));   //       +----------------------+
            orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(30), dateNow.AddMinutes(60)));   //           +------------------+
            orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(40), dateNow.AddMinutes(50)));   //              +------------+
            orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(42), dateNow.AddMinutes(47)));   //                 +-----+
            orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(45), dateNow.AddMinutes(45)));   //                    +
            orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(70), dateNow.AddMinutes(75)));   //                                  +---+
            orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(90), dateNow.AddMinutes(110)));  //                                          +--------------+
            orderedDateIntervals.Add(new DateInterval(dateNow.AddMinutes(120), dateNow.AddMinutes(140))); //                                                            +-----------+

            var result = orderedDateIntervals.GetSortedDateTimes();

            var correctDateTimes = new List<DateTime>();
            orderedDateIntervals.ForEach(x => correctDateTimes.AddRange(new List<DateTime> { x.Min.Value, x.Max.Value }));
            correctDateTimes.Sort();

            Assert.AreEqual( correctDateTimes, result);
        }
Пример #17
0
        public void TestTriggerSort()
        {
            // build trigger in expected sort order
            ITrigger t1 = TriggerBuilder.Create().WithIdentity("a").Build();
            ITrigger t2 = TriggerBuilder.Create().WithIdentity("b").Build();
            ITrigger t3 = TriggerBuilder.Create().WithIdentity("c").Build();
            ITrigger t4 = TriggerBuilder.Create().WithIdentity("a", "a").Build();
            ITrigger t5 = TriggerBuilder.Create().WithIdentity("a", "b").Build();
            ITrigger t6 = TriggerBuilder.Create().WithIdentity("a", "c").Build();

            List<ITrigger> ts = new List<ITrigger>();
            // add triggers to list in somewhat randomized order
            ts.Add(t5);
            ts.Add(t6);
            ts.Add(t4);
            ts.Add(t3);
            ts.Add(t1);
            ts.Add(t2);

            // sort the list
            ts.Sort();

            // check the order of the list
            Assert.AreEqual(t1, ts[0]);
            Assert.AreEqual(t2, ts[1]);
            Assert.AreEqual(t3, ts[2]);
            Assert.AreEqual(t4, ts[3]);
            Assert.AreEqual(t5, ts[4]);
            Assert.AreEqual(t6, ts[5]);
        }
        public void CorrectlyRemovesItems()
        {
            const int MaxCount = 20;
            var rand = new Random(Seed);
            var items = new List<PriorityQueueItem<int>>(MaxCount);

            for(int count = 3; count < MaxCount; count++)
            {
                var pq = MakeMaxPQ();
                items.Clear();

                // Prepare
                for (int i = 0; i < count; i++)
                    items.Add(pq.Enqueue(rand.Next()));
                // Invert the comparison to get descending order.
                items.Sort((a, b) => b.Item - a.Item);
                // Remove all the middle elements.
                for (int i = 1; i < count - 1; i++)
                    pq.Remove(items[i].Index);

                // Test
                Assert.That(pq.Dequeue() == items[0].Item, Is.True);
                Assert.That(pq.Dequeue() == items[count - 1].Item, Is.True);
            }
        }
        public void TestWithRenumber(int count)
        {
            List<int> correctList = new List<int>();
            Random r = new Random();
            for (int x = 0; x < count; x++)
            {
                correctList.Add(r.Next(10000000));
            }
            CustomSortHelper<int> items = new CustomSortHelper<int>(correctList, (x, y) => x.CompareTo(y) < 0);
            correctList.Sort();

            for (int i = 0; i < Math.Min(count, 100); i++)
            {
                int adder = r.Next(10000000);
                correctList[i] += adder;
                items[i] += adder;
                correctList.Sort();
                items.SortAssumingIncreased(i);

                for (int x = 0; x < count; x++)
                    if (correctList[x] != items[x])
                        throw new Exception();

            }

        }
Пример #20
0
		public void SettingsFolderWithNewerConfig_SortsBeforeOneWithOlderConfig()
		{

			using (var tempFolder = new TemporaryFolder())
			{
				var firstDirPath = Path.Combine(tempFolder.Path, "first");
				var secondDirPath = Path.Combine(tempFolder.Path, "second");
				var firstConfigFile = Path.Combine(firstDirPath, TestCrossPlatformSettingsProvider.UserConfigFileName);
				var secondConfigFile = Path.Combine(secondDirPath, TestCrossPlatformSettingsProvider.UserConfigFileName);
				Directory.CreateDirectory(firstDirPath);
				Directory.CreateDirectory(secondDirPath);
				File.WriteAllText(firstConfigFile, @"nonsense");
				Thread.Sleep(1000); // May help ensure write times are sufficiently different on TeamCity.
				File.WriteAllText(secondConfigFile, @"nonsense"); // second is newer

				var result = TestCrossPlatformSettingsProvider.VersionDirectoryComparison(firstDirPath, secondDirPath);
				Assert.That(result, Is.GreaterThan(0));

				Thread.Sleep(1000); // May help ensure write times are sufficiently different on TeamCity.
				File.WriteAllText(firstConfigFile, @"nonsense"); // now first is newer
				result = TestCrossPlatformSettingsProvider.VersionDirectoryComparison(firstDirPath, secondDirPath);
				Assert.That(result, Is.LessThan(0));

				// A final check to make sure it is really working the way we want
				var list = new List<string>();
				list.Add(secondDirPath);
				list.Add(firstDirPath);
				list.Sort(TestCrossPlatformSettingsProvider.VersionDirectoryComparison);
				Assert.That(list[0], Is.EqualTo(firstDirPath));
			}
		}
Пример #21
0
		public void SettingsFolderWithNoConfig_SortsAfterOneWithConfig()
		{
			// We do two iterations like this to vary whether the (originally) first or last directory lacks
			// the config file. (We can't achieve this reliably by deleting the file because it sometimes
			// takes the system some time to notice that it is gone.)
			for (var which = 0; which < 1; which++)
			{
				using (var tempFolder = new TemporaryFolder())
				{
					var firstDirPath = Path.Combine(tempFolder.Path, "first");
					var secondDirPath = Path.Combine(tempFolder.Path, "second");
					var firstConfigFile = Path.Combine(firstDirPath, TestCrossPlatformSettingsProvider.UserConfigFileName);
					var secondConfigFile = Path.Combine(firstDirPath, TestCrossPlatformSettingsProvider.UserConfigFileName);
					Directory.CreateDirectory(firstDirPath);
					Directory.CreateDirectory(secondDirPath);
					if (which == 0)
						File.WriteAllText(firstConfigFile, @"nonsense");
					else
						File.WriteAllText(secondConfigFile, @"nonsense");

					var list = new List<string>();
					list.Add(secondDirPath);
					list.Add(firstDirPath);
					list.Sort(TestCrossPlatformSettingsProvider.VersionDirectoryComparison);
					if (which == 0)
						Assert.That(list[0], Is.EqualTo(firstDirPath), "first directory has config so should have come first");
					else
						Assert.That(list[0], Is.EqualTo(secondDirPath), "second directory has config so should have come first");
				}
			}
		}
Пример #22
0
 public void TestCompareTo()
 {
     ScoreRow row1 = new ScoreRow("7", "foo", new int[] { 50, 200, 100 });
       ScoreRow row2 = new ScoreRow("7", "foo", new int[] { 200, 200, 50 });
       ScoreRow row3 = new ScoreRow("7", "foo", new int[] { 200, 200, 200 });
       ScoreRow row4 = new ScoreRow("8", "foo", new int[] { 200, 200, 200 });
       ScoreRow row5 = new ScoreRow("7", "fob", new int[] { 200, 200, 200 });
       ScoreRow row6 = new ScoreRow("5", "bar", new int[] { 200, 300, 200 });
       ScoreRow row7 = new ScoreRow("4", "baz", new int[] { 50, 50, 100 });
       ScoreRow row8 = new ScoreRow("3", "baz", new int[] { -1, -1, -1 });
       ScoreRow row9 = new ScoreRow("3", "baz", new int[] { 0, 0, 0 });
       ScoreRow row10 = new ScoreRow("3", "baz", new int[] { 0, -1, -1 });
       ScoreRow row11 = new ScoreRow("9", "baz", new int[] { 50, 100, 50 });
       ScoreRow row12 = new ScoreRow("10", "baz", new int[] { 100, 50, 50 });
       List<ScoreRow> list = new List<ScoreRow>(
       new ScoreRow[] {row1, row2, row3, row4, row5, row6, row7, row8, row9,
                   row10, row11, row12
                  });
       list.Sort();
       Assert.AreEqual(row6, list[0]);
       Assert.AreEqual(row5, list[1]);
       Assert.AreEqual(row3, list[2]);
       Assert.AreEqual(row4, list[3]);
       Assert.AreEqual(row2, list[4]);
       Assert.AreEqual(row1, list[5]);
       Assert.AreEqual(row7, list[6]);
       Assert.AreEqual(row11, list[7]);
       Assert.AreEqual(row12, list[8]);
       Assert.AreEqual(row9, list[9]);
       Assert.AreEqual(row10, list[10]);
       Assert.AreEqual(row8, list[11]);
 }
Пример #23
0
        public void TestComparerFactory()
        {
            ComparerFactory f = new ComparerFactory();

            List<TestClass1> list = new List<TestClass1>();
            list.Add(new TestClass1(5, "1"));
            list.Add(new TestClass1(45, "2"));
            list.Add(new TestClass1(40, "233"));

            list.Sort(f.New<TestClass1>("field1"));

            Assert.IsTrue(list[0].field1 == 5);
            Assert.IsTrue(list[1].field1 == 40);
            Assert.IsTrue(list[2].field1 == 45);

            List<TestClass2> list2 = new List<TestClass2>();
            list2.Add(new TestClass2(new TestClass1(5, "3434")));
            list2.Add(new TestClass2(new TestClass1(45, "4")));
            list2.Add(new TestClass2(new TestClass1(10, "342334")));

            list2.Sort(f.New<TestClass2>("class1.field1"));

            Assert.IsTrue(list2[0].class1.field1 == 5);
            Assert.IsTrue(list2[1].class1.field1 == 10);
            Assert.IsTrue(list2[2].class1.field1 == 45);
        }
 private List<CodecMatch> GetSoretedList(params CodecMatch[] codecs)
 {
     var list = new List<CodecMatch>();
     list.AddRange(codecs);
     list.Sort();
     list.Reverse();//we want from higher to smaller
     return list;
 }
        public void Add_NoCase_yz_27_proof()
        {
            var list = new List<string> {" yz", "aaa"};
            list.Sort((x,y) => System.String.Compare(x, y, System.StringComparison.Ordinal));

            Assert.AreEqual(" yz", list[0]);
            Assert.AreEqual("aaa", list[1]);
        }
Пример #26
0
 public void SimpleComparer()
 {
     IList<string> list = new List<string> { "3", "2", "1", "4" };
     list.Sort(StringComparer.Ordinal);
     Assert.AreEqual(list[0], "1");
     Assert.AreEqual(list[1], "2");
     Assert.AreEqual(list[2], "3");
     Assert.AreEqual(list[3], "4");
 }
Пример #27
0
        public IEnumerable<string> readFiles(string searchString)
        {
            var list = new List<string>();
            thePackage.ForData(searchString, (name, stream) => list.Add(stream.ReadAllText()));

            list.Sort();

            return list;
        }
Пример #28
0
 public void Simple()
 {
     IList<int> list = new List<int> { 3, 2, 1, 4 };
     list.Sort();
     Assert.AreEqual(list[0], 1);
     Assert.AreEqual(list[1], 2);
     Assert.AreEqual(list[2], 3);
     Assert.AreEqual(list[3], 4);
 }
Пример #29
0
 public void TestGetBoolUniqueness()
 {
     List<bool> vs = new List<bool>();
     for (int i=0; i<1000; i++) {
         vs.Add(Rand.GetBool());
     }
     vs.Sort();
     Assert.AreNotEqual(vs[0], vs[vs.Count-1]);
 }
Пример #30
0
        public IEnumerable<string> readFiles(string searchString)
        {
            var list = new List<string>();
            ((IPackageInfo)thePackage).ForFiles(BottleFiles.DataFolder, searchString, (name, stream) => list.Add(stream.ReadAllText()));

            list.Sort();

            return list;
        }