Beispiel #1
0
        public void test_Count_with_Predicate()
        {
            FillMap <int>();
            var predicate = Predicates.IsGreaterThan("this", 5);

            Assert.AreEqual(4, map.Aggregate(Aggregators.Count(), predicate));
            Assert.AreEqual(4, map.Aggregate(Aggregators.Count("this"), predicate));
        }
        public async Task Test_AggregateAny()
        {
            var dictionary = await Client.GetMapAsync <string, Item>(CreateUniqueName());

            await using var _ = DestroyAndDispose(dictionary);

            await Fill(dictionary, i => new Item(new Header(i, new Handle(false)), new int[1], new int[1]));

            Assert.AreEqual(10, await dictionary.AggregateAsync(Aggregators.Count("enabled[any]")));
        }
        public async Task Test_Count()
        {
            var dictionary = await Client.GetMapAsync <string, int>(CreateUniqueName());

            await using var _ = DestroyAndDispose(dictionary);

            await Fill(dictionary, i => i);

            Assert.AreEqual(10, await dictionary.AggregateAsync(Aggregators.Count()));
            Assert.AreEqual(10, await dictionary.AggregateAsync(Aggregators.Count("this")));
        }
        public async Task Test_Count_with_Predicate()
        {
            var dictionary = await Client.GetMapAsync <string, int>(CreateUniqueName());

            await using var _ = DestroyAndDispose(dictionary);

            await Fill(dictionary, i => i);

            var predicate = Predicates.GreaterThan("this", 5);

            Assert.AreEqual(4, await dictionary.AggregateAsync(Aggregators.Count(), predicate));
            Assert.AreEqual(4, await dictionary.AggregateAsync(Aggregators.Count("this"), predicate));
        }
Beispiel #5
0
        private void AssertAggregator <TResult>(AggregatorBase <TResult> aggregator, int classId)
        {
            var aggregatorType = aggregator.GetType();

            Assert.That(aggregator.FactoryId, Is.EqualTo(FactoryIds.AggregatorDsFactoryId));
            Assert.That(aggregator.ClassId, Is.EqualTo(classId));

            Assert.Throws <ArgumentException>(() => _ = Aggregators.Count(""));
            Assert.Throws <ArgumentException>(() => _ = Aggregators.Count(null));

            Assert.Throws <ArgumentNullException>(() => aggregator.WriteData(null));
            Assert.Throws <ArgumentNullException>(() => aggregator.ReadData(null));

            using var output = new ObjectDataOutput(1024, _serializationService, Endianness.BigEndian);
            aggregator.WriteData(output);

            using var input = new ObjectDataInput(output.Buffer, _serializationService, Endianness.BigEndian);
            var a = (AggregatorBase <TResult>)Activator.CreateInstance(aggregatorType);

            a.ReadData(input);

            Assert.That(a.AttributePath, Is.EqualTo(aggregator.AttributePath));

            var data = _serializationService.ToData(aggregator);

            if (aggregatorType.IsGenericType)
            {
                // doh - cannot deserialize generic types?
                IAggregator <object> x = null;

                if (aggregatorType.GetGenericTypeDefinition() == typeof(MaxAggregator <>))
                {
                    x = _serializationService.ToObject <MaxAggregator <object> >(data);
                }
                else if (aggregatorType.GetGenericTypeDefinition() == typeof(MinAggregator <>))
                {
                    x = _serializationService.ToObject <MinAggregator <object> >(data);
                }
                else
                {
                    Assert.Fail("Unsupported generic aggregator type.");
                }

                Assert.That(x.AttributePath, Is.EqualTo(aggregator.AttributePath));
            }
            else
            {
                var x = _serializationService.ToObject <IAggregator <TResult> >(data);
                Assert.That(x.AttributePath, Is.EqualTo(aggregator.AttributePath));
            }
        }
Beispiel #6
0
        public void Tests()
        {
            AssertAggregator((CountAggregator)Aggregators.Count("name"), AggregatorDataSerializerHook.Count);

            AssertAggregator((BigIntegerSumAggregator)Aggregators.BigIntegerSum("name"), AggregatorDataSerializerHook.BigIntSum);
            AssertAggregator((DoubleSumAggregator)Aggregators.DoubleSum("name"), AggregatorDataSerializerHook.DoubleSum);
            AssertAggregator((FixedSumAggregator)Aggregators.FixedPointSum("name"), AggregatorDataSerializerHook.FixedSum);
            AssertAggregator((LongSumAggregator)Aggregators.LongSum("name"), AggregatorDataSerializerHook.LongSum);
            AssertAggregator((FloatingPointSumAggregator)Aggregators.FloatingPointSum("name"), AggregatorDataSerializerHook.FloatingPointSum);
            AssertAggregator((IntegerSumAggregator)Aggregators.IntegerSum("name"), AggregatorDataSerializerHook.IntSum);

            AssertAggregator((NumberAverageAggregator)Aggregators.NumberAvg("name"), AggregatorDataSerializerHook.NumberAvg);
            AssertAggregator((DoubleAverageAggregator)Aggregators.DoubleAvg("name"), AggregatorDataSerializerHook.DoubleAvg);
            AssertAggregator((IntegerAverageAggregator)Aggregators.IntegerAvg("name"), AggregatorDataSerializerHook.IntAvg);
            AssertAggregator((LongAverageAggregator)Aggregators.LongAvg("name"), AggregatorDataSerializerHook.LongAvg);

            AssertAggregator((MaxAggregator <int>)Aggregators.Max <int>("name"), AggregatorDataSerializerHook.Max);
            AssertAggregator((MinAggregator <int>)Aggregators.Min <int>("name"), AggregatorDataSerializerHook.Min);

            AssertAggregator((CountAggregator)Aggregators.Count(), AggregatorDataSerializerHook.Count);

            AssertAggregator((BigIntegerSumAggregator)Aggregators.BigIntegerSum(), AggregatorDataSerializerHook.BigIntSum);
            AssertAggregator((DoubleSumAggregator)Aggregators.DoubleSum(), AggregatorDataSerializerHook.DoubleSum);
            AssertAggregator((FixedSumAggregator)Aggregators.FixedPointSum(), AggregatorDataSerializerHook.FixedSum);
            AssertAggregator((LongSumAggregator)Aggregators.LongSum(), AggregatorDataSerializerHook.LongSum);
            AssertAggregator((FloatingPointSumAggregator)Aggregators.FloatingPointSum(), AggregatorDataSerializerHook.FloatingPointSum);
            AssertAggregator((IntegerSumAggregator)Aggregators.IntegerSum(), AggregatorDataSerializerHook.IntSum);

            AssertAggregator((NumberAverageAggregator)Aggregators.NumberAvg(), AggregatorDataSerializerHook.NumberAvg);
            AssertAggregator((DoubleAverageAggregator)Aggregators.DoubleAvg(), AggregatorDataSerializerHook.DoubleAvg);
            AssertAggregator((IntegerAverageAggregator)Aggregators.IntegerAvg(), AggregatorDataSerializerHook.IntAvg);
            AssertAggregator((LongAverageAggregator)Aggregators.LongAvg(), AggregatorDataSerializerHook.LongAvg);

            AssertAggregator((MaxAggregator <int>)Aggregators.Max <int>(), AggregatorDataSerializerHook.Max);
            AssertAggregator((MinAggregator <int>)Aggregators.Min <int>(), AggregatorDataSerializerHook.Min);
        }
Beispiel #7
0
 public void test_Count()
 {
     FillMap <int>();
     Assert.AreEqual(10, map.Aggregate(Aggregators.Count()));
     Assert.AreEqual(10, map.Aggregate(Aggregators.Count("this")));
 }
Beispiel #8
0
 public void test_AggregateAny()
 {
     FillMap <Item>();
     Assert.AreEqual(10, map.Aggregate(Aggregators.Count("enabled[any]")));
 }