Ejemplo n.º 1
0
        public void TryAddContentTest()
        {
            var numberOfPages = 1;

            // generate test pages
            byte[] testArray = new byte[Constants.PAGE_SIZE_INCL_HEADER * numberOfPages];

            Memory <byte> memory = new Memory <byte>(testArray);

            // create dummy headers for the 5 pages
            for (uint i = 0; i < numberOfPages; i++)
            {
                var slice = memory.Slice((int)(Constants.PAGE_SIZE_INCL_HEADER * i));
                SpanExtensions.WriteBytes(slice, 0, UnitTestHelper.GetPageHeader(i, PageType.Data));
            }

            string testContent  = "Hello World!!!";
            var    bytesContent = Encoding.UTF8.GetBytes(testContent);

            var dataPageManager = new DataPageManager(memory);
            var page            = (DataPage)dataPageManager.GetPageById(0);

            page.Should().NotBeNull();
            var id = page.TryAddContent(bytesContent, 0);

            id.Id.Should().NotBe(0);

            var document = page.FindById(id.Id);

            document.Should().NotBeNull();
        }
Ejemplo n.º 2
0
        public void Export_Span_Format()
        {
            var span = new SpanBuilder("test-span", new SimpleSpanProcessor(new NoopSpanExporter()),
                                       TraceConfig.Default).StartSpan();

            span.PutHttpHostAttribute("http://example.com", 80);
            span.PutHttpMethodAttribute("POST");
            span.PutHttpPathAttribute("path");
            span.PutHttpRawUrlAttribute("https://example.com?q=*");
            span.PutHttpRequestSizeAttribute(long.MinValue);
            span.PutHttpResponseSizeAttribute(long.MaxValue);
            span.PutHttpRouteAttribute("route");
            span.PutHttpStatusCode((int)HttpStatusCode.Accepted, "Accepted");
            span.PutHttpUserAgentAttribute("google");

            var convertedSpan = SpanExtensions.ToSpan(span as Span, "test-project");

            Assert.NotNull(convertedSpan);
            Assert.True(convertedSpan.Attributes.AttributeMap.ContainsKey("/http/host"));
            Assert.True(convertedSpan.Attributes.AttributeMap.ContainsKey("/http/method"));
            Assert.True(convertedSpan.Attributes.AttributeMap.ContainsKey("/http/status_code"));
            Assert.True(convertedSpan.Attributes.AttributeMap.ContainsKey("/http/route"));
            Assert.True(convertedSpan.Attributes.AttributeMap.ContainsKey("/http/user_agent"));
            Assert.True(convertedSpan.Attributes.AttributeMap.ContainsKey("/http/request_size"));
            Assert.True(convertedSpan.Attributes.AttributeMap.ContainsKey("/http/response_size"));
            Assert.True(convertedSpan.Attributes.AttributeMap.ContainsKey("/http/url"));
            Assert.True(convertedSpan.Attributes.AttributeMap.ContainsKey("/http/path"));
        }
Ejemplo n.º 3
0
 private static void HeapSortAndAssert(Span <byte> array)
 {
     SpanExtensions.HeapSort(array, IntComparison, 0, array.Length - 1);
     for (var i = 1; i < array.Length; i++)
     {
         Assert.True(array[i - 1] <= array[i]);
     }
 }
Ejemplo n.º 4
0
        public void CycleCrossover()
        {
            var p1        = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var p2        = new int[] { 9, 3, 7, 8, 2, 6, 5, 1, 4 };
            var offspring = new int[p1.Length];

            SpanExtensions.CycleCrossover(p1, p2, offspring);

            offspring
            .Should().Equal(1, 3, 7, 4, 2, 6, 5, 8, 9);
        }
Ejemplo n.º 5
0
        public void CutAndCrossfillCrossover()
        {
            var p1        = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var p2        = new int[] { 9, 3, 7, 8, 2, 6, 5, 1, 4 };
            var offspring = new int[p1.Length];

            SpanExtensions.CutAndCrossfillCrossover(p1, p2, 4, offspring);

            offspring
            .Should().Equal(1, 2, 3, 4, 9, 7, 8, 6, 5);
        }
Ejemplo n.º 6
0
        public void PartiallyMappedCrossover2()
        {
            var p1        = new int[] { 5, 7, 6, 2, 1, 4, 0, 3 };
            var p2        = new int[] { 4, 6, 5, 0, 2, 1, 7, 3 };
            var offspring = new int[p1.Length];

            SpanExtensions.PartiallyMappedCrossover(p1, p2, 1, 7, offspring);

            offspring
            .Should().Equal(5, 7, 6, 2, 1, 4, 0, 3);
        }
Ejemplo n.º 7
0
        public void PartiallyMappedCrossover1()
        {
            var p1        = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var p2        = new int[] { 9, 3, 7, 8, 2, 6, 5, 1, 4 };
            var offspring = new int[p1.Length];

            SpanExtensions.PartiallyMappedCrossover(p1, p2, 3, 4, offspring);

            offspring
            .Should().Equal(9, 3, 2, 4, 5, 6, 7, 1, 8);
        }
Ejemplo n.º 8
0
        private static void Compare(BethesdaField first, BethesdaField second, StringBuilder sb, int indentLevel)
        {
            if (SpanExtensions.SequenceEqual(first.Payload, second.Payload))
            {
                return;
            }

            string indent = Indent(indentLevel);

            sb.Append(indent).AppendLine(first.ToString())
            .Append(indent).AppendLine("vs.")
            .Append(indent).AppendLine(second.ToString());
        }
Ejemplo n.º 9
0
        public void GetBytesTest()
        {
            string s = "askljr3489ur34fojirejdresg";

            byte[] testArray = Encoding.UTF8.GetBytes(s);

            Memory <byte> target = new byte[500];

            SpanExtensions.WriteBytes(target, 0, testArray);

            var span   = target.Span;
            var bytes  = span.ReadBytes(0, testArray.Length);
            var result = Encoding.UTF8.GetString(bytes);

            result.Should().Be(s);
        }
Ejemplo n.º 10
0
        private Memory <byte> GenerateTestPages()
        {
            var numberOfPages = 5;

            // generate test pages
            byte[] testArray = new byte[Constants.PAGE_SIZE_INCL_HEADER * numberOfPages];

            Memory <byte> memory = new Memory <byte>(testArray);

            // create dummy headers for the 5 pages
            for (uint i = 0; i < numberOfPages; i++)
            {
                var slice = memory.Slice((int)(Constants.PAGE_SIZE_INCL_HEADER * i));
                SpanExtensions.WriteBytes(slice, 0, UnitTestHelper.GetPageHeader(i, PageType.Data));
            }

            return(new Memory <byte>(testArray));
        }
Ejemplo n.º 11
0
    public void SpanSequenceEqual()
    {
        for (int i = 0; i < M; i++)
        {
            for (int j = 0; j < M; j++)
            {
                Span <byte> a = items[i];
                Span <byte> b = items[j];

                var x = i == j;
                var y = SpanExtensions.SequenceEqual(a, b);

                if (x != y)
                {
                    throw new Exception();
                }
            }
        }
    }
Ejemplo n.º 12
0
        public void Setup()
        {
            var numberOfPages = 1;

            // generate test pages
            byte[] testArray = new byte[Constants.PAGE_SIZE_INCL_HEADER * numberOfPages];

            Memory <byte> memory = new Memory <byte>(testArray);

            // create dummy headers for the 5 pages
            for (uint i = 0; i < numberOfPages; i++)
            {
                var slice = memory.Slice((int)(Constants.PAGE_SIZE_INCL_HEADER * i));
                SpanExtensions.WriteBytes(slice, 0, UnitTestHelper.GetPageHeader(i, PageType.Data));
            }

            string testContent = "Hello World!!!";

            bytesContent = Encoding.UTF8.GetBytes(testContent);

            var _dataPageManager = new DataPageManager(memory);

            _page  = (DataPage)_dataPageManager.GetPageById(0);
            _guids = new ushort[100];
            for (int i = 0; i < 100; i++)
            {
                var res = _page.TryAddContent(bytesContent, 0);
                _guids[i] = res.Id;
            }

            Random random = new Random();

            for (int i = 0; i < Int16.MaxValue * 10; i++)
            {
                _indexes.Add(random.Next(0, 99));
            }
        }