Esempio n. 1
0
        internal static StackExchange.Redis.SetOperation ToRedisOperation(this SetOperations op)
        {
            var res = StackExchange.Redis.SetOperation.Union;

            mapping.TryGetValue(op, out res);
            return(res);
        }
Esempio n. 2
0
        /// <summary>
        /// Set operations are applied. See also <see cref="SetOperations"/> and <see cref="Loxy.SetOperation(SetOperations, Loxy)"/>
        /// </summary>
        /// <param name="Operation">Setoperation</param>
        /// <param name="Clip">the other loca</param>
        /// <returns>the settheoretical Loxy.</returns>
        public Loxy SetOperation(SetOperations Operation, Loca Clip)
        {
            Loxy L     = ToLoxy();
            Loxy LClip = Clip.ToLoxy();

            return(L.SetOperation(Operation, LClip));
        }
Esempio n. 3
0
        public void SubSetsOf3()
        {
            var set = new[] { 1, 2, 3 };

            var subSetsNeg = SetOperations <int> .SubSets(set, -1).ToArray();

            Assert.AreEqual(0, subSetsNeg.Length);

            var subSets0 = SetOperations <int> .SubSets(set, 0).ToArray();

            Assert.AreEqual(1, subSets0.Length);

            var subSets1 = SetOperations <int> .SubSets(set, 1).ToArray();

            Assert.AreEqual(3, subSets1.Length);

            var subSets2 = SetOperations <int> .SubSets(set, 2).ToArray();

            Assert.AreEqual(3, subSets2.Length);

            var subSets3 = SetOperations <int> .SubSets(set, 3).ToArray();

            Assert.AreEqual(1, subSets3.Length);

            var subSets4 = SetOperations <int> .SubSets(set, 4).ToArray();

            Assert.AreEqual(0, subSets4.Length);
        }
Esempio n. 4
0
        public static IEnumerable <Group> NaiveSolver(ProblemSpecification spec)
        {
            int minimalNumberOfColors = MinimalNumberOfColors(spec.Colors.Count, spec.Fraction);

            return(Enumerable.Range(minimalNumberOfColors, spec.Colors.Count - minimalNumberOfColors + 1)
                   .SelectMany(n => SetOperations <Color> .SubSets(spec.Colors, n)
                               .SelectMany(NaiveSolverFull)));
        }
Esempio n. 5
0
        public void Cross0By0()
        {
            var set1 = new int[0];
            var set2 = new int[0];

            var set1TimesSet2 = SetOperations <int> .CrossProduct(new[] { set1, set2 }).ToArray();

            Assert.AreEqual(0, set1TimesSet2.Length);
        }
Esempio n. 6
0
        private static IEnumerable <Group> NaiveSolverFull(IEnumerable <Color> colors)
        {
            var colourPointsPerColor = from color in colors
                                       select color.Points.Select(colorValue => new ColorPoint(colorValue, color));

            var groupCandidates = from colorPointCombination in SetOperations <ColorPoint> .CrossProduct(colourPointsPerColor)
                                  select new Group(colorPointCombination);

            return(groupCandidates.Where(IsGroupValid));
        }
Esempio n. 7
0
        public QueryExpressionBodyBinaryImpl(SQLVendorImpl vendor, SetOperations setOperation, CorrespondingSpec correspondingSpec, QueryExpressionBody left, QueryExpressionBody right, SetQuantifier setQuantifier)
            : base(vendor)
        {
            ArgumentValidator.ValidateNotNull(nameof(left), left);
            ArgumentValidator.ValidateNotNull(nameof(right), right);

            this._setOperation      = setOperation;
            this._correspondingSpec = correspondingSpec;
            this._left          = left;
            this._right         = right;
            this._setQuantifier = setQuantifier;
        }
Esempio n. 8
0
        public void ItCanDoASimpleMinus()
        {
            var expr = SetOperations.Minus(
                Select.Star <Person>()
                .From <Person>(),
                Select.Star <Person>()
                .From <Person>()
                .Where <Person>(p => p.Age > 42));
            var result = expr.ToSqlExpression();

            Assert.That(result, Is.EqualTo(TokenGeneration_SetOperationTests_Results.simpleMinusExpression));
        }
Esempio n. 9
0
        /// <summary>
        /// Set operations are applied <see cref="SetOperations"/>
        /// </summary>
        /// <param name="Operation">Setoperation</param>
        /// <param name="Clip">the other Loxy</param>
        /// <returns>the result of the setoperation</returns>
        public Loxy SetOperation(SetOperations Operation, Loxy Clip)
        {
            List <List <IntPoint> > Me     = ToClipperPoly(this);
            List <List <IntPoint> > Second = ToClipperPoly(Clip);
            Clipper c = new Clipper();

            c.AddPaths(Me, PolyType.ptSubject, true);
            c.AddPaths(Second, PolyType.ptClip, true);
            List <List <IntPoint> > Solution = new List <List <IntPoint> >();

            c.Execute((ClipType)Operation, Solution, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
            return(FromClipperLoxy(Solution));
        }
Esempio n. 10
0
        public void AdjacentSets()
        {
            var a = Polygon.Rectangle(5, 5);
            var b = Polygon.Rectangle(5, 2.5).TransformedPolygon(new Transform((5, 5)));

            var set = SetOperations.ClassifySegments2d(a, b);

            Assert.Equal(4, set.Where(c => c.classification == SetClassification.AOutsideB).Count());
            Assert.Equal(4, set.Where(c => c.classification == SetClassification.BOutsideA).Count());

            Assert.Empty(set.Where(c => c.classification == SetClassification.AInsideB));
            Assert.Empty(set.Where(c => c.classification == SetClassification.BInsideA));
        }
Esempio n. 11
0
        public void OverlappingSetsFilterAndGraphCorrectly()
        {
            var a = Polygon.Rectangle(5, 5);
            var b = Polygon.Rectangle(5, 5).TransformedPolygon(new Transform((2.5, 2.5)));

            if (a.Intersects2d(b, out List <(Vector3 result, int, int)> results))
            {
                var locations = results.Select(r => r.result).ToList();
                a.Split(locations);
                b.Split(locations);
            }
            var set = SetOperations.ClassifySegments2d(a, b, ((Vector3, Vector3, SetClassification classification)e) =>
            {
                return(e.classification == SetClassification.AOutsideB || e.classification == SetClassification.BInsideA || e.classification == SetClassification.AInsideB);
            });
Esempio n. 12
0
        public void SubSetsOfEmpty()
        {
            var set = new int[0];

            var subSetsNeg = SetOperations <int> .SubSets(set, -1).ToArray();

            Assert.AreEqual(0, subSetsNeg.Length);

            var subSets0 = SetOperations <int> .SubSets(set, 0).ToArray();

            Assert.AreEqual(1, subSets0.Length);

            var subSets1 = SetOperations <int> .SubSets(set, 1).ToArray();

            Assert.AreEqual(0, subSets1.Length);
        }
Esempio n. 13
0
        public void ItShouldBePossibleToDoARecursiveCommonTableExpression()
        {
            var expr =
                With.Table <RecursivePerson>(
                    SetOperations.UnionAll(
                        Select.Column <Person>(p => new { Level = 0, p.Name, p.ParentId, })
                        .From <Person>()
                        .Where <Person>(p => p.Name == "Kalle"),
                        Select.Column <RecursivePerson>(rp => new { Level = rp.Level + 1 })
                        .Column <Person>(p => new { p.Name, p.ParentId })
                        .From <Person>()
                        .InnerJoin <Person, RecursivePerson>((p, rp) => p.Id == rp.ParentId)))
                .Query(Select.Star <RecursivePerson>().From <RecursivePerson>());
            var result = expr.ToSqlExpression();

            Assert.That(result, Is.EqualTo(TokenGeneration_CommonTableExpressions_Results.recursiveCommonTableExpression));
        }
Esempio n. 14
0
        public void ItCanDoAUnionsWithCommonTableExpressions()
        {
            var identifier = Table <Person> .WithTableAlias("cte");

            var expr =
                With.Table(
                    identifier,
                    SetOperations.Union(
                        Select.Star <Person>().From <Person>().Where <Person>(p => p.Age > 42),
                        Select.Star <Person>().From <Person>().Where <Person>(p => p.Name == "Kalle")))
                .Query(
                    SetOperations.Union(
                        Select.Star(identifier).From(identifier).Where <Person>(identifier, p => p.Age == 50),
                        Select.Star(identifier).From(identifier).Where <Person>(identifier, p => p.Name == "Kalle")));

            var result = expr.ToSqlExpression();
            var sql    = SqlGen.SqlifyExpression(AnsiSql.Dialect, result);
            var sql2   = SqlGen.SqlifyExpression(AnsiSql.Dialect, TokenGeneration_SetOperationTests_Results.unionsInACommonTableExpression);

            Assert.That(result, Is.EqualTo(TokenGeneration_SetOperationTests_Results.unionsInACommonTableExpression));
        }
Esempio n. 15
0
        public void OverlappingSets()
        {
            var a = Polygon.Rectangle(5, 5);
            var b = Polygon.Rectangle(5, 5).TransformedPolygon(new Transform((2.5, 2.5)));

            if (a.Intersects2d(b, out List <(Vector3 result, int, int)> results))
            {
                var locations = results.Select(r => r.result).ToList();
                a.Split(locations);
                b.Split(locations);
            }

            Assert.Equal(6, a.Vertices.Count);
            Assert.Equal(6, b.Vertices.Count);

            var set = SetOperations.ClassifySegments2d(a, b);

            Assert.Equal(4, set.Where(c => c.classification == SetClassification.AOutsideB).Count());
            Assert.Equal(4, set.Where(c => c.classification == SetClassification.BOutsideA).Count());
            Assert.Equal(2, set.Where(c => c.classification == SetClassification.AInsideB).Count());
            Assert.Equal(2, set.Where(c => c.classification == SetClassification.BInsideA).Count());
        }
Esempio n. 16
0
    /// <summary>
    /// Console program entry point
    /// </summary>
    /// <param name="args">The command-line arguments.</param>
    public static void Main (string[] args)
    {
        Console.WriteLine ("Enter the string pattern to get powerset and permutations: ");
        string input = Console.ReadLine ();

        // Construct an object to work on
        SetOperations ops = new SetOperations ();

        // Get all the permutations 
        Console.WriteLine ();
        Console.WriteLine ("Permutations: ");
        IList<string> permutations = ops.Permute (input);
        foreach (string s in permutations)
            Console.WriteLine (s);

        // Get the powerset
        Console.WriteLine ();
        Console.WriteLine ("Powerset: ");
        IList<string> powerset = ops.PowerSet (input);
        foreach (string s in powerset)
            Console.WriteLine (s);
    }
Esempio n. 17
0
        public void Cross2By3()
        {
            var set1 = new[] { 1, 2 };
            var set2 = new[] { 7, 8, 9 };

            var set1TimesSet2 = SetOperations <int> .CrossProduct(new[] { set1, set2 }).ToArray();

            Assert.AreEqual(6, set1TimesSet2.Length);
            var expected = new[]
            {
                new[] { 1, 7 },
                new[] { 1, 8 },
                new[] { 1, 9 },
                new[] { 2, 7 },
                new[] { 2, 8 },
                new[] { 2, 9 }
            };

            for (int i = 0; i < 6; i++)
            {
                CollectionAssert.AreEqual(expected[i], set1TimesSet2[i]);
            }
        }
Esempio n. 18
0
        public void ItShouldBePossibleToMapUnions()
        {
            var factory = new HyperboliqConnectionFactory(SqlLite.Dialect, "Data source=:memory:");

            using (var con = factory.OpenDbConnection())
            {
                const string createTable = "CREATE TABLE Person (Id INT, Name VARCHAR(50), Age INT, LivesAtHouseId INT, ParentId INT)";
                var          cmd1        = con.AsIDbConnection().CreateCommand();
                cmd1.CommandText = createTable;
                cmd1.ExecuteNonQuery();

                var insertQuery = Insert.Into <Person>().AllColumns.Values(
                    new Person {
                    Id = 1, Name = "Kalle", Age = 42
                },
                    new Person {
                    Id = 2, Name = "Pelle", Age = 42
                },
                    new Person {
                    Id = 3, Name = "Putte", Age = 45
                });
                con.ExecuteNonQuery(insertQuery);

                var selectQuery =
                    SetOperations.Union(
                        Select.Star <Person>().From <Person>().Where <Person>(p => p.Age > 42),
                        Select.Star <Person>().From <Person>().Where <Person>(p => p.Name == "Kalle")
                        );
                var result = con.Query <Person>(selectQuery);

                Assert.That(result, Has.Count.EqualTo(2));

                Assert.True(result.Any(p => p.Id == 1 && p.Name == "Kalle" && p.Age == 42));
                Assert.True(result.Any(p => p.Id == 3 && p.Name == "Putte" && p.Age == 45));
            }
        }
Esempio n. 19
0
		/// <summary>
		/// Internal method common for all functions.
		/// </summary>
        private static PhpArray SetOperation(SetOperations op, PhpArray array, PhpArray[] arrays,
            IComparer<KeyValuePair<IntStringKey, object>> comparer)
        {
            if (array == null)
            {
                PhpException.ArgumentNull("array");
                return null;
            }

            if (arrays == null || arrays.Length == 0)
            {
                PhpException.InvalidArgumentCount(null, null);
                return null;
            }

            Debug.Assert(comparer != null);

            PhpArray result = new PhpArray();
            array.SetOperation(op, arrays, comparer, result);

            // the result is inplace deeply copied on return to PHP code:
            result.InplaceCopyOnReturn = true;
            return result;
        }
Esempio n. 20
0
 public virtual QueryExpressionBodyBinary NewBinaryQuery(QueryExpressionBody left, QueryExpressionBody right, SetOperations setOperation, SetQuantifier quantifier = SetQuantifier.Distinct, CorrespondingSpec correspondingSpec = null)
 {
     return(new QueryExpressionBodyBinaryImpl(this.vendor, setOperation, correspondingSpec, left, right, quantifier));
 }