Beispiel #1
0
        public void SaltSize()
        {
            var sizes = new List<int>();

            for (int i = 0; i < 100; i++)
            {
                var salt = Current.GenerateSalt(Int32.MaxValue);

                sizes.Add(salt.Length);
            }

            Assert.IsTrue(sizes.Max() <= 33, "Max length = " + sizes.Max());
        }
Beispiel #2
0
        public void HashSize()
        {
            var sizes = new List<int>();

            string salt;
            for (int i = 0; i < 100; i++)
            {
                var hash = Current.SecureHash(Convert.ToBase64String(Current.Random(32)), out salt);

                sizes.Add(hash.Length);
            }

            Assert.IsTrue(sizes.Max() <= 32, "hash.Length = " + sizes.Max());
        }
Beispiel #3
0
        public void Should38()
        {
            var times = new List<long>();

            var lines = File.ReadAllLines("C:\\tmp\\badphonenumber-clean.log");
            foreach (var line in lines)
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var isValidNumber = IsValidNumber(line.Trim());
                stopwatch.Stop();
                if (isValidNumber)
                {
                    Console.WriteLine("{0}", line);
                }
                times.Add(stopwatch.ElapsedMilliseconds);
                Thread.Sleep(TimeSpan.FromMilliseconds(500));
            }

            var average = times.Average();
            var count = times.Count;
            var sum = times.Sum();
            var max = times.Max();
            Console.WriteLine("{0} ms. {1} numbers. {2} sum. {3} max", average, count, sum, max);
        }
        public void Can_get_lots_of_records_with_new_instantiation_every_time_test()
        {
            var times = new List<double>();

            for (int i = 0; i < 40; ++i)
            {
                var sw = Stopwatch.StartNew();
                var dapperDriver = new DapperDriver();
                var rows = dapperDriver.GetLotsOfRecords<TransactionHistory>();

                Assert.That(rows, Is.Not.Null);
                Assert.That(rows.Count(), Is.GreaterThan(0));

                sw.Stop();

                times.Add(sw.ElapsedMilliseconds);
                Console.WriteLine("took {0} ms to get {1} records",
                    sw.ElapsedMilliseconds,
                    rows.Count());
            }

            Console.WriteLine("average: {0}, min: {1}, max: {2}",
                times.Average(),
                times.Min(),
                times.Max());

            var timesSansMinAndMax = new List<double>();
            timesSansMinAndMax.AddRange(times);
            timesSansMinAndMax.Remove(timesSansMinAndMax.Min());
            timesSansMinAndMax.Remove(timesSansMinAndMax.Max());
            Console.WriteLine("average sans min & max: {0}",
                timesSansMinAndMax.Average());
        }
        public void Can_get_few_records_test()
        {
            var efDriver = new EFDriver();
            var times = new List<double>();

            for (int i = 0; i < 100; ++i)
            {
                var sw = Stopwatch.StartNew();
                var rows = efDriver.GetAFewRecords();

                Assert.That(rows, Is.Not.Null);
                Assert.That(rows.Count(), Is.GreaterThan(0));

                sw.Stop();

                times.Add(sw.ElapsedMilliseconds);
                Console.WriteLine("took {0} ms to get {1} records",
                    sw.ElapsedMilliseconds,
                    rows.Count());
            }

            Console.WriteLine("average: {0}, min: {1}, max: {2}, std dev: {3}, median: {4}",
                times.Average(),
                times.Min(),
                times.Max(),
                times.StandardDeviation(),
                times.Median());

            var timesSansMinAndMax = new List<double>();
            timesSansMinAndMax.AddRange(times);
            timesSansMinAndMax.Remove(timesSansMinAndMax.Min());
            timesSansMinAndMax.Remove(timesSansMinAndMax.Max());
            Console.WriteLine("average sans min & max: {0}",
                timesSansMinAndMax.Average());
        }
        public void Can_get_lots_of_records_with_new_instantiation_every_time_test()
        {
            var times = new List<double>();

            for (int i = 0; i < 40; ++i)
            {
                var sw = Stopwatch.StartNew();
                var efDriver = new EFDriver();
                var rows = efDriver.GetLotsOfRecords();

                Assert.That(rows, Is.Not.Null);
                Assert.That(rows.Count(), Is.GreaterThan(0));

                sw.Stop();

                times.Add(sw.ElapsedMilliseconds);
                Console.WriteLine("took {0} ms to get {1} records",
                    sw.ElapsedMilliseconds,
                    rows.Count());
            }

            Console.WriteLine("average: {0}, min: {1}, max: {2}, std dev: {3}",
                times.Average(),
                times.Min(),
                times.Max(),
                times.StandardDeviation());
        }
Beispiel #7
0
        public void TestNameTest()
        {
            var ints = new List<int> {1, 2, 3, 4, 5, 6};

            var filtered = ints.Where(x => x >= ints.Max() - 2);

            Assert.IsTrue(new[]{4,5,6}.SequenceEqual(filtered));
        }
Beispiel #8
0
        private static ulong GetMaxPrimeFactorFor(ulong number)
        {
            var primeFactors = new List<ulong>(0);

            for (ulong i = number; i * i < number; i++)
            {
                if (!IsPrime(i)) continue;

                if (number % i != 0) continue;

                primeFactors.Add(i);
            }

            return primeFactors.Max();
        }
        public void AggregatesTicksIntoSecondBars()
        {
            var timeProvider = new ManualTimeProvider(TimeZones.NewYork);
            var enumerator = new TradeBarBuilderEnumerator(Time.OneSecond, TimeZones.NewYork, timeProvider);

            // noon new york time
            var currentTime = new DateTime(2015, 10, 08, 12, 0, 0);
            timeProvider.SetCurrentTime(currentTime);

            // add some ticks
            var ticks = new List<Tick>
            {
                new Tick(currentTime, "SPY", 199.55m, 199, 200) {Quantity = 10},
                new Tick(currentTime, "SPY", 199.56m, 199.21m, 200.02m) {Quantity = 5},
                new Tick(currentTime, "SPY", 199.53m, 198.77m, 199.75m) {Quantity = 20},
                new Tick(currentTime, "SPY", 198.77m, 199.75m) {Quantity = 0},
                new Tick(currentTime, "SPY", 199.73m, 198.77m, 199.75m) {Quantity = 20},
                new Tick(currentTime, "SPY", 198.77m, 199.75m) {Quantity = 0},
            };

            foreach (var tick in ticks)
            {
                enumerator.ProcessData(tick);
            }

            // even though no data is here, it will still return true
            Assert.IsTrue(enumerator.MoveNext());
            Assert.IsNull(enumerator.Current);

            // advance a second
            currentTime = currentTime.AddSeconds(1);
            timeProvider.SetCurrentTime(currentTime);

            Assert.IsTrue(enumerator.MoveNext());
            Assert.IsNotNull(enumerator.Current);

            // in the spirit of not duplicating the above code 5 times (OHLCV, we'll assert these ere as well)
            var bar = (TradeBar)enumerator.Current;
            Assert.AreEqual(currentTime.AddSeconds(-1), bar.Time);
            Assert.AreEqual(currentTime, bar.EndTime);
            Assert.AreEqual("SPY", bar.Symbol.Value);
            Assert.AreEqual(ticks.First().LastPrice, bar.Open);
            Assert.AreEqual(ticks.Max(x => x.LastPrice), bar.High);
            Assert.AreEqual(ticks.Min(x => x.LastPrice), bar.Low);
            Assert.AreEqual(ticks.Last().LastPrice, bar.Close);
            Assert.AreEqual(ticks.Sum(x => x.Quantity), bar.Volume);
        }
Beispiel #10
0
        private List<ProteinSpectrumMatch> MergePrsm(List<ProteinSpectrumMatch> targetList)
        {
            //var sortedList = targetList.OrderBy(prsm => prsm.ScanNum).ToList();
            //var minScan = sortedList.First().ScanNum;
            var maxScan = targetList.Max(prsm => prsm.ScanNum);

            var ret = new ProteinSpectrumMatch[maxScan + 1];
            foreach (var prsm in targetList)
            {
                var scan = prsm.ScanNum;

                if (ret[scan] == null)
                {
                    ret[scan] = prsm;
                }
                else
                {
                    if (prsm.SpectralEvalue < ret[scan].SpectralEvalue)
                        ret[scan] = prsm;
                }
            }

            return ret.Where(prsm => prsm != null).ToList();
        }
        public void maximum_inflight_is_respected(int limit)
        {
            var counts = new List<int>();
            long completed = 0;
            var _lock = new object();

            // ReSharper disable AccessToModifiedClosure
            _subject.AddConsumer(s => {
                Thread.Sleep(15);
                lock (_lock) { counts.Add(_subject.CurrentInflight()); }
                Interlocked.Increment(ref completed);
                Thread.Sleep(15);
            });
            // ReSharper restore AccessToModifiedClosure

            _subject.SetMaximumInflight(limit);
            _subject.Start();

            const int runs = 100;
            for (int i = 0; i < runs; i++) { _subject.AddWork(""); }

            while (Interlocked.Read(ref completed) < runs)
            {
                Thread.Sleep(500);
            }
            _subject.Stop();

            Assert.That(counts.Count(), Is.GreaterThan(0), "No actions ran");
            Assert.That(counts.Min(), Is.GreaterThan(0), "Inflight count is invalid");
            Assert.That(counts.Max(), Is.LessThanOrEqualTo(limit), "More workers run in parallel than limit");
        }
        public void WriteCommandList_should_include_all_commands_and_descriptions()
        {
            //  arrange
            var commandList = new List<ICommand> {
                new MockCommand1(),
                new MockCommand1()
            };
            int maxCommandNameLength = commandList.Max(x => x.CommandName.Length);

            //  act
            _helpWriter.WriteCommandList(commandList);

            //  assert
            string expectedOutput = "\r\nAvailable commands:\r\n" +
                                    "  " + commandList[0].CommandName.PadRight(maxCommandNameLength + 4) + commandList[0].Description + "\r\n" +
                                    "  " + commandList[1].CommandName.PadRight(maxCommandNameLength + 4) + commandList[1].Description + "\r\n";
            Assert.AreEqual(expectedOutput, _logger.Output);
        }
Beispiel #13
0
		public void BenchSingleAdd()
		{
			Database.RegisterDataObject(typeof(TestTable));
			Database.RegisterDataObject(typeof(TestTableRelations));
			Database.RegisterDataObject(typeof(TestTableRelationsEntries));

			Database.DeleteObject(Database.SelectAllObjects<TestTable>());
			Database.DeleteObject(Database.SelectAllObjects<TestTableRelations>());
			Database.DeleteObject(Database.SelectAllObjects<TestTableRelationsEntries>());
			
			Assert.IsEmpty(Database.SelectAllObjects<TestTable>(), "Database shouldn't have any record For TestTable.");
			Assert.IsEmpty(Database.SelectAllObjects<TestTableRelations>(), "Database shouldn't have any record For TestTable.");
			Assert.IsEmpty(Database.SelectAllObjects<TestTableRelationsEntries>(), "Database shouldn't have any record For TestTable.");
			
			var objs = Enumerable.Range(0, 100).Select(i => new TestTable { TestField = string.Format("Bench Single Add '{0}'", i) }).ToArray();

			var times = new List<long>();
			foreach (var obj in objs)
			{
				var stopWatch = Stopwatch.StartNew();
				Database.AddObject(obj);
				stopWatch.Stop();
				times.Add(stopWatch.ElapsedMilliseconds);
			}
						
			var relationObjs = Enumerable.Range(0, 100).Select(i => new TestTableRelations { TestField = string.Format("Bench Single Relations Add '{0}'", i) }).ToArray();
			foreach (var obj in relationObjs)
				obj.Entries = Enumerable.Range(0, 5).Select(i => new TestTableRelationsEntries { ForeignTestField = obj.ObjectId }).ToArray();
			
			var timesRelations =  new List<long>();
			foreach (var obj in relationObjs)
			{
				var stopWatch = Stopwatch.StartNew();
				Database.AddObject(obj);
				stopWatch.Stop();
				timesRelations.Add(stopWatch.ElapsedMilliseconds);
			}

			Console.WriteLine("Bench Single TestTable Add Total Elapse {3}ms, Average {0}ms, Min {1}ms, Max {2}ms", times.Average(), times.Min(), times.Max(), times.Sum());
			Console.WriteLine("Bench Single TestTableRelations Add Total Elapse {3}ms, Average {0}ms, Min {1}ms, Max {2}ms", timesRelations.Average(), timesRelations.Min(), timesRelations.Max(), timesRelations.Sum());
		}
        public void ListExtensions_Max_ThrowsExceptionIfListIsEmpty()
        {
            var list = new List<Int32>();

            Assert.That(() => list.Max(),
                Throws.TypeOf<InvalidOperationException>());
        }
        public void ListExtensions_Max_ReturnsMaxValue()
        {
            var list = new List<Int32>() { 4, 5, 6, 99, 10, 1, 12, 45 };

            var result = list.Max();

            TheResultingValue(result).ShouldBe(99);
        }
Beispiel #16
0
        public void Can_get_scalar_value()
        {
            List<Author> authors = new List<Author>();
            authors.Add(new Author() { Name = "Demis Bellot", Birthday = DateTime.Today.AddYears(-20), Active = true, Earnings = 99.9m, Comments = "CSharp books", Rate = 10, City = "London", FloatProperty = 10.25f, DoubleProperty = 3.23 });
            authors.Add(new Author() { Name = "Angel Colmenares", Birthday = DateTime.Today.AddYears(-25), Active = true, Earnings = 50.0m, Comments = "CSharp books", Rate = 5, City = "Bogota", FloatProperty = 7.59f, DoubleProperty = 4.23 });
            authors.Add(new Author() { Name = "Adam Witco", Birthday = DateTime.Today.AddYears(-20), Active = true, Earnings = 80.0m, Comments = "Math Books", Rate = 9, City = "London", FloatProperty = 15.5f, DoubleProperty = 5.42 });
            authors.Add(new Author() { Name = "Claudia Espinel", Birthday = DateTime.Today.AddYears(-23), Active = true, Earnings = 60.0m, Comments = "Cooking books", Rate = 10, City = "Bogota", FloatProperty = 0.57f, DoubleProperty = 8.76 });
            authors.Add(new Author() { Name = "Libardo Pajaro", Birthday = DateTime.Today.AddYears(-25), Active = true, Earnings = 80.0m, Comments = "CSharp books", Rate = 9, City = "Bogota", FloatProperty = 8.43f, DoubleProperty = 7.35 });
            authors.Add(new Author() { Name = "Jorge Garzon", Birthday = DateTime.Today.AddYears(-28), Active = true, Earnings = 70.0m, Comments = "CSharp books", Rate = 9, City = "Bogota", FloatProperty = 1.25f, DoubleProperty = 0.3652 });
            authors.Add(new Author() { Name = "Alejandro Isaza", Birthday = DateTime.Today.AddYears(-20), Active = true, Earnings = 70.0m, Comments = "Java books", Rate = 0, City = "Bogota", FloatProperty = 1.5f, DoubleProperty = 100.563 });
            authors.Add(new Author() { Name = "Wilmer Agamez", Birthday = DateTime.Today.AddYears(-20), Active = true, Earnings = 30.0m, Comments = "Java books", Rate = 0, City = "Cartagena", FloatProperty = 3.5f, DoubleProperty = 7.23 });
            authors.Add(new Author() { Name = "Rodger Contreras", Birthday = DateTime.Today.AddYears(-25), Active = true, Earnings = 90.0m, Comments = "CSharp books", Rate = 8, City = "Cartagena", FloatProperty = 0.25f, DoubleProperty = 9.23 });
            authors.Add(new Author() { Name = "Chuck Benedict", Birthday = DateTime.Today.AddYears(-22), Active = true, Earnings = 85.5m, Comments = "CSharp books", Rate = 8, City = "London", FloatProperty = 9.95f, DoubleProperty = 4.91 });
            authors.Add(new Author() { Name = "James Benedict II", Birthday = DateTime.Today.AddYears(-22), Active = true, Earnings = 85.5m, Comments = "Java books", Rate = 5, City = "Berlin", FloatProperty = 4.44f, DoubleProperty = 6.41 });
            authors.Add(new Author() { Name = "Ethan Brown", Birthday = DateTime.Today.AddYears(-20), Active = true, Earnings = 45.0m, Comments = "CSharp books", Rate = 5, City = "Madrid", FloatProperty = 6.67f, DoubleProperty = 8.05 });
            authors.Add(new Author() { Name = "Xavi Garzon", Birthday = DateTime.Today.AddYears(-22), Active = true, Earnings = 75.0m, Comments = "CSharp books", Rate = 9, City = "Madrid", FloatProperty = 1.25f, DoubleProperty = 3.99 });
            authors.Add(new Author()
            {
                Name = "Luis garzon",
                Birthday = DateTime.Today.AddYears(-22),
                Active = true,
                Earnings = 85.0m,
                Comments = "CSharp books",
                Rate = 10,
                City = "Mexico",
                LastActivity = DateTime.Today,
                NRate = 5,
                FloatProperty = 1.25f,
                NFloatProperty = 3.15f,
                DoubleProperty = 1.25,
                NDoubleProperty = 8.25
            });

            using (var db = OpenDbConnection())
            {
                db.CreateTable<Author>(true);
                db.DeleteAll<Author>();

                db.InsertAll(authors);

                var expectedDate = authors.Max(e => e.Birthday);
                var r1 = db.Scalar<Author, DateTime>(e => Sql.Max(e.Birthday));
                Assert.That(expectedDate, Is.EqualTo(r1));

                expectedDate = authors.Where(e => e.City == "London").Max(e => e.Birthday);
                r1 = db.Scalar<Author, DateTime>(e => Sql.Max(e.Birthday), e => e.City == "London");
                Assert.That(expectedDate, Is.EqualTo(r1));

                r1 = db.Scalar<Author, DateTime>(e => Sql.Max(e.Birthday), e => e.City == "SinCity");
                Assert.That(default(DateTime), Is.EqualTo(r1));


                var expectedNullableDate = authors.Max(e => e.LastActivity);
                DateTime? r2 = db.Scalar<Author, DateTime?>(e => Sql.Max(e.LastActivity));
                Assert.That(expectedNullableDate, Is.EqualTo(r2));

                expectedNullableDate = authors.Where(e => e.City == "Bogota").Max(e => e.LastActivity);
                r2 = db.Scalar<Author, DateTime?>(
                    e => Sql.Max(e.LastActivity),
                    e => e.City == "Bogota");
                Assert.That(r2, Is.EqualTo(expectedNullableDate));

                r2 = db.Scalar<Author, DateTime?>(e => Sql.Max(e.LastActivity), e => e.City == "SinCity");
                Assert.That(default(DateTime?), Is.EqualTo(r2));


                var expectedDecimal = authors.Max(e => e.Earnings);
                decimal r3 = db.Scalar<Author, decimal>(e => Sql.Max(e.Earnings));
                Assert.That(expectedDecimal, Is.EqualTo(r3));

                expectedDecimal = authors.Where(e => e.City == "London").Max(e => e.Earnings);
                r3 = db.Scalar<Author, decimal>(e => Sql.Max(e.Earnings), e => e.City == "London");
                Assert.That(expectedDecimal, Is.EqualTo(r3));

                r3 = db.Scalar<Author, decimal>(e => Sql.Max(e.Earnings), e => e.City == "SinCity");
                Assert.That(default(decimal), Is.EqualTo(r3));


                var expectedNullableDecimal = authors.Max(e => e.NEarnings);
                decimal? r4 = db.Scalar<Author, decimal?>(e => Sql.Max(e.NEarnings));
                Assert.That(expectedNullableDecimal, Is.EqualTo(r4));

                expectedNullableDecimal = authors.Where(e => e.City == "London").Max(e => e.NEarnings);
                r4 = db.Scalar<Author, decimal?>(e => Sql.Max(e.NEarnings), e => e.City == "London");
                Assert.That(expectedNullableDecimal, Is.EqualTo(r4));

                r4 = db.Scalar<Author, decimal?>(e => Sql.Max(e.NEarnings), e => e.City == "SinCity");
                Assert.That(default(decimal?), Is.EqualTo(r4));


                var expectedDouble = authors.Max(e => e.DoubleProperty);
                double r5 = db.Scalar<Author, double>(e => Sql.Max(e.DoubleProperty));
                Assert.That(expectedDouble, Is.EqualTo(r5).Within(.1d));

                expectedDouble = authors.Where(e => e.City == "London").Max(e => e.DoubleProperty);
                r5 = db.Scalar<Author, double>(e => Sql.Max(e.DoubleProperty), e => e.City == "London");
                Assert.That(expectedDouble, Is.EqualTo(r5).Within(.1d));

                r5 = db.Scalar<Author, double>(e => Sql.Max(e.DoubleProperty), e => e.City == "SinCity");
                Assert.That(default(double), Is.EqualTo(r5));


                var expectedNullableDouble = authors.Max(e => e.NDoubleProperty);
                double? r6 = db.Scalar<Author, double?>(e => Sql.Max(e.NDoubleProperty));
                Assert.That(expectedNullableDouble, Is.EqualTo(r6));


                expectedNullableDouble = authors.Where(e => e.City == "London").Max(e => e.NDoubleProperty);
                r6 = db.Scalar<Author, double?>(e => Sql.Max(e.NDoubleProperty), e => e.City == "London");
                Assert.That(expectedNullableDouble, Is.EqualTo(r6));

                r6 = db.Scalar<Author, double?>(e => Sql.Max(e.NDoubleProperty), e => e.City == "SinCity");
                Assert.That(default(double?), Is.EqualTo(r6));



                var expectedFloat = authors.Max(e => e.FloatProperty);
                var r7 = db.Scalar<Author, float>(e => Sql.Max(e.FloatProperty));
                Assert.That(expectedFloat, Is.EqualTo(r7));

                expectedFloat = authors.Where(e => e.City == "London").Max(e => e.FloatProperty);
                r7 = db.Scalar<Author, float>(e => Sql.Max(e.FloatProperty), e => e.City == "London");
                Assert.That(expectedFloat, Is.EqualTo(r7));

                r7 = db.Scalar<Author, float>(e => Sql.Max(e.FloatProperty), e => e.City == "SinCity");
                Assert.That(default(float), Is.EqualTo(r7));


                var expectedNullableFloat = authors.Max(e => e.NFloatProperty);
                var r8 = db.Scalar<Author, float?>(e => Sql.Max(e.NFloatProperty));
                Assert.That(expectedNullableFloat, Is.EqualTo(r8));

                expectedNullableFloat = authors.Where(e => e.City == "London").Max(e => e.NFloatProperty);
                r8 = db.Scalar<Author, float?>(e => Sql.Max(e.NFloatProperty), e => e.City == "London");
                Assert.That(expectedNullableFloat, Is.EqualTo(r8));

                r8 = db.Scalar<Author, float?>(e => Sql.Max(e.NFloatProperty), e => e.City == "SinCity");
                Assert.That(default(float?), Is.EqualTo(r8));


                var expectedString = authors.Min(e => e.Name);
                var r9 = db.Scalar<Author, string>(e => Sql.Min(e.Name));
                Assert.That(expectedString, Is.EqualTo(r9));

                expectedString = authors.Where(e => e.City == "London").Min(e => e.Name);
                r9 = db.Scalar<Author, string>(e => Sql.Min(e.Name), e => e.City == "London");
                Assert.That(expectedString, Is.EqualTo(r9));

                r9 = db.Scalar<Author, string>(e => Sql.Max(e.Name), e => e.City == "SinCity");
                Assert.That(string.IsNullOrEmpty(r9));

                //Can't MIN(bit)/MAX(bit) in SQL Server
                if (Dialect == Dialect.SqlServer)
                {
                    var expectedBool = authors.Min(e => e.Active);
                    var r10 = db.Scalar<Author, bool>(e => Sql.Count(e.Active));
                    Assert.That(expectedBool, Is.EqualTo(r10));

                    expectedBool = authors.Max(e => e.Active);
                    r10 = db.Scalar<Author, bool>(e => Sql.Count(e.Active));
                    Assert.That(expectedBool, Is.EqualTo(r10));

                    r10 = db.Scalar<Author, bool>(e => Sql.Count(e.Active), e => e.City == "SinCity");
                    Assert.IsFalse(r10);
                }

                var expectedShort = authors.Max(e => e.Rate);
                var r11 = db.Scalar<Author, short>(e => Sql.Max(e.Rate));
                Assert.That(expectedShort, Is.EqualTo(r11));

                expectedShort = authors.Where(e => e.City == "London").Max(e => e.Rate);
                r11 = db.Scalar<Author, short>(e => Sql.Max(e.Rate), e => e.City == "London");
                Assert.That(expectedShort, Is.EqualTo(r11));

                r11 = db.Scalar<Author, short>(e => Sql.Max(e.Rate), e => e.City == "SinCity");
                Assert.That(default(short), Is.EqualTo(r7));


                var expectedNullableShort = authors.Max(e => e.NRate);
                var r12 = db.Scalar<Author, short?>(e => Sql.Max(e.NRate));
                Assert.That(expectedNullableShort, Is.EqualTo(r12));

                expectedNullableShort = authors.Where(e => e.City == "London").Max(e => e.NRate);
                r12 = db.Scalar<Author, short?>(e => Sql.Max(e.NRate), e => e.City == "London");
                Assert.That(expectedNullableShort, Is.EqualTo(r12));

                r12 = db.Scalar<Author, short?>(e => Sql.Max(e.NRate), e => e.City == "SinCity");
                Assert.That(default(short?), Is.EqualTo(r12));

            }

        }
		public void Can_GetSetCountByScores()
		{
			var scores = new List<double>();

			storeMembers.ForEach(x =>
			{ 
				Redis.AddItemToSortedSet(SetId, x);
				scores.Add(RedisClient.GetLexicalScore(x));
			});

			Assert.That(Redis.GetSortedSetCount(SetId, scores.Min(), scores.Max()), Is.EqualTo(storeMembers.Count()));
			Assert.That(Redis.GetSortedSetCount(SetId, scores.Min(), scores.Min()), Is.EqualTo(1));
		}
Beispiel #18
0
        public void create()
        {
            var retention = new List<ArchiveInfo>() { new ArchiveInfo(1, 60), new ArchiveInfo(60, 60) };

            // check if invalid configuration fails successfully
            Assert.Throws<InvalidConfigurationException>(() => Whipser.Create(db, new List<ArchiveInfo>()));

            // create a new db with a valid configuration
            Whipser.Create(db, retention);

            // attempt to create another db in the same file, this should fail
            Assert.Throws<InvalidConfigurationException>(() => Whipser.Create(db, retention));

            var info = Whipser.Info(db);

            Assert.AreEqual(retention.Max(x => x.Retention), info.MaxRetention);
            Assert.AreEqual(AggregationType.Average, info.AggregationType);
            Assert.AreEqual(0.5f, info.xFilesFactor);

            Assert.AreEqual(retention.Count, info.ArchiveList.Count);
            Assert.AreEqual(retention[0].SecondsPerPoint, info.ArchiveList[0].SecondsPerPoint);
            Assert.AreEqual(retention[0].Points, info.ArchiveList[0].Points);
            Assert.AreEqual(retention[1].SecondsPerPoint, info.ArchiveList[1].SecondsPerPoint);
            Assert.AreEqual(retention[1].Points, info.ArchiveList[1].Points);

            RemoveDb();
        }