Пример #1
0
        public void CantGetMostFrequentValueIfEmpty()
        {
            var distinctValues = new DistinctValues <string>();

            string value;
            int    count;

            Assert.IsFalse(distinctValues.TryGetMostFrequentValue(out value, out count));
        }
Пример #2
0
        // Unary Operators

        public PossibleValueSet Not()
        {
            DetermineBoolType();

            var result = new PossibleValueSet(ExpressionType);

            result.ContainsNull = ContainsNull;
            result.DistinctValues.AddRange(DistinctValues.Cast <bool>().Select(v => !v).Cast <object>());
            return(result);
        }
Пример #3
0
        // Unary Operators

        public PossibleValueSet Not()
        {
            CheckType <bool>();

            PossibleValueSet result = new PossibleValueSet(typeof(bool));

            result.ContainsNull = ContainsNull;
            result.DistinctValues.AddRange(DistinctValues.Cast <bool>().Select(v => !v).Cast <object>());
            return(result);
        }
Пример #4
0
        private static Guid GetLineageUuid([NotNull] DistinctValues <Guid> distinctGuids)
        {
            Guid mostFrequentLineageGuid;
            int  count;

            return(distinctGuids.TryGetMostFrequentValue(
                       out mostFrequentLineageGuid,
                       out count)
                                       ? mostFrequentLineageGuid
                                       : Guid.NewGuid());
        }
Пример #5
0
        public void SimpleTest_Jumbled()
        {
            //Given
            var nums = new int[6] {
                2, 1, 1, 2, 3, 1
            };

            //When
            var result = new DistinctValues().solution(nums);

            //Then
            Assert.Equal(3, result);
        }
Пример #6
0
        public void SimpleTest_ThreeWithDupsWithNegatives()
        {
            //Given
            var nums = new int[3] {
                -1, 0, -1
            };

            //When
            var result = new DistinctValues().solution(nums);

            //Then
            Assert.Equal(2, result);
        }
Пример #7
0
        public void SimpleTest_TwoUniqueDigits()
        {
            //Given
            var nums = new int[2] {
                1, 2
            };

            //When
            var result = new DistinctValues().solution(nums);

            //Then
            Assert.Equal(2, result);
        }
Пример #8
0
        public void SimpleTest_SingleDigit()
        {
            //Given
            var nums = new int[1] {
                1
            };

            //When
            var result = new DistinctValues().solution(nums);

            //Then
            Assert.Equal(1, result);
        }
Пример #9
0
        public PossibleValueSet IsNotNull()
        {
            PossibleValueSet result = new PossibleValueSet(typeof(bool));

            if (ContainsNull)
            {
                result.DistinctValues.Add(false);
            }
            if (ContainsAllNonNullValues || DistinctValues.Any())
            {
                result.DistinctValues.Add(true);
            }
            return(result);
        }
Пример #10
0
        public void CanGetMostFrequentValue()
        {
            var distinctValues = new DistinctValues <string>();

            distinctValues.Add("a");
            distinctValues.Add("a");
            distinctValues.Add("a");
            distinctValues.Add("b");
            distinctValues.Add(null);

            string value;
            int    count;

            Assert.AreEqual(1, distinctValues.NullCount);
            Assert.IsTrue(distinctValues.TryGetMostFrequentValue(out value, out count));
            Assert.AreEqual("a", value);
            Assert.AreEqual(3, count);
        }
Пример #11
0
        public bool Contains(object obj)
        {
            if (obj == null)
            {
                return(ContainsNull);
            }

            if (obj.GetType() != ExpressionType)
            {
                return(false);
            }

            if (ContainsAllNonNullValues)
            {
                return(true);
            }

            return(DistinctValues.Contains(obj));
        }
        private static void FindDuplicates()
        {
            Debug.Assert(DistinctValues.Count == 0);

            for (var index = 0; index < Arrays.Count; index++)
            {
                var generationCount = GenerationCounts[index];
                IdCount += generationCount;

                var array = Arrays[index];
                for (var i = 0; i < generationCount; i++)
                {
                    if (!DistinctValues.Add(array[i]))
                    {
                        Collisions.Add(array[i]);
                    }
                }
            }

            DistinctValues.Clear();
        }
Пример #13
0
        public void CanUnion()
        {
            var dv1 = new DistinctValues <string>();

            dv1.Add("a");
            dv1.Add("a");
            dv1.Add("a");
            dv1.Add("b");
            dv1.Add(null);
            dv1.Add(null);
            dv1.Add(null);
            dv1.Add(null);

            var dv2 = new DistinctValues <string>();

            dv2.Add("a");
            dv2.Add("b");
            dv2.Add("b");
            dv2.Add("b");
            dv2.Add("b");
            dv2.Add("c");
            dv2.Add(null);

            dv1.Union(dv2);

            Assert.AreEqual(5, dv1.NullCount);
            string value;
            int    count;

            Assert.IsTrue(dv1.TryGetMostFrequentValue(out value, out count));
            Assert.AreEqual("b", value);
            Assert.AreEqual(5, count);

            var list = new List <DistinctValue <string> >(dv1.Values);

            Assert.AreEqual(3, list.Count);
        }
Пример #14
0
        private static bool ImportException(
            [NotNull] IRow row, [NotNull] string importOriginValue, DateTime importDate,
            [NotNull] ExceptionObjectFactory factory,
            [NotNull]
            IDictionary <Guid, QualityConditionExceptions> targetExceptionsByConditionVersion,
            [NotNull] IDictionary <esriGeometryType, HashSet <int> > replacedExceptionObjects,
            [NotNull] ExceptionWriter writer,
            out int matchCount)
        {
            ExceptionObject exceptionObject = factory.CreateExceptionObject(row);

            matchCount = 0;

            // import only active exceptions
            if (exceptionObject.Status != ExceptionObjectStatus.Active)
            {
                return(false);
            }

            var matchingLineageUuids = new DistinctValues <Guid>();

            var origins = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
            {
                importOriginValue
            };

            foreach (ExceptionObject matchingExceptionObject in GetMatchingExceptionObjects(
                         targetExceptionsByConditionVersion,
                         exceptionObject))
            {
                // add to Uuids of matching exceptions (usually, should be unique)
                if (matchingExceptionObject.ManagedLineageUuid != null)
                {
                    // also if matching exception is inactive
                    // --> lineage of inactive exceptions may be continued (resurrection of inactive exceptions)
                    matchingLineageUuids.Add(matchingExceptionObject.ManagedLineageUuid.Value);

                    // NOTE: consider *preferring* active exceptions, only if none: resurrect inactive exception lineage
                }

                // include the origin values of active replaced exceptions
                // Note: not for resurrected exceptions (inactive/with end date -> active)
                if (matchingExceptionObject.ManagedVersionEndDate == null)
                {
                    foreach (string replacedOrigin in
                             ExceptionObjectUtils.ParseOrigins(matchingExceptionObject.ManagedOrigin))
                    {
                        origins.Add(replacedOrigin);
                    }
                }

                matchCount++;

                AddToReplacedExceptionObjects(matchingExceptionObject, replacedExceptionObjects);
            }

            writer.Write(row,
                         importDate,
                         ExceptionObjectUtils.FormatOrigins(origins),
                         GetLineageUuid(matchingLineageUuids),
                         versionOriginValue: importOriginValue,
                         statusValue: "Active");

            return(true);
        }
        public void TestAggregate()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            cache.Clear();


            Hashtable ht = new Hashtable();

            ht.Add("comparableMaxKey1", 100);
            ht.Add("comparableMaxKey2", 80.5);
            ht.Add("comparableMaxKey3", 19.5);
            ht.Add("comparableMaxKey4", 2);
            cache.InsertAll(ht);

            IEntryAggregator aggregator = new DoubleAverage(IdentityExtractor.Instance);
            object           result     = cache.Aggregate(cache.Keys, aggregator);

            Assert.AreEqual(50.5, result);

            cache.Insert("comparableKey5", null);
            result = cache.Aggregate(cache.Keys, aggregator);
            Assert.AreEqual(50.5, result);

            IFilter alwaysFilter = new AlwaysFilter();

            result = cache.Aggregate(alwaysFilter, aggregator);
            Assert.AreEqual(50.5, result);

            cache.Clear();

            ht = new Hashtable();
            ht.Add("comparableMaxKey1", 435);
            ht.Add("comparableMaxKey2", 253);
            ht.Add("comparableMaxKey3", 3);
            ht.Add("comparableMaxKey4", null);
            ht.Add("comparableMaxKey5", -3);
            cache.InsertAll(ht);

            aggregator = new ComparableMax(IdentityExtractor.Instance);
            object max = cache.Aggregate(cache.Keys, aggregator);

            Assert.AreEqual(max, 435);

            max = cache.Aggregate(alwaysFilter, aggregator);
            Assert.AreEqual(max, 435);

            cache.Clear();

            ht = new Hashtable();
            ht.Add("comparableMaxKey1", 435);
            ht.Add("comparableMaxKey2", 253);
            ht.Add("comparableMaxKey3", 3);
            ht.Add("comparableMaxKey4", 3);
            ht.Add("comparableMaxKey5", 3);
            ht.Add("comparableMaxKey6", null);
            ht.Add("comparableMaxKey7", null);
            cache.InsertAll(ht);

            aggregator = new DistinctValues(IdentityExtractor.Instance);
            result     = cache.Aggregate(cache.Keys, aggregator);
            Assert.AreEqual(3, ((ICollection)result).Count);
            foreach (object o in ht.Values)
            {
                Assert.IsTrue(((IList)result).Contains(o) || o == null);
            }

            IFilter lessFilter = new LessFilter(IdentityExtractor.Instance, 100);

            result = cache.Aggregate(lessFilter, aggregator);
            Assert.AreEqual(1, ((ICollection)result).Count);

            cache.Clear();

            ht = new Hashtable();
            ht.Add("key1", 100);
            ht.Add("key2", 80.5);
            ht.Add("key3", 19.5);
            ht.Add("key4", 2);

            cache.InsertAll(ht);

            aggregator = new DoubleSum(IdentityExtractor.Instance);
            result     = cache.Aggregate(cache.Keys, aggregator);
            Assert.AreEqual(202, result);

            IFilter filter = new AlwaysFilter();

            result = cache.Aggregate(filter, aggregator);
            Assert.AreEqual(202, result);


            cache.Clear();

            ht = new Hashtable();
            ht.Add("key1", 100);
            ht.Add("key2", 80);
            ht.Add("key3", 19);
            ht.Add("key4", 2);
            ht.Add("key5", null);

            cache.InsertAll(ht);

            aggregator = new LongSum(IdentityExtractor.Instance);
            result     = cache.Aggregate(cache.Keys, aggregator);
            Assert.AreEqual(201, result);

            IFilter greaterFilter = new GreaterFilter(IdentityExtractor.Instance, 1);

            result = cache.Aggregate(greaterFilter, aggregator);
            Assert.AreEqual(201, result);

            CacheFactory.Shutdown();
        }