Example #1
0
        public void CheckingFunctionMustPassOnceToAllowMergeOfSubsetAndCanBeTested()
        {
            var arrayCache = new ArrayCache <int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            Assert.IsTrue(arrayCache.CheckMergeArea(new Point(4, 4), MakeTestArray(5, 5, 2), Math.Max, (a, b) => { return(b > a); }));
        }
Example #2
0
        public void IfCheckingFunctionDoesntPassOnceCheckMergeAreaFails()
        {
            var arrayCache = new ArrayCache <int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            Assert.IsFalse(arrayCache.CheckMergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max, (a, b) => { return(a != b); }));
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PdbModule"/> class.
        /// </summary>
        /// <param name="module">The XML module description.</param>
        /// <param name="pdbFile">Already opened PDB file.</param>
        public PdbModule(XmlModule module, PdbFile pdbFile)
        {
            PdbFile             = pdbFile;
            Name                = !string.IsNullOrEmpty(module.Name) ? module.Name : Path.GetFileNameWithoutExtension(module.SymbolsPath).ToLower();
            Namespace           = module.Namespace;
            globalScopeCache    = SimpleCache.CreateStruct(() => new PdbGlobalScope(this));
            builtinSymbolsCache = new DictionaryCache <TypeIndex, PdbSymbol>(CreateBuiltinSymbol);
            allSymbolsCache     = new ArrayCache <PdbSymbol>(PdbFile.TpiStream.TypeRecordCount, CreateSymbol);
            definedSymbolsCache = new ArrayCache <PdbSymbol>(PdbFile.TpiStream.TypeRecordCount, true, GetDefinedSymbol);
            constantsCache      = SimpleCache.CreateStruct(() =>
            {
                Dictionary <string, ConstantSymbol> constants = new Dictionary <string, ConstantSymbol>();

                foreach (SymbolRecordKind kind in ConstantSymbol.Kinds)
                {
                    foreach (ConstantSymbol c in PdbFile.PdbSymbolStream[kind].OfType <ConstantSymbol>())
                    {
                        if (!constants.ContainsKey(c.Name))
                        {
                            constants.Add(c.Name, c);
                        }
                    }
                }
                return((IReadOnlyDictionary <string, ConstantSymbol>)constants);
            });
        }
Example #4
0
        public void Should_invoke_route_description_provider_with_path_of_route()
        {
            // Given
            const string expectedPath = "/some/path/{capture}";

            var module = new FakeNancyModule(with =>
            {
                with.AddGetRoute(expectedPath);
            });

            var catalog = A.Fake <INancyModuleCatalog>();

            A.CallTo(() => catalog.GetAllModules(A <NancyContext> ._)).Returns(new[] { module });

            var descriptionProvider =
                A.Fake <IRouteDescriptionProvider>();

            // When
            var cache = new RouteCache(
                catalog,
                A.Fake <INancyContextFactory>(),
                this.routeSegmentExtractor,
                descriptionProvider,
                A.Fake <ICultureService>(),
                ArrayCache.Empty <IRouteMetadataProvider>());

            // Then
            A.CallTo(() => descriptionProvider.GetDescription(A <LegacyNancyModule> ._, expectedPath)).MustHaveHappened();
        }
Example #5
0
        /// <summary>
        /// Takes the registration tasks and calls the relevant methods to register them
        /// </summary>
        /// <param name="registrationTasks">Registration tasks</param>
        protected override sealed void RegisterRegistrationTasks(IEnumerable <IRegistrations> registrationTasks)
        {
            foreach (var applicationRegistrationTask in registrationTasks.ToList())
            {
                var applicationTypeRegistrations = applicationRegistrationTask.TypeRegistrations == null?
                                                   ArrayCache.Empty <TypeRegistration>() :
                                                       applicationRegistrationTask.TypeRegistrations.ToArray();

                this.RegisterTypes(this.ApplicationContainer, applicationTypeRegistrations.Where(tr => tr.Lifetime != Lifetime.PerRequest));
                this.RequestScopedTypes = this.RequestScopedTypes.Concat(applicationTypeRegistrations.Where(tr => tr.Lifetime == Lifetime.PerRequest)
                                                                         .Select(tr => new TypeRegistration(tr.RegistrationType, tr.ImplementationType, Lifetime.Singleton)))
                                          .ToArray();

                var applicationCollectionRegistrations = applicationRegistrationTask.CollectionTypeRegistrations == null?
                                                         ArrayCache.Empty <CollectionTypeRegistration>() :
                                                             applicationRegistrationTask.CollectionTypeRegistrations.ToArray();

                this.RegisterCollectionTypes(this.ApplicationContainer, applicationCollectionRegistrations.Where(tr => tr.Lifetime != Lifetime.PerRequest));
                this.RequestScopedCollectionTypes = this.RequestScopedCollectionTypes.Concat(applicationCollectionRegistrations.Where(tr => tr.Lifetime == Lifetime.PerRequest)
                                                                                             .Select(tr => new CollectionTypeRegistration(tr.RegistrationType, tr.ImplementationTypes, Lifetime.Singleton)))
                                                    .ToArray();

                var applicationInstanceRegistrations = applicationRegistrationTask.InstanceRegistrations;

                if (applicationInstanceRegistrations != null)
                {
                    this.RegisterInstances(this.ApplicationContainer, applicationInstanceRegistrations);
                }
            }
        }
Example #6
0
        private static T[] LoadCacheObjects <T>(string id) where T : ICacheable
        {
            try
            {
                if (CacheService == null)
                {
                    return(null);
                }
                if (string.IsNullOrEmpty(id))
                {
                    return(null);
                }

                ArrayCache <T> arrayCache = CacheService.Get <ArrayCache <T> >(id) as ArrayCache <T>;
                if (arrayCache == null)
                {
                    return(null);
                }
                return(arrayCache.Objects);
            }
            catch (Exception ex)
            {
                LogProxy.Error(ex, false);
                return(null);
            }
        }
Example #7
0
        public void Should_invoke_route_description_provider_with_module_that_route_is_defined_in()
        {
            // Given
            var module = new FakeNancyModule(with =>
            {
                with.AddGetRoute("/");
            });

            var catalog = A.Fake <INancyModuleCatalog>();

            A.CallTo(() => catalog.GetAllModules(A <NancyContext> ._)).Returns(new[] { module });

            var descriptionProvider =
                A.Fake <IRouteDescriptionProvider>();

            // When
            var cache = new RouteCache(
                catalog,
                A.Fake <INancyContextFactory>(),
                this.routeSegmentExtractor,
                descriptionProvider,
                A.Fake <ICultureService>(),
                ArrayCache.Empty <IRouteMetadataProvider>());

            // Then
            A.CallTo(() => descriptionProvider.GetDescription(module, A <string> ._)).MustHaveHappened();
        }
Example #8
0
        public void ShouldRetrieveFromAnEvenNumberedLengthCache()
        {
            ICache <TestKey, int> cache = new ArrayCache <TestKey, int>(default(HashCodeComparer <TestKey>));

            cache.GetOrAdd(new TestKey(3), t => 3);
            cache.GetOrAdd(new TestKey(1), t => 1);
            cache.GetOrAdd(new TestKey(7), t => 7);
            cache.GetOrAdd(new TestKey(4), t => 4);
            cache.GetOrAdd(new TestKey(6), t => 6);
            cache.GetOrAdd(new TestKey(2), t => 2);
            cache.GetOrAdd(new TestKey(8), t => 8);
            cache.GetOrAdd(new TestKey(5), t => 5);

            cache.Count.ShouldBe(8);

            var three = cache.GetOrAdd(new TestKey(3), null);

            three.ShouldBe(3);

            var five = cache.GetOrAdd(new TestKey(5), null);

            five.ShouldBe(5);

            var six = cache.GetOrAdd(new TestKey(6), null);

            six.ShouldBe(6);
        }
Example #9
0
        private static void AddCache <T>(string id, T[] objs) where T : ICacheable, new()
        {
            try
            {
                if (CacheService == null)
                {
                    return;
                }

                if (string.IsNullOrEmpty(id))
                {
                    return;
                }

                ArrayCache <T> arrayCache = new ArrayCache <T>();

                arrayCache.Id      = id;
                arrayCache.Objects = objs;
                arrayCache.Version = DateTime.Now.Ticks;

                CacheService.Set(arrayCache);
            }
            catch (Exception ex)
            {
                LogProxy.Error(ex, false);
            }
        }
Example #10
0
        public void IfCheckingFunctionDoesntPassOnceMergeAreaThrowsException()
        {
            var arrayCache = new ArrayCache <int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max, (a, b) => { return(a != b); });
        }
Example #11
0
        internal static byte[] UrlEncodeToBytes(byte[] bytes, int offset, int count)
        {
            if (bytes == null)
            {
                throw new ArgumentNullException("bytes");
            }

            int blen = bytes.Length;

            if (blen == 0)
            {
                return(ArrayCache.Empty <byte>());
            }

            if (offset < 0 || offset >= blen)
            {
                throw new ArgumentOutOfRangeException("offset");
            }

            if (count < 0 || count > blen - offset)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            MemoryStream result = new MemoryStream(count);
            int          end    = offset + count;

            for (int i = offset; i < end; i++)
            {
                UrlEncodeChar((char)bytes[i], result, false);
            }

            return(result.ToArray());
        }
    private void Awake()
    {
        m_cache_v3  = new ArrayCache <Vector3>();
        m_cache_v2  = new ArrayCache <Vector2>();
        m_cache_int = new ArrayCache <int>();

        float max = 0;

        m_watch         = new System.Diagnostics.Stopwatch();
        m_heightmap_len = 1 << config.Iterations;
        m_heightmap     = HeightMapFactory.CreateHeightMapByFractal(config.Iterations, config.H, config.min, config.max, config.seed, config.type);
        max             = config.max;
        HeightMapFilter.FilterFIR(m_heightmap, m_heightmap_len + 1, fir_config.times, fir_config.k);

        //m_heightmap_len = config_line.size -1;
        //m_heightmap = HeightMapFuzzyLandscaping.CreateHeightMap(config_line.size, config_line.seed, config_line.max,config_line.smooth_step);

        //m_heightmap_len = config_line.size - 1;
        //m_heightmap = HeightMapFuzzyLandscaping.CreateMapByLine(config_line.size, config_line.seed, config_line.max, config_line.line_num,config_line.smooth_step);

        //m_heightmap_len = config_particle.size - 1;
        //m_heightmap = HeightMapParticleDeposition.CreateMap(config_particle.size, config_particle.seed, config_particle.deposition_time, config_particle.deposition_deap, config_particle.deposition_size,config_particle.each_h,out max);
        //HeightMapVolcano.ToVolcano(m_heightmap, m_heightmap_len + 1, max * 0.5f);
        //HeightMapFilter.FilterFIR(m_heightmap, m_heightmap_len + 1, fir_config.times, fir_config.k);


        InitMeshMap();
        var mask      = SurfaceMaskCreator.CreateMask(m_heightmap_len);
        var maskcolor = SurfaceMaskCreator.GeneralMaskData(m_heightmap_len, max, m_heightmap, 0);

        mask.SetPixels(maskcolor);
        mask.Apply();
        PieceMat.SetTexture("_Mask", mask);
    }
Example #13
0
        public void Clear()
        {
            int populateCount = 0;
            ArrayCache <string> arrayCache = new ArrayCache <string>(testArray.Length, index =>
            {
                populateCount++;
                return(testArray[index]);
            });

            Assert.Equal(testArray.Length, arrayCache.Count);
            for (int i = 0; i < arrayCache.Count; i++)
            {
                Assert.Equal(testArray[i], arrayCache[i]);
            }
            Assert.Equal(testArray.Length, populateCount);
            arrayCache.Clear();
            for (int i = 0; i < arrayCache.Count; i++)
            {
                Assert.Equal(testArray[i], arrayCache[i]);
            }
            Assert.Equal(testArray.Length * 2, populateCount);
            arrayCache.InvalidateCache();
            for (int i = 0; i < arrayCache.Count; i++)
            {
                Assert.Equal(testArray[i], arrayCache[i]);
            }
            Assert.Equal(testArray.Length * 3, populateCount);
        }
            protected override IEnumerable <IRequestStartup> RegisterAndGetRequestStartupTasks(FakeContainer container, Type[] requestStartupTypes)
            {
                this.RequestStartupTasksResolveContainer = container;

                this.GetRequestStartupTasksCalled = true;

                return(this.OverriddenRequestStartupTasks ?? ArrayCache.Empty <IRequestStartup>());
            }
        public void Should_not_trim_trailing_slash_if_requesting_root()
        {
            // Given, When
            var results = this.matcher.Match("/", "/", ArrayCache.Empty <string>(), null);

            // Then
            results.IsMatch.ShouldBeTrue();
        }
Example #16
0
        public void IfMergeThrowsExceptionCheckMergedAreaFails()
        {
            var arrayCache = new ArrayCache <int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);

            Assert.IsFalse(arrayCache.CheckMergeArea(new Point(12, 12), MakeTestArray(10, 10, 1), MergeWithException));
        }
Example #17
0
        public void IfMergeDoesNotThrowsExceptionCheckMergedAreaPasses()
        {
            var arrayCache = new ArrayCache <int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);

            Assert.IsTrue(arrayCache.CheckMergeArea(new Point(13, 13), MakeTestArray(10, 10, 1), MergeWithException));
        }
Example #18
0
        public void AccessingPointsOutsideArrayCacheThrowsExceptionBR()
        {
            var arrayCache = new ArrayCache <int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);

            arrayCache.GetMergedPoint(new Point(13, 13));
        }
Example #19
0
        public void AccessingPointsOutsideArrayCacheThrowsExceptionBR()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);

            arrayCache.GetMergedPoint(new Point(13, 13));
        }
Example #20
0
        public void CheckMergeTestsAgainstDefaultValue()
        {
            var arrayCache = new ArrayCache <int>(10, 10, 1);

            var areaToAdd = MakeTestArray(10, 10, 1);

            Assert.IsFalse(arrayCache.CheckMergeArea(new Point(0, 0), areaToAdd, MergeWithException));
        }
Example #21
0
        private DefaultViewFactory CreateFactory(params IViewEngine[] viewEngines)
        {
            if (viewEngines == null)
            {
                viewEngines = ArrayCache.Empty <IViewEngine>();
            }

            return(new DefaultViewFactory(this.resolver, viewEngines, this.renderContextFactory, this.conventions, this.rootPathProvider));
        }
Example #22
0
        public void ArrayCacheStoresAreasLargerThanDefaultSizeAfter2Merges()
        {
            var arrayCache = new ArrayCache <int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            arrayCache.MergeArea(new Point(4, 4), MakeTestArray(10, 10, 2), Math.Max);

            Assert.AreEqual(arrayCache.TL, new Point(3, 3));
            Assert.AreEqual(arrayCache.BR, new Point(13, 13));
        }
Example #23
0
        public void ArrayCacheCanBeInitialisedToAValue()
        {
            var arrayCache = new ArrayCache <int>(10, 10, 1);

            var areaToAdd    = MakeTestArray(10, 10, 0);
            var areaExpected = MakeTestArray(10, 10, 1);

            arrayCache.MergeArea(new Point(0, 0), areaToAdd, Math.Max);

            CollectionAssert.AreEqual(areaExpected, arrayCache.GetMergedArea());
        }
Example #24
0
        public ManualStaticContentTests()
        {
            this.bootstrapper = new ConfigurableBootstrapper(
                configuration =>
            {
                configuration.ApplicationStartup((c, p) => StaticContent.Enable(p));
                configuration.Modules(ArrayCache.Empty <Type>());
            });

            this.browser = new Browser(bootstrapper);
        }
Example #25
0
        public void ArrayCacheCanBeInitialisedToAValue()
        {
            var arrayCache = new ArrayCache<int>(10, 10, 1);

            var areaToAdd = MakeTestArray(10, 10, 0);
            var areaExpected = MakeTestArray(10, 10, 1);

            arrayCache.MergeArea(new Point(0, 0), areaToAdd, Math.Max);

            CollectionAssert.AreEqual(areaExpected, arrayCache.GetMergedArea());
        }
Example #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public DefaultModelBinderLocatorFixture()
        {
            var environment = new DefaultNancyEnvironment();

            environment.AddValue(JsonConfiguration.Default);

            var bindingDefaults =
                new BindingDefaults(environment);

            this.defaultBinder = new DefaultBinder(ArrayCache.Empty <ITypeConverter>(), ArrayCache.Empty <IBodyDeserializer>(), A.Fake <IFieldNameConverter>(), bindingDefaults);
        }
Example #27
0
        public void ArrayCacheStoresAreasWithinDefaultSize()
        {
            var arrayCache = new ArrayCache <int>(10, 10);

            var areaToAdd = MakeTestArray(10, 10, 1);

            arrayCache.MergeArea(new Point(0, 0), areaToAdd, Math.Max);

            CollectionAssert.AreEqual(areaToAdd, arrayCache.GetMergedArea());
            Assert.AreEqual(arrayCache.TL, new Point(0, 0));
            Assert.AreEqual(arrayCache.BR, new Point(9, 9));
        }
Example #28
0
        public void ArrayCacheMergesTwoInputAreasUsingFunction()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            arrayCache.MergeArea(new Point(4, 4), MakeTestArray(10, 10, 2), Math.Max);

            var mergedArea = arrayCache.GetMergedArea();

            Assert.AreEqual(mergedArea[4 - arrayCache.TL.x, 4 - arrayCache.TL.x], 2);
            Assert.AreEqual(mergedArea[3 - arrayCache.TL.x, 3 - arrayCache.TL.x], 1);
        }
Example #29
0
        /// <summary>
        /// Gets a delegate to handle converting a nancy response
        /// to the format required by OWIN and signals that the we are
        /// now complete.
        /// </summary>
        /// <param name="context">The Nancy Context.</param>
        /// <param name="environment">OWIN environment.</param>
        /// <param name="next">The next stage in the OWIN pipeline.</param>
        /// <param name="performPassThrough">A predicate that will allow the caller to determine if the request passes through to the
        /// next stage in the owin pipeline.</param>
        /// <returns>Delegate</returns>
        private static Task RequestComplete(
            NancyContext context,
            IDictionary <string, object> environment,
            Func <NancyContext, bool> performPassThrough,
            AppFunc next)
        {
            var owinResponseHeaders = Get <IDictionary <string, string[]> >(environment, "owin.ResponseHeaders");
            var owinResponseBody    = Get <Stream>(environment, "owin.ResponseBody");

            var nancyResponse = context.Response;

            if (!performPassThrough(context))
            {
                environment["owin.ResponseStatusCode"] = (int)nancyResponse.StatusCode;

                if (nancyResponse.ReasonPhrase != null)
                {
                    environment["owin.ResponseReasonPhrase"] = nancyResponse.ReasonPhrase;
                }

                foreach (var responseHeader in nancyResponse.Headers)
                {
                    owinResponseHeaders[responseHeader.Key] = new[] { responseHeader.Value };
                }

                if (!string.IsNullOrWhiteSpace(nancyResponse.ContentType))
                {
                    owinResponseHeaders["Content-Type"] = new[] { nancyResponse.ContentType };
                }

                if (nancyResponse.Cookies != null && nancyResponse.Cookies.Count != 0)
                {
                    const string setCookieHeaderKey = "Set-Cookie";
                    string[]     cookieHeader;
                    string[]     setCookieHeader = owinResponseHeaders.TryGetValue(setCookieHeaderKey, out cookieHeader)
                                                    ? cookieHeader
                                                    : ArrayCache.Empty <string>();
                    owinResponseHeaders[setCookieHeaderKey] = setCookieHeader
                                                              .Concat(nancyResponse.Cookies.Select(cookie => cookie.ToString()))
                                                              .ToArray();
                }

                nancyResponse.Contents(owinResponseBody);
            }
            else
            {
                return(next(environment));
            }

            context.Dispose();

            return(TaskHelpers.CompletedTask);
        }
        internal static void SetKeys([NotNull] List <Keys> keys)
        {
            Guard.ArgumentNotNull(keys, nameof(keys));

            if (!ArrayCache.TryGetValue(keys.Count, out _currentKeys))
            {
                _currentKeys = new Keys[keys.Count];
                ArrayCache.Add(keys.Count, _currentKeys);
            }

            keys.CopyTo(_currentKeys);
        }
Example #31
0
        public void CheckingFunctionMustPassOnceToAllowMerge()
        {
            var arrayCache = new ArrayCache <int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            arrayCache.MergeArea(new Point(12, 12), MakeTestArray(10, 10, 2), Math.Max, (a, b) => { return(a == 1); });

            //Check we have the correct value
            var mergedArea = arrayCache.GetMergedArea();

            Assert.AreEqual(mergedArea[13 - arrayCache.TL.x, 13 - arrayCache.TL.x], 2);
        }
Example #32
0
        public void ArrayCacheMergesTwoInputAreasUsingFunction()
        {
            var arrayCache = new ArrayCache <int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            arrayCache.MergeArea(new Point(4, 4), MakeTestArray(10, 10, 2), Math.Max);

            var mergedArea = arrayCache.GetMergedArea();

            Assert.AreEqual(mergedArea[4 - arrayCache.TL.x, 4 - arrayCache.TL.x], 2);
            Assert.AreEqual(mergedArea[3 - arrayCache.TL.x, 3 - arrayCache.TL.x], 1);
        }
Example #33
0
        public void ArrayCacheUsesInitialisedValueWhenCacheExpands()
        {
            var arrayCache = new ArrayCache <int>(10, 10, 1);

            var areaToAdd  = MakeTestArray(10, 10, 0);
            var areaToAdd2 = MakeTestArray(10, 10, 0);

            arrayCache.MergeArea(new Point(0, 0), areaToAdd, Math.Max);
            arrayCache.MergeArea(new Point(30, 30), areaToAdd2, Math.Max);

            Assert.AreEqual(arrayCache.GetMergedPoint(new Point(20, 20)), 1);
        }
Example #34
0
        public void ArrayCacheCanBeAccessedPointByPoint()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            arrayCache.MergeArea(new Point(4, 4), MakeTestArray(10, 10, 2), Math.Max);

            var mergedArea = arrayCache.GetMergedArea();

            Assert.AreEqual(arrayCache.GetMergedPoint(new Point(3, 3)), 1);
            Assert.AreEqual(arrayCache.GetMergedPoint(new Point(4, 4)), 2);
            Assert.AreEqual(arrayCache.GetMergedPoint(new Point(13, 13)), 2);
        }
Example #35
0
        public void IfMergeThrowsExceptionCheckMergedAreaFails()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);

            Assert.IsFalse(arrayCache.CheckMergeArea(new Point(12, 12), MakeTestArray(10, 10, 1), MergeWithException));
        }
Example #36
0
        public void ArrayCacheStoresAreasWithinDefaultSizeNotOriginAligned()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            var areaToAdd = MakeTestArray(10, 10, 1);

            arrayCache.MergeArea(new Point(-10, -10), areaToAdd, Math.Max);

            CollectionAssert.AreEqual(areaToAdd, arrayCache.GetMergedArea());
            Assert.AreEqual(arrayCache.TL, new Point(-10, -10));
            Assert.AreEqual(arrayCache.BR, new Point(-1, -1));
            Assert.AreEqual(arrayCache.CacheWidth, 10);
            Assert.AreEqual(arrayCache.CacheHeight, 10);
        }
Example #37
0
        public void IfCheckingFunctionDoesntPassOnceCheckMergeAreaFails()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            Assert.IsFalse(arrayCache.CheckMergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max, (a, b) => { return a != b; }));
        }
Example #38
0
        public void ArrayCacheUsesInitialisedValueWhenCacheExpands()
        {
            var arrayCache = new ArrayCache<int>(10, 10, 1);

            var areaToAdd = MakeTestArray(10, 10, 0);
            var areaToAdd2 = MakeTestArray(10, 10, 0);

            arrayCache.MergeArea(new Point(0, 0), areaToAdd, Math.Max);
            arrayCache.MergeArea(new Point(30, 30), areaToAdd2, Math.Max);

            Assert.AreEqual(arrayCache.GetMergedPoint(new Point(20, 20)), 1);
        }
Example #39
0
        public void CheckingFunctionMustPassOnceToAllowMerge()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            arrayCache.MergeArea(new Point(12, 12), MakeTestArray(10, 10, 2), Math.Max, (a, b) => { return a == 1; });

            //Check we have the correct value
            var mergedArea = arrayCache.GetMergedArea();
            Assert.AreEqual(mergedArea[13 - arrayCache.TL.x, 13 - arrayCache.TL.x], 2);
        }
Example #40
0
        public void CheckingFunctionMustPassOnceToAllowMergeOfSubsetAndCanBeTested()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            Assert.IsTrue(arrayCache.CheckMergeArea(new Point(4, 4), MakeTestArray(5, 5, 2), Math.Max, (a, b) => { return b > a; }));
        }
Example #41
0
        public void IfMergeDoesNotThrowsExceptionCheckMergedAreaPasses()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);

            Assert.IsTrue(arrayCache.CheckMergeArea(new Point(13, 13), MakeTestArray(10, 10, 1), MergeWithException));
        }
Example #42
0
        public void ArrayCacheStoresAreasWithinDefaultSize()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            var areaToAdd = MakeTestArray(10, 10, 1);

            arrayCache.MergeArea(new Point(0, 0), areaToAdd, Math.Max);

            CollectionAssert.AreEqual(areaToAdd, arrayCache.GetMergedArea());
            Assert.AreEqual(arrayCache.TL, new Point(0, 0));
            Assert.AreEqual(arrayCache.BR, new Point(9, 9));
        }
Example #43
0
        public void CheckMergeTestsAgainstDefaultValue()
        {
            var arrayCache = new ArrayCache<int>(10, 10, 1);

            var areaToAdd = MakeTestArray(10, 10, 1);

            Assert.IsFalse(arrayCache.CheckMergeArea(new Point(0, 0), areaToAdd, MergeWithException));
        }
Example #44
0
        public void ArrayCacheStoresAreasLargerThanDefaultSize()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            var areaToAdd = MakeTestArray(20, 20, 1);

            arrayCache.MergeArea(new Point(-10, -10), areaToAdd, Math.Max);

            CollectionAssert.AreEqual(areaToAdd, arrayCache.GetMergedArea());
            Assert.AreEqual(arrayCache.TL, new Point(-10, -10));
            Assert.AreEqual(arrayCache.BR, new Point(9, 9));

            Assert.AreEqual(arrayCache.CacheWidth, 20);
            Assert.AreEqual(arrayCache.CacheHeight, 20);
        }
 private void InitialiseCaches(int cacheX, int cacheY)
 {
     mapCache = new ArrayCache<RoomTemplateTerrain>(cacheX, cacheY, RoomTemplateTerrain.Transparent);
     idCache = new ArrayCache<int>(cacheX, cacheY, defaultId);
 }
Example #46
0
        public void IfCheckingFunctionDoesntPassOnceMergeAreaThrowsException()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max, (a, b) => { return a != b; });
        }
Example #47
0
        public void ArrayCacheStoresAreasLargerThanDefaultSizeAfter2Merges()
        {
            var arrayCache = new ArrayCache<int>(10, 10);

            arrayCache.MergeArea(new Point(3, 3), MakeTestArray(10, 10, 1), Math.Max);
            arrayCache.MergeArea(new Point(4, 4), MakeTestArray(10, 10, 2), Math.Max);

            Assert.AreEqual(arrayCache.TL, new Point(3, 3));
            Assert.AreEqual(arrayCache.BR, new Point(13, 13));
        }