예제 #1
0
파일: UnitTest1.cs 프로젝트: bmdub/AutoStat
        public void NoKeyTest()
        {
            var autostat = new AutoStat <TestRecord>();

            int count = 1_000;

            for (int i = 0; i < count; i++)
            {
                TestRecord record = new TestRecord()
                {
                    Name                = "John" + i.ToString().PadLeft(6, '0'),
                    Weight              = count - (i / (count - i)),
                    ID                  = i,
                    TransactionID       = Guid.NewGuid(),
                    NetWorth            = 5000,
                    SeenDate            = DateTime.Now,
                    OtherDate           = DateTimeOffset.Now,
                    PocketChange        = new decimal(0.01) * new decimal(i),
                    TimeSpent           = TimeSpan.FromMinutes(60),
                    CarColor            = Color.Red,
                    SomeObject          = new object(),
                    SometimesNullObject = i % 2 == 0 ? null : new object()
                };

                autostat.Collect(record);
            }

            autostat.GetStatsComparedTo(autostat);
        }
예제 #2
0
파일: UnitTest1.cs 프로젝트: bmdub/AutoStat
        public void ComparedStatsWithKeyTest()
        {
            var autostat = new AutoStat <TestRecord>(keyName: "id");

            int count = 1_000;

            for (int i = 0; i < count; i++)
            {
                TestRecord record = new TestRecord()
                {
                    Name                = "John" + i.ToString().PadLeft(6, '0'),
                    Weight              = count - (i / (count - i)),
                    ID                  = i,
                    TransactionID       = Guid.NewGuid(),
                    NetWorth            = 5000,
                    SeenDate            = DateTime.Now,
                    OtherDate           = DateTimeOffset.Now,
                    PocketChange        = new decimal(0.01) * new decimal(i),
                    TimeSpent           = TimeSpan.FromMinutes(60),
                    CarColor            = Color.Red,
                    SomeObject          = new object(),
                    SometimesNullObject = i % 2 == 0 ? null : new object()
                };

                autostat.Collect(record);
            }

            var autostat2 = new AutoStat <TestRecord>(keyName: "id");

            for (int i = 0; i < count; i++)
            {
                TestRecord record = new TestRecord()
                {
                    Name                = "John" + i.ToString().PadLeft(6, '0'),
                    Weight              = count - (i / (count - i)),
                    ID                  = i,
                    TransactionID       = Guid.NewGuid(),
                    NetWorth            = 5000,
                    SeenDate            = DateTime.Now,
                    OtherDate           = DateTimeOffset.Now,
                    PocketChange        = new decimal(0.01) * new decimal(i),
                    TimeSpent           = TimeSpan.FromMinutes(60),
                    CarColor            = Color.Red,
                    SomeObject          = new object(),
                    SometimesNullObject = i % 2 == 0 ? null : new object()
                };

                autostat2.Collect(record);
            }

            var comparedStats = autostat2.GetStatsComparedTo(autostat);

            Assert.True(comparedStats.Where(stat => stat.Name.Contains("Sample") && stat.IsDifferent && stat.MemberName == "TransactionID").Any());

            //...
        }
예제 #3
0
파일: Program.cs 프로젝트: bmdub/AutoStat
        static void Main(string[] args)
        {
            //var config = new TestConfiguration(SelectionMode.Attribute, Configuration.DefaultStatCollectors.Append("TestStatCollector"));
            var config = new TestConfiguration(SelectionMode.All, Configuration.DefaultStatCollectors.Append("TestStatCollector"));

            //var autoStat1 = new AutoStat<Host>(config);
            var autoStat1 = new AutoStat <Host>(keyName: "id");
            //var autoStat2 = new AutoStat<Host>(config);
            var autoStat2 = new AutoStat <Host>(keyName: "id");

            Random random      = new Random();
            int    recordCount = 1_000_000;

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            for (int i = 0; i < recordCount; i++)
            {
                Host record = new Host()
                {
                    Name         = "Wyatt" + i.ToString().PadLeft(6, '0'),
                    SerialNumber = i,
                    Id           = i,
                    Uptime       = TimeSpan.FromMinutes(i),
                    PokerMoney   = new decimal(0.01) * new decimal(i),
                    DeathCount   = recordCount - (i / (recordCount - i)),
                    Awareness    = Awareness.NotAlive,
                    Escaped      = random.Next(0, 2) == 1
                };

                autoStat1.Collect(record);
            }
            Console.WriteLine(stopwatch.Elapsed);
            //return;
            var recordStats1 = autoStat1.GetStats();

            Console.Write(recordStats1.ToTextFormat());
            //recordStats = recordStats.Where(stat => stat.MemberName == "SerialNumber").ToRecordStats();
            Console.Write(recordStats1.ToTextTableFormat(Console.WindowWidth));
            //recordStats1.OpenCsvInPowershell("stats.csv");


            for (int i = 0; i < recordCount; i++)
            {
                Host record = new Host()
                {
                    Name         = "Wyatt" + i.ToString().PadLeft(6, '0'),
                    SerialNumber = i + recordCount,
                    Id           = i,
                    Uptime       = TimeSpan.FromMinutes(i),
                    PokerMoney   = new decimal(0.02) * new decimal(i),
                    DeathCount   = recordCount - (i / (recordCount - i)),
                    Awareness    = random.Next(0, 2) == 1 ? Awareness.NotAlive : Awareness.Alive,
                    Escaped      = true
                };

                autoStat2.Collect(record);
            }

            var recordStats2 = autoStat2.GetStats();

            Console.Write(recordStats2.ToTextFormat());
            Console.Write(recordStats2.ToTextTableFormat(Console.WindowWidth));
            //recordStats1.OpenCsvInPowershell("stats.csv");

            var recordStats3 = autoStat1.GetStatsComparedTo(autoStat2)
                               .HighlightWhen(stat => stat.DiffPct >= .30);

            Console.Write(recordStats3.ToTextFormat());
            Console.Write(recordStats3.ToTextTableFormat(Console.WindowWidth));
            //recordStats1.OpenCsvInPowershell("stats.csv");

            Console.ReadKey();
        }