public void Table_with_extra_rows_should_fail_compared_to_superset_collection()
        {
            var set = new[]
            {
                new SetComparisonTestObject
                {
                    DateTimeProperty = DateTime.Today,
                    GuidProperty = testGuid1,
                    IntProperty = 1,
                    StringProperty = "a"
                },
                new SetComparisonTestObject
                {
                    DateTimeProperty = DateTime.Today,
                    GuidProperty = testGuid2,
                    IntProperty = 2,
                    StringProperty = "b"
                },
            };

            var subsetTable = CreateTableWithAllColumns();
            subsetTable.AddRow(set[0].DateTimeProperty.ToString(), set[0].GuidProperty.ToString(), set[0].IntProperty.ToString(), set[0].StringProperty);
            subsetTable.AddRow(set[1].DateTimeProperty.ToString(), set[1].GuidProperty.ToString(), set[1].IntProperty.ToString(), set[1].StringProperty);
            subsetTable.AddRow(DateTime.Now.ToString(), Guid.NewGuid().ToString(), 1.ToString(), "c");

            var comparer = new SetComparer<SetComparisonTestObject>(subsetTable);
            comparer.CompareToSuperSet(set);
        }
Example #2
0
        /// <inheritdoc/>
        public override byte[] Write()
        {
            if (Constructed == false)
            {
                throw new FormatException("The encoding of a sequence value shall be constructed.");
            }

            var contentBytes = new List <byte>();
            var comparer     = new SetComparer();

            var orderedContent = this.Content.OrderBy(p => p, comparer);

            foreach (var item in orderedContent)
            {
                contentBytes.AddRange(item.Write());
            }

            var resBytes = new List <byte>();

            resBytes.AddRange(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed));
            resBytes.AddRange(DerWriter.WriteLength(contentBytes, (Asn1Type)this.Asn1Tag));
            resBytes.AddRange(contentBytes);

            return(resBytes.ToArray());
        }
Example #3
0
 private static int FindSet(List<List<bool>> sets, List<bool> set)
 {
     SetComparer comparer = new SetComparer();
     for (int i = 0; i < sets.Count; i++)
     {
         if (comparer.Equals(set, sets[i]))
         {
             return i;
         }
     }
     return -1;
 }
Example #4
0
        public static void ShouldContainSameValuesAs(this ICollection <string> left, ICollection <string> right, string becauseOnlyOnLeft = null, string becauseOnlyOnRight = null)
        {
            var comparer   = new SetComparer <string>();
            var comparison = comparer.Compare(left, right, StringComparer.Ordinal);

            var asserts = new List <Action> {
                () => comparison.OnlyOnLeft.ShouldBeEmpty(becauseOnlyOnLeft),
                () => comparison.OnlyOnRight.ShouldBeEmpty(becauseOnlyOnRight)
            };

            asserts.AssertAll();
        }
Example #5
0
 public void Setup()
 {
     QueryHelper = new QueryHelper();
     Data        = new TestData(QueryHelper);
     Session     = new TestSession();
     SetComparer = new SetComparer();
     Session.BeginUpdate();
     Data.AddEventTypesPersisted(1, Session);
     Data.AddNewslettersPersisted(1, Session);
     Data.AddSeriesPersisted(1, Session);
     Data.AddActsPersisted(1, Session);
     Data.AddGenresPersisted(1, Session);
     Session.Commit();
 }
        private static bool AddSetDeluxe(List <VakjeSetDeluxe> alleSets, BommenBepalerStatsIteratie iteratie, int minCountBommen, int minCountNietBommen, List <Vakje> vakjes)
        {
            var newSet = new VakjeSetDeluxe(minCountBommen, minCountNietBommen, vakjes);

            var matchingSets = alleSets.Where(t => SetComparer.SetsAreEqual(newSet, t)).ToList();

            if (matchingSets.Count > 1)
            {
                throw new InvalidOperationException("Should never happen");
            }
            else if (matchingSets.Count == 0)
            {
                alleSets.Add(newSet);
                foreach (var unrevealed in vakjes)
                {
                    unrevealed.VakjeBerekeningen.SetsDeluxe.Add(newSet);
                }
                return(true);
            }
            else
            {
                var  setExisting = matchingSets.First();
                bool changed     = false;

                var newMinGuaranteed    = Math.Max(setExisting.MinCountGuaranteedBombs, newSet.MinCountGuaranteedBombs);
                var newMinGuaranteedNot = Math.Max(setExisting.MinCountGuaranteedNotBombs, newSet.MinCountGuaranteedNotBombs);

                if (setExisting.MinCountGuaranteedBombs != newMinGuaranteed)
                {
                    changed = true;
                    setExisting.MinCountGuaranteedBombs = newMinGuaranteed;
                }

                if (setExisting.MinCountGuaranteedNotBombs != newMinGuaranteedNot)
                {
                    changed = true;
                    setExisting.MinCountGuaranteedNotBombs = newMinGuaranteedNot;
                }

                if (setExisting.MinCountGuaranteedBombs + setExisting.MinCountGuaranteedNotBombs > setExisting.Vakjes.Count)
                {
                    throw new InvalidOperationException("Dit kan ook niet");
                }
                return(changed);
            }
        }
        private static List <List <IntersectionAndSet> > EnsureNoDuplicates(List <List <IntersectionAndSet> > setGroupsToAdd)
        {
            var setGroups = new List <List <IntersectionAndSet> >();

            foreach (var itemToAdd in setGroupsToAdd)
            {
                var matchingSets = setGroups.Where(t => SetComparer.MultipleSetsAreEqual(t.Select(z => z.VakjeSetDeluxe).ToList(), itemToAdd.Select(g => g.VakjeSetDeluxe).ToList())).ToList();
                if (matchingSets.Count == 0)
                {
                    setGroups.Add(itemToAdd);
                }
                //else
                //{
                //    Debug.WriteLine("Item already exists");
                //}
            }
            return(setGroups);
        }
Example #8
0
        /// <inheritdoc/>
        public override byte[] Write()
        {
            var contentBytes = new List <byte>();
            var comparer     = new SetComparer();

            var orderedContent = this.Content.OrderBy(p => p, comparer);

            foreach (var item in orderedContent)
            {
                contentBytes.AddRange(item.Write());
            }

            var resBytes = new List <byte>();

            resBytes.Add(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed));
            resBytes.AddRange(DerWriter.WriteLength(contentBytes, (Asn1Type)this.Asn1Tag));
            resBytes.AddRange(contentBytes);

            return(resBytes.ToArray());
        }
Example #9
0
 public override bool Equals(object obj)
 {
     IWhere other = obj as IWhere;
     if (other == null || GetSql() != other.GetSql())
     {
         return false;
     }
     SetComparer<IDataParameter> comparer = new SetComparer<IDataParameter>(Parameters, other.Parameters);
     return comparer.AreEqual;
 }
Example #10
0
        public TermExpression(IXTable source, IXColumn left, CompareOperator op, IXColumn right)
        {
            _evaluate = EvaluateNormal;

            // Save arguments as-is for ToString()
            _left  = left;
            _cOp   = op;
            _right = right;

            // Disallow constant <op> constant [likely error not wrapping column name]
            if (_left is ConstantColumn && _right is ConstantColumn)
            {
                throw new ArgumentException($"({left} {op.ToQueryForm()} {right}) is comparing two constants. Wrap [ColumnNames] in braces.");
            }

            // If the left side is a constant and the operator can be swapped, move it to the right side.
            // Comparers can check if the right side is constant and run a faster loop when that's the case.
            if (_left.IsConstantColumn() && !(_right.IsConstantColumn()))
            {
                if (op.TryInvertCompareOperator(out op))
                {
                    _left  = right;
                    _right = left;
                }
            }

            // Disallow unquoted constants used as strings
            if (_right.IsConstantColumn() && _left.ColumnDetails.Type == typeof(String8) && _right.ColumnDetails.Type == typeof(String8))
            {
                ConstantColumn cRight = _right as ConstantColumn;
                if (cRight != null && !cRight.IsNull && cRight.WasUnwrappedLiteral)
                {
                    throw new ArgumentException($"{right} is compared to a string, but is unquoted. Strings must be quoted.");
                }
            }

            // Convert the right side to the left side type if required
            // This means constants will always be casted to the other side type.
            if (_left.ColumnDetails.Type != _right.ColumnDetails.Type)
            {
                _right = CastedColumn.Build(source, _right, _left.ColumnDetails.Type, ValueKinds.Invalid);
            }

            // Get the left and right getters
            _leftGetter  = _left.CurrentGetter();
            _rightGetter = _right.CurrentGetter();

            // Null comparison is generic
            if (_right.IsNullConstant())
            {
                if (op == CompareOperator.Equal)
                {
                    _comparer = WhereIsNull;
                }
                else if (op == CompareOperator.NotEqual)
                {
                    _comparer = WhereIsNotNull;
                }
                else
                {
                    throw new ArgumentException($"Only equals and not equals operators are supported against null.");
                }
            }
            else if (_left.IsNullConstant())
            {
                _left = _right;
                if (op == CompareOperator.Equal)
                {
                    _comparer = WhereIsNull;
                }
                else if (op == CompareOperator.NotEqual)
                {
                    _comparer = WhereIsNotNull;
                }
                else
                {
                    throw new ArgumentException($"Only equals and not equals operators are supported against null.");
                }
            }
            else
            {
                // Get a comparer which can compare the values
                _comparer = TypeProviderFactory.Get(left.ColumnDetails.Type).TryGetComparer(op);
                if (_comparer == null)
                {
                    throw new ArgumentException($"No comparer found for type {left.ColumnDetails.Type.Name}.");
                }
            }

            // Optimize Enum to Constant comparisons to use the underlying indices
            if (_left.IsEnumColumn() && _right.IsConstantColumn())
            {
                // Get an optimized comparer against the indices rather than values
                IXColumn replacedRight = _right;
                _comparer = SetComparer.ConvertToEnumIndexComparer(_left, _comparer, ref replacedRight, source);

                // Get the indices on the left side
                _leftGetter = _left.IndicesCurrentGetter();

                // Use the updated value for the right side
                _rightGetter = replacedRight.CurrentGetter();
            }

            // Allow String8 to constant Contains queries to compare on the raw byte[] and int[]
            if (op == CompareOperator.Contains && _right.IsConstantColumn() && _left.ColumnDetails.Type == typeof(String8) && !_left.IsEnumColumn())
            {
                Func <object> rawGetter = _left.ComponentGetter(ColumnComponent.String8Raw);

                if (rawGetter != null)
                {
                    String8         rightValue      = (String8)_right.ValuesGetter()().Array.GetValue(0);
                    String8Comparer string8Comparer = new String8Comparer();

                    _evaluate = (vector) =>
                    {
                        String8Raw raw = (String8Raw)rawGetter();
                        string8Comparer.WhereContains(raw, rightValue, vector);
                    };
                }
            }
        }