Example #1
0
 protected void AssertFirstMove(string expected, List<List<MoveDesc>> actual)
 {
     Assert.IsNotNull(actual);
     Assert.IsTrue(actual.Count > 0);
     Assert.IsTrue(actual.TrueForAll(x => x.Count > 0));
     actual.ForEach(x => Assert.AreEqual(expected, x[0].ToString(
         Notation.LongAlgebraic)));
 }
        public void TestHandToStringMethod()
        {
            var rndNumber = new Random();
            var listOfCards = new List<ICard>();

            for (int i = 0; i < 5; i++)
            {
                CardFace rndCardFace = (CardFace)rndNumber.Next(2, 15);
                CardSuit rndCardSuit = (CardSuit)rndNumber.Next(1, 5);

                listOfCards.Add(new Card(rndCardFace, rndCardSuit));
            }
            Hand randomHand = new Hand(listOfCards);
            Assert.IsTrue(listOfCards.TrueForAll(x => randomHand.ToString().IndexOf(x.ToString()) > 0));
        }
        public async Task TestBachingPostPointsAsync()
        {
            try
            {
                var client = new InfluxDBClient (influxUrl, dbUName, dbpwd);

                var points = new List<IInfluxDatapoint> ();

                var today = DateTime.Now.ToShortDateString ();
                var now = DateTime.Now.ToShortTimeString ();
                var start = DateTime.Now.AddDays (-5);
                var end = DateTime.Now;

                for ( int i = 0; i < 5000; i++ )
                {
                    var valDouble = new InfluxDatapoint<double> ();
                    valDouble.UtcTimestamp = DataGen.RandomDate (start, end);
                    valDouble.Tags.Add ("TestDate", today);
                    valDouble.Tags.Add ("TestTime", now);
                    valDouble.Fields.Add ("Doublefield", DataGen.RandomDouble ());
                    valDouble.Fields.Add ("Doublefield2", DataGen.RandomDouble ());
                    valDouble.MeasurementName = measurementName;
                    valDouble.Precision = (TimePrecision) ( DataGen.RandomInt () % 6 ) + 1;

                    var valInt = new InfluxDatapoint<int> ();
                    valInt.UtcTimestamp = DataGen.RandomDate (start, end);
                    valInt.Tags.Add ("TestDate", today);
                    valInt.Tags.Add ("TestTime", now);
                    valInt.Fields.Add ("Intfield", DataGen.RandomInt ());
                    valInt.Fields.Add ("Intfield2", DataGen.RandomInt ());
                    valInt.MeasurementName = measurementName;
                    valInt.Precision = (TimePrecision) ( DataGen.RandomInt () % 6 ) + 1;

                    var valBool = new InfluxDatapoint<bool> ();
                    valBool.UtcTimestamp = DataGen.RandomDate (start, end);
                    valBool.Tags.Add ("TestDate", today);
                    valBool.Tags.Add ("TestTime", now);
                    valBool.Fields.Add ("Booleanfield", DateTime.Now.Ticks % 2 == 0);
                    valBool.MeasurementName = measurementName;
                    valBool.Precision = (TimePrecision) ( DataGen.RandomInt () % 6 ) + 1;

                    var valString = new InfluxDatapoint<string> ();
                    valString.UtcTimestamp = DataGen.RandomDate (start, end);
                    valString.Tags.Add ("TestDate", today);
                    valString.Tags.Add ("TestTime", now);
                    valString.Fields.Add ("Stringfield", DataGen.RandomString ());
                    valString.MeasurementName = measurementName;
                    valString.Precision = (TimePrecision) ( DataGen.RandomInt () % 6 ) + 1;


                    points.Add (valString);
                    points.Add (valInt);
                    points.Add (valDouble);
                    points.Add (valBool);
                }

                var r = await client.PostPointsAsync (dbName, points);
                Assert.IsTrue (points.TrueForAll (p => p.Saved == true), "PostPointsAsync did not save all points");

            }
            catch ( Exception e )
            {

                Assert.Fail ("Unexpected exception of type {0} caught: {1}",
                            e.GetType (), e.Message);
                return;
            }
        }
        public void TestUnLink()
        {
            LogicContainer_Accessor target = new LogicContainer_Accessor();
            List<CounterComponent> counters = new List<CounterComponent>()
            {
                new NoneCounter(),
                new DraweableCounter(),
                new BothCounter(),
                new UpdateableCounter(),
            };

            foreach (var item in counters)
                target.Add(item);

            target.Remove(counters[0]);

            Assert.AreEqual(3, counters[0].CountRemoved);
            counters.RemoveAt(0);

            Assert.IsTrue(counters.TrueForAll(item => item.CountRemoved == 1));
        }
        public void TransactionalStack3()
        {
            var stack = new TransactionalStack<int>();

            stack.Push(1);
            stack.Push(2);
            stack.Push(3);

            var t1 = stack.BeginTransaction();
            var t2 = stack.BeginTransaction();

            t1.Push(4);
            t2.Push(5);

            t1.Commit();
            AssertionHelpers.AssertThrows<Psimulex.Core.Exceptions.InvalidTransactionException>(() => t2.Commit());

            Assert.AreEqual(4, stack.Pop());
            Assert.AreEqual(3, stack.Pop());
            Assert.AreEqual(2, stack.Pop());
            Assert.AreEqual(1, stack.Pop());

            var transactions = new List<StackTransaction<int>>();
            for (int i = 0; i < 100; ++i)
            {
                transactions.Add(stack.BeginTransaction());
            }

            transactions[22].Push(9);
            transactions[22].Commit();

            transactions.TrueForAll(t => t.Status == TransactionStates.Invalid || t.Status == TransactionStates.Committed);
            transactions.ForEach(t => AssertionHelpers.AssertThrows<Psimulex.Core.Exceptions.InvalidTransactionException>(() => t.Commit()));
        }
 public void DirectoryTree_TestWithFileSearch()
 {
     DirectoryTree tree = new DirectoryTree(baseDirName, "file*");
     List<String> files = new List<string>();
     tree.OnFoundFile +=
         file => {
             var ff = File.OpenRead(file.FullName);
             if (FileSearch.searchInFile(ff, Encoding.UTF8.GetBytes("словоо")))
                 files.Add(file.Name);
         };
     tree.run();
     Assert.IsFalse(files.TrueForAll(x => x != file1Name));
     Assert.IsFalse(files.TrueForAll(x => x != file4Name));
     Assert.IsTrue(files.TrueForAll(x => x != file2Name));
     Assert.IsTrue(files.TrueForAll(x => x != file3Name));
 }
        public void TestLink()
        {
            LogicContainer_Accessor target = new LogicContainer_Accessor();
            List<CounterComponent> counters = new List<CounterComponent>()
            {
                new NoneCounter(),
                new DraweableCounter(),
                new BothCounter(),
                new UpdateableCounter(),
            };

            foreach (var item in counters)
                target.Add(item);

            Assert.IsTrue(counters.TrueForAll(item => item.CountAdded == 3));
        }
 public void DirectoryTree_Test2()
 {
     DirectoryTree tree = new DirectoryTree(baseDirName, "file*");
     List<String> files = new List<string>();
     tree.OnFoundFile += x => files.Add(x.Name);
     tree.run();
     Assert.IsTrue(!files.TrueForAll(x => x != file1Name));
     Assert.IsTrue(!files.TrueForAll(x => x != file2Name));
     Assert.IsTrue(!files.TrueForAll(x => x != file3Name));
     Assert.IsTrue(!files.TrueForAll(x => x != file4Name));
 }
 private static void CheckInList(List<string> inList, List<string> expectedInList)
 {
     inList.Sort();
     expectedInList.Sort();
     Console.WriteLine(@"Znalezione pliki:");
     foreach (string znalezionyPlik in inList)
         Console.WriteLine(znalezionyPlik);
     Console.WriteLine(@"Spodziewane pliki:");
     foreach (var znalezionyPlik in expectedInList)
         Console.WriteLine(znalezionyPlik);
     Assert.IsTrue(inList.Count == expectedInList.Count && inList.TrueForAll(expectedInList.Contains),
                   "Błąd przygotowania testu: zawartość folderu testowego nie zgadza się z przewidywaną.");
 }
Example #10
0
 private bool CompareHookLists(List<Hook> expected, List<Hook> actual)
 {
     return
         expected == actual ||
         (expected.Count == actual.Count &&
         expected.TrueForAll(e => CompareHooks(e, actual[expected.IndexOf(e)])));
 }
        public void QuickPulseTelemetryModuleSupportsMultipleTelemetryProcessorsForSingleConfiguration()
        {
            // ARRANGE
            var configXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <ApplicationInsights xmlns=""http://schemas.microsoft.com/ApplicationInsights/2013/Settings"">
              <InstrumentationKey>some ikey</InstrumentationKey>
              <TelemetryModules>
            <Add Type=""Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector""/>
              </TelemetryModules>
              <TelemetryProcessors>
            <Add Type=""Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector""/>
              </TelemetryProcessors>
            </ApplicationInsights>";

            File.WriteAllText(this.configFilePath, configXml);

            var config = TelemetryConfiguration.Active;

            // ACT
            var telemetryProcessors = new List<IQuickPulseTelemetryProcessor>();
            const int TelemetryProcessorCount = 4;
            for (int i = 0; i < TelemetryProcessorCount; i++)
            {
                // this recreates config.TelemetryProcessors collection, and all its members are reinstantiated
                var builder = config.TelemetryProcessorChainBuilder;
                builder = builder.Use(current => new SimpleTelemetryProcessorSpy());
                builder.Build();

                telemetryProcessors.Add(config.TelemetryProcessors.OfType<QuickPulseTelemetryProcessor>().Single());
            }

            // ASSERT
            var module = TelemetryModules.Instance.Modules.OfType<QuickPulseTelemetryModule>().SingleOrDefault();
            var registeredProcessors = QuickPulseTestHelper.GetTelemetryProcessors(module);

            Assert.AreEqual(TelemetryProcessorCount + 1, registeredProcessors.Count);  // one was there after the initial configuration loading
            Assert.IsTrue(telemetryProcessors.TrueForAll(registeredProcessors.Contains));
        }
        public void DrawRasterTest()
        {
            IRasterControlView View = MockRepository.GenerateStub<IRasterControlView>();
            View.Resolution = 100;
            View.RasterWidth = 1;
            View.IsCartesian = true;
            View.BB = new Rect(0, 0, 10, 10);
            View.CoordinateTransform = new TikzEdt.Parser.TikzMatrix();

            RasterControlModel target = new RasterControlModel(View);
            List<Point> lstpts = new List<Point>();
            List<double> lstrads = new List<double>();
            Action<Point, Point> LineDrawMethod = (p1,p2)=>lstpts.Add(p1);
            Action<double, double> EllipseDrawMethod = (r1,r2)=>lstrads.Add(r1); 
            target.DrawRaster(LineDrawMethod, EllipseDrawMethod);
            Assert.IsTrue( lstpts.TrueForAll(p=> p.X == Math.Round(p.X) &&   p.Y == Math.Round(p.Y)));
            Assert.AreEqual(0, lstrads.Count);
        }