Ejemplo n.º 1
0
        public void HighlightKeepsCase()
        {
            var sampleGetter = new SampleGetter();

            sampleGetter.GetSample(GenerateStandardResultTestPage(), new Query()
            {
                Fragments = new string[] { "fusce" }
            })
            .ShouldBe("Sed finibus rhoncus diam quis ultrices. <strong>Fusce</strong> est est, suscipit ac nisl ut, auctor semper ligula. Curabitur aliquam ornare nisi ac finibus. Proin dui justo, tincidunt at dictum quis, pulvinar volutpat lacus. Praesent fringilla rutrum dui id volutpat. Quisque lacinia magna sit amet ligula viverra, nec molestie diam accumsan. In efficitur nisi felis, sed fermentum justo varius eu. Nulla fringilla a eros nec maximus.");
        }
Ejemplo n.º 2
0
        public void SamplerShowParagraphContainingKeyword()
        {
            var sampleGetter = new SampleGetter();

            sampleGetter.GetSample(GenerateStandardResultTestPage(),
                                   new Query()
            {
                Fragments = new string[] { "magna" }
            })
            .ShouldBe("Aliquam et fermentum leo. Curabitur odio nibh, convallis vel <strong>magna</strong> id, aliquam sagittis nisl. Pellentesque in purus fringilla purus tempor scelerisque. Nunc vestibulum euismod nisl, eu tincidunt sem posuere id. Vivamus non massa venenatis, ullamcorper lacus id, viverra elit. Aenean maximus eleifend augue, vel volutpat diam mattis sed. Morbi porttitor ipsum augue, sit amet sodales tellus pellentesque eu. Phasellus egestas quis est non lobortis. Nam ipsum nulla, mollis at sodales quis, consequat rutrum");
        }
Ejemplo n.º 3
0
        public void SamplerHaxMaxLengthOfSample()
        {
            var sampleGetter = new SampleGetter();

            sampleGetter.GetSample(GenerateBigChunkResultTestPage(),
                                   new Query()
            {
                Fragments = new string[] { "dolor" }
            })
            .Length.ShouldBeLessThan(529);
        }
Ejemplo n.º 4
0
        public void SamplerHighlightsKeyword()
        {
            var sampleGetter = new SampleGetter();

            sampleGetter.GetSample(GenerateStandardResultTestPage(),
                                   new Query()
            {
                Fragments = new string[] { "dolor" }
            })
            .ShouldContain("<strong>dolor</strong>");
        }
Ejemplo n.º 5
0
        public void SamplerHandlesEmptyContent()
        {
            var sampleGetter = new SampleGetter();

            sampleGetter.GetSample(GenerateResultTestPage(new string[] { }),
                                   new Query()
            {
                Fragments = new string[] { "dolor" }
            })
            .ShouldBeNull();
        }
Ejemplo n.º 6
0
        public void SamplerHandlesNullContent()
        {
            var sampleGetter = new SampleGetter();

            sampleGetter.GetSample(GenerateResultTestPage((IEnumerable <string>)null),
                                   new Query()
            {
                Fragments = new string[] { "dolor" }
            })
            .ShouldBeNull();
        }
Ejemplo n.º 7
0
        public void SamplerShowsOnlyReleventParagraph()
        {
            var sampleGetter = new SampleGetter();

            sampleGetter.GetSample(GenerateStandardResultTestPage(),
                                   new Query()
            {
                Fragments = new string[] { "dolor" }
            })
            .ShouldBe("Lorem ipsum <strong>dolor</strong> sit amet, consectetur adipiscing elit. Morbi quis viverra nulla. Duis viverra, orci et faucibus suscipit, nulla odio vestibulum orci, a tempor odio libero et augue. Aenean aliquam feugiat suscipit. Nunc ultricies tortor vel augue viverra, sit amet tincidunt lectus faucibus. Aliquam vel aliquet purus. Nulla sed suscipit lorem. Nulla aliquam neque et massa dictum rhoncus non id enim. Suspendisse potenti. Cras dui ex, dapibus eu diam nec, convallis volutpat felis. Morbi convallis leo at diam");
        }
Ejemplo n.º 8
0
        public async void BusinessLogicCallback_GetSampleToken()
        {
            string sha256String;
            var    mongoClient   = new MongoClient($"mongodb://{_dockerFixture.IpAddress}:27017");
            var    listRequester = new ListRequester(Configuration, Logger,
                                                     new MongoMetadataReader(Configuration, mongoClient, Logger), GetShareConfig());

            var sampleGetter = new SampleGetter(Configuration, Logger);

            WriteFakeDataIntoTestMongo(mongoClient);
            CreateTestFile();

            var tokens = await listRequester
                         .RequestListAsync("GanzTollerTauschPartner", DateTime.Now.AddDays(-7),
                                           null, "eltesto");

            var deserializedToken = new JwtBuilder()
                                    .WithAlgorithm(new HMACSHA512Algorithm())
                                    .WithSecret(Configuration["Token:Secret"])
                                    .MustVerifySignature()
                                    .Decode <IDictionary <string, object> > (tokens[0]._Token);

            var sha256FromToken   = deserializedToken["sha256"].ToString();
            var partnerFromToken  = deserializedToken["partner"].ToString();
            var filesizeFromToken = long.Parse(deserializedToken["filesize"].ToString());

            using (var sha256 = SHA256.Create())
            {
                sha256String = HexStringFromBytes(sha256
                                                  .ComputeHash(sampleGetter
                                                               .Get(sha256FromToken, partnerFromToken, "eltesto").FileStream));
            }

            Assert.Equal("c79a962e9dc9f4251fd2bf4398d4676b36ed8814c46c0807bf68f466652b35d0", sha256String);
            Assert.Equal(29, filesizeFromToken);
        }
Ejemplo n.º 9
0
    private void Awake()
    {
        Instance = this;

        obstacles = GetComponentsInChildren <Collider2D>();

        var startTime = Time.realtimeSinceStartup;

        //
        var   bounds  = new Bounds();
        float minSize = Mathf.Infinity;

        foreach (var obstacle in obstacles)
        {
            bounds.Encapsulate(obstacle.bounds);

            minSize = Mathf.Min(obstacle.bounds.size.x, obstacle.bounds.size.y, minSize);
        }

        var step = minSize / 2;

        var matrixSizeX = Mathf.CeilToInt((bounds.max.x - bounds.min.x) / step);
        var matrixSizeY = Mathf.CeilToInt((bounds.max.y - bounds.min.y) / step);

        var samples = new bool[matrixSizeX, matrixSizeY];

        SampleGetter getSample = (i, j) => new Vector2(bounds.min.x + i * step, bounds.min.y + j * step);

        for (var i = 0; i < matrixSizeX; ++i)
        {
            for (var j = 0; j < matrixSizeY; ++j)
            {
                samples[i, j] = IsReachable(getSample(i, j));
            }
        }

        // simplify
        var horizontal = samples.Clone() as bool[, ];
        var vertical   = samples.Clone() as bool[, ];

        for (var i = 0; i < matrixSizeX; ++i)
        {
            for (var j = 0; j < matrixSizeY; ++j)
            {
                if (!samples[i, j])
                {
                    continue;
                }

                if (i > 0 && samples[i - 1, j] && i < matrixSizeX - 1 && samples[i + 1, j])
                {
                    horizontal[i, j] = false; // not significant on the horizontal
                }

                if (j > 0 && samples[i, j - 1] && j < matrixSizeY - 1 && samples[i, j + 1])
                {
                    vertical[i, j] = false; // not significant on the vertical
                }
            }
        }

        var significantSamples = new List <Vector2Int>();

        for (var i = 0; i < matrixSizeX; ++i)
        {
            for (var j = 0; j < matrixSizeY; ++j)
            {
                if (horizontal[i, j] && vertical[i, j])
                {
                    continue; // inner corner, never on the shortest path
                }
                if (horizontal[i, j] && !(j > 0 && horizontal[i, j - 1] && j < matrixSizeY - 1 && horizontal[i, j + 1]))
                {
                    significantSamples.Add(new Vector2Int(i, j));
                }

                if (vertical[i, j] && !(i > 0 && vertical[i - 1, j] && i < matrixSizeX - 1 && vertical[i + 1, j]))
                {
                    significantSamples.Add(new Vector2Int(i, j));
                }
            }
        }

        for (var i = 0; i < significantSamples.Count; ++i)
        {
            for (var j = i + 1; j < significantSamples.Count; ++j)
            {
                var left  = significantSamples[i];
                var right = significantSamples[j];

                if (Mathf.Abs(left.x - right.x) == 1 && Mathf.Abs(right.y - left.y) == 1)
                {
                    var leftSample  = getSample(left.x, left.y);
                    var rightSample = getSample(right.x, right.y);

                    nodes.Add((leftSample + rightSample) / 2);
                }
            }
        }

        // build paths
        distances = new float[nodes.Count, nodes.Count];

        for (var i = 0; i < nodes.Count; ++i)
        {
            for (var j = i + 1; j < nodes.Count; ++j)
            {
                if (i == j)
                {
                    distances[i, j] = distances[j, i] = 0;
                }
                else if (IsVisible(nodes[i], nodes[j]))
                {
                    distances[i, j] = distances[j, i] = Vector2.Distance(nodes[i], nodes[j]);
                }
                else
                {
                    distances[i, j] = distances[j, i] = Mathf.Infinity;
                }
            }
        }

        for (var k = 0; k < nodes.Count; ++k)
        {
            for (var i = 0; i < nodes.Count; ++i)
            {
                for (var j = 0; j < nodes.Count; ++j)
                {
                    if (distances[i, j] > distances[i, k] + distances[k, j])
                    {
                        distances[i, j] = distances[i, k] + distances[k, j];
                    }
                }
            }
        }

        var endTime = Time.realtimeSinceStartup;

        Debug.Log("time " + (endTime - startTime) + " nodes " + nodes.Count);
    }