Пример #1
0
        public void OrderIrrelevantTest()
        {
            const int  resourceCount    = 99;
            const int  bucketCount      = 10;
            var        idealBalance     = (int)Math.Floor((double)(resourceCount) / bucketCount);
            List <int> resources        = Enumerable.Range(0, resourceCount).ToList();
            List <int> buckets          = Enumerable.Range(0, bucketCount).ToList();
            var        resourceBalancer = new BestFitBalancer <int, int>(buckets, resources);
            Dictionary <int, List <int> > balancerResults = resourceBalancer.GetDistribution(buckets);

            ValidateBalance(buckets, resources, balancerResults, idealBalance);

            // reverse inputs
            resources.Reverse();
            buckets.Reverse();
            resourceBalancer = new BestFitBalancer <int, int>(buckets, resources);
            Dictionary <int, List <int> > balancerResultsFromReversedInputs = resourceBalancer.GetDistribution(buckets);

            ValidateBalance(buckets, resources, balancerResultsFromReversedInputs, idealBalance);

            Assert.IsTrue(balancerResults.Keys.SequenceEqual(balancerResultsFromReversedInputs.Keys), "Bucket order");
            foreach (int bucket in balancerResults.Keys)
            {
                Assert.IsTrue(balancerResults[bucket].SequenceEqual(balancerResultsFromReversedInputs[bucket]), "Resource order");
            }
        }
Пример #2
0
 public void IdealCaseLessResourcesThanBuckets2Test()
 {
     const int bucketCount = 100;
     const int resourceCount = 30;
     var idealBalance = (int)Math.Floor((double)(resourceCount) / bucketCount);
     List<int> buckets = Enumerable.Range(0, bucketCount).ToList();
     List<int> resources = Enumerable.Range(0, resourceCount).ToList();
     var resourceBalancer = new BestFitBalancer<int, int>(buckets, resources);
     Dictionary<int, List<int>> balancerResults = resourceBalancer.GetDistribution(buckets);
     ValidateBalance(buckets, resources, balancerResults, idealBalance);
 }
Пример #3
0
        public void IdealCaseResourcesMatchBucketsTest()
        {
            const int  bucketCount      = 100;
            const int  resourceCount    = 100;
            var        idealBalance     = (int)Math.Floor((double)(resourceCount) / bucketCount);
            List <int> buckets          = Enumerable.Range(0, bucketCount).ToList();
            List <int> resources        = Enumerable.Range(0, resourceCount).ToList();
            var        resourceBalancer = new BestFitBalancer <int, int>(buckets, resources);
            Dictionary <int, List <int> > balancerResults = resourceBalancer.GetDistribution(buckets);

            ValidateBalance(buckets, resources, balancerResults, idealBalance);
        }
Пример #4
0
 public void HalfBucketsActiveTest()
 {
     const int resourceCount = 99;
     const int bucketCount = 10;
     const int activeBucketCount = bucketCount/2;
     var idealBalance = (int)Math.Floor((double)(resourceCount) / activeBucketCount);
     List<int> resources = Enumerable.Range(0, resourceCount).ToList();
     List<int> buckets = Enumerable.Range(0, bucketCount).ToList();
     List<int> activeBuckets = buckets.Take(activeBucketCount).ToList();
     var resourceBalancer = new BestFitBalancer<int, int>(buckets, resources);
     Dictionary<int, List<int>> balancerResults = resourceBalancer.GetDistribution(activeBuckets);
     ValidateBalance(activeBuckets, resources, balancerResults, idealBalance);
 }
Пример #5
0
        public void HalfBucketsActiveTest()
        {
            const int  resourceCount     = 99;
            const int  bucketCount       = 10;
            const int  activeBucketCount = bucketCount / 2;
            var        idealBalance      = (int)Math.Floor((double)(resourceCount) / activeBucketCount);
            List <int> resources         = Enumerable.Range(0, resourceCount).ToList();
            List <int> buckets           = Enumerable.Range(0, bucketCount).ToList();
            List <int> activeBuckets     = buckets.Take(activeBucketCount).ToList();
            var        resourceBalancer  = new BestFitBalancer <int, int>(buckets, resources);
            Dictionary <int, List <int> > balancerResults = resourceBalancer.GetDistribution(activeBuckets);

            ValidateBalance(activeBuckets, resources, balancerResults, idealBalance);
        }
Пример #6
0
        public void OrderIrrelevantTest()
        {
            const int resourceCount = 99;
            const int bucketCount = 10;
            var idealBalance = (int)Math.Floor((double)(resourceCount) / bucketCount);
            List<int> resources = Enumerable.Range(0, resourceCount).ToList();
            List<int> buckets = Enumerable.Range(0, bucketCount).ToList();
            var resourceBalancer = new BestFitBalancer<int, int>(buckets, resources);
            Dictionary<int, List<int>> balancerResults = resourceBalancer.GetDistribution(buckets);
            ValidateBalance(buckets, resources, balancerResults, idealBalance);

            // reverse inputs
            resources.Reverse();
            buckets.Reverse();
            resourceBalancer = new BestFitBalancer<int, int>(buckets, resources);
            Dictionary<int, List<int>> balancerResultsFromReversedInputs = resourceBalancer.GetDistribution(buckets);
            ValidateBalance(buckets, resources, balancerResultsFromReversedInputs, idealBalance);

            Assert.IsTrue(balancerResults.Keys.SequenceEqual(balancerResultsFromReversedInputs.Keys), "Bucket order");
            foreach (int bucket in balancerResults.Keys)
            {
                Assert.IsTrue(balancerResults[bucket].SequenceEqual(balancerResultsFromReversedInputs[bucket]), "Resource order");
            }
        }
Пример #7
0
        public void IdealCaseRangedTest()
        {
            const int MaxResourceCount = 20;
            const int MaxBucketCount = 20;

            for (int resourceCount = 1; resourceCount <= MaxResourceCount; resourceCount++)
            {
                for (int bucketCount = 1; bucketCount <= MaxBucketCount; bucketCount++)
                {
                    var idealBalance = (int)Math.Floor((double)(resourceCount) / bucketCount);
                    List<int> buckets = Enumerable.Range(0, bucketCount).ToList();
                    List<int> resources = Enumerable.Range(0, resourceCount).ToList();
                    var resourceBalancer = new BestFitBalancer<int, int>(buckets, resources);
                    Dictionary<int, List<int>> balancerResults = resourceBalancer.GetDistribution(buckets);
                    ValidateBalance(buckets, resources, balancerResults, idealBalance);
                }
            }
        }