Beispiel #1
0
        public void GetIdealBodyWeightFromDataSource_Using_Moq()
        {
            List <WeightCalculator> weights = new List <WeightCalculator>()
            {
                new WeightCalculator()
                {
                    Height = 175, Gender = 'm'
                },
                new WeightCalculator()
                {
                    Height = 172, Gender = 'm'
                },
                new WeightCalculator()
                {
                    Height = 175, Gender = 'w'
                }
            };
            mock <IDataRepository> repo = new mock <IDataRepository>();

            repo.Setup(w => w.GetWeights()).Returns(weights);
            WeightCalculator weightCalculator = new WeightCalculator(repo.Object);
            var actual = weightCalculator.GetIdealBodyWeightFromDataSource();

            double[] expected = { 62.5, 62.75 };
            actual.Should().Equal(expected);
        }
Beispiel #2
0
        public void GetIdealBodyWeightFromDataSource_WithGoodinputs_Returns_Correct_Results()
        {
            WeightCalculator weightCalculator = new WeightCalculator(new FakeWeightRepository());
            List <double>    actual           = weightCalculator.GetIdealBodyWeightFromDataSource();

            double[] expected = { 62.5, 62.75, 74 };
            CollectionAssertion.AreEqual(expected, actual);
        }
Beispiel #3
0
 public Task <PackageInfo> GetPackageInfo(List <Guid> productIds)
 {
     return(Task.FromResult(new PackageInfo()
     {
         Weight = WeightCalculator.CalculateWeight(productIds.Count),
         Volume = VolumeEstimator.Calculate(productIds.Count)
     }));
 }
Beispiel #4
0
        public Task <PackageInfo> GetPackageInfo(IEnumerable <int> productIds)
        {
            var count = productIds.Count();

            return(Task.FromResult(new PackageInfo()
            {
                Weight = WeightCalculator.CalculateWeight(count),
                Volume = VolumeEstimator.Calculate(count)
            }));
        }
        public void Validate_With_BadSex_Returns_False()
        {
            WeightCalculator weightCalculator = new WeightCalculator();

            weightCalculator.Sex = 't';

            bool actual = weightCalculator.Validate();

            actual.Should().BeFalse();
        }
        public void GetIdealBodyWeightFromDataSource_WithGoodInputs_Returns_Correct_Results()
        {
            WeightCalculator weightCalculator = new WeightCalculator(new FakeWeightRepository());

            List <double> actual = weightCalculator.GetIdealBodyWeightFromDataSource();

            double[] expected = { 62.5, 62.75, 74 };

            actual.Should().BeEquivalentTo(expected);
        }
 public static bool Dijkstra <V, E>(
     this Graph <V, E> graph,
     int from,
     int to,
     WeightCalculator <E> calculator,
     out GraphPath <V, E> path,
     ExplorationCallbacks <V, E> callbacks = default
     )
 {
     return(graph.AStar(from, to, ZeroHeuristics, calculator, out path, callbacks));
 }
        public void MyTestMethod(double height, char sex, double expected)
        {
            WeightCalculator weightCalculator = new WeightCalculator
            {
                Height = height,
                Sex    = sex
            };

            var actual = weightCalculator.GetIdealBodyWeight();

            actual.Should().Be(expected);
        }
        public void WorkingWith_Data_Driven_Tests(double height, char sex, double expected)
        {
            WeightCalculator weightCalculator = new WeightCalculator
            {
                Height = height,
                Sex    = sex
            };

            var actual = weightCalculator.GetIdealBodyWeight();

            actual.Should().Be(expected);
        }
Beispiel #10
0
        public void GetIdealBodyWeight_Gender_B_And_Height_180_return_0()
        {
            //Arrange
            WeightCalculator sut = new WeightCalculator {
                Gender = 'b', Height = 180
            };

            //Act
            double actual   = sut.GetIdealBodyWeight();
            double expected = 0;

            //Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #11
0
        public IActionResult Clans()
        {
            logger.LogInformation("Clans");

            var data = new Clans();

            var badges = from c in db.Clans
                         select new ClanModel
            {
                Description      = c.Description,
                Image            = c.BadgeUrl,
                IsWarLogPublic   = c.IsWarLogPublic,
                Level            = c.ClanLevel,
                Location         = c.LocationName,
                Losses           = c.WarLosses,
                Name             = c.Name,
                Points           = c.ClanPoints,
                RequiredTrophies = c.RequiredTrophies,
                Tag          = c.Tag,
                Ties         = c.WarTies,
                Type         = c.Type,
                WarFrequency = c.WarFrequency,
                Wins         = c.WarWins,
                WinStreak    = c.WarWinStreak
            };

            var weights = new WeightCalculator(db).Calculate().ToDictionary(w => w.Tag);

            foreach (var row in badges)
            {
                if (weights.TryGetValue(row.Tag, out WeightCalculator.Results weight))
                {
                    row.Th14Count       = weight.Th14Count;
                    row.Th13Count       = weight.Th13Count;
                    row.Th12Count       = weight.Th12Count;
                    row.Th11Count       = weight.Th11Count;
                    row.Th10Count       = weight.Th10Count;
                    row.Th9Count        = weight.Th9Count;
                    row.Th8Count        = weight.Th8Count;
                    row.ThLowCount      = weight.ThLowCount;
                    row.EstimatedWeight = weight.EstimatedWeight;
                }

                data.Add(row);
            }

            return(Ok(data));
        }
        public void GetIdealBodyWeight_WithBadSex_And_Height_180_Throw_Exception()
        {
            // Arrange
            WeightCalculator sut = new WeightCalculator
            {
                Sex    = 'r',
                Height = 180
            };

            // Act
            double actual   = sut.GetIdealBodyWeight();
            double expected = 0;

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void GetIdealBodyWeight_WithSex_W_And_Height_180_Return_65()
        {
            // Arrange
            WeightCalculator sut = new WeightCalculator
            {
                Sex    = 'w',
                Height = 180
            };

            // Act
            double actual   = sut.GetIdealBodyWeight();
            double expected = 65;

            // Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #14
0
        public static bool AStarWithPlan <V, E>(
            this Graph <V, E> graph,
            int from,
            int to,
            Heuristics heuristics,
            WeightCalculator <E> weightCalculator,
            out GraphPlan <V, E> navigator,
            ExplorationCallbacks <V, E> callbacks = default
            )
        {
            if (graph.AStar(from, to, heuristics, weightCalculator, out var path, callbacks))
            {
                navigator = new GraphPlan <V, E>(path);
                return(true);
            }

            navigator = default;
            return(false);
        }
Beispiel #15
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public object FunctionHandler(InputModel input, ILambdaContext context)
        {
            if (input == null)
            {
                return(new List <int> {
                    42
                });
            }

            if (input.WorkStart > input.BusiestHour || input.BusiestHour > input.WorkEnd)
            {
                return(new List <int>());
            }

            var weightCalculator = new WeightCalculator();
            var spreadCalculator = new SpreadCalculator();

            var weights = weightCalculator.Calculate(input);
            var spread  = spreadCalculator.Calculate(input, weights);

            return(spread);
        }
        public void WeightCalculateTest()
        {
            var calculator = new WeightCalculator();

            var input = new InputModel
            {
                AverageCustomersPerDay = 30,
                WorkStart   = 9,
                WorkEnd     = 18,
                BusiestHour = 16
            };
            var weights = calculator.Calculate(input);

            //hours: 9 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18
            //index: 0 - 1  - 2  - 3  - 4  - 5  - 6  - 7  - 8  - 9
            Assert.Equal(10, weights.Count);

            var busiestHourWeight = weights[7];

            Assert.Equal(busiestHourWeight, weights.Max());
            Assert.Equal(7.67, busiestHourWeight, 2);
            Assert.Equal(1, weights[0]);
            Assert.Equal(1, weights[9]);
        }
        public void SpreadCalculateFullTest()
        {
            var calculator = new SpreadCalculator();

            var input = new InputModel
            {
                AverageCustomersPerDay = 30,
                WorkStart   = 9,
                WorkEnd     = 18,
                BusiestHour = 16
            };
            var weights = new WeightCalculator().Calculate(input);

            var customersForMonth = Enumerable.Repeat(0, 1000)
                                    .Select(x => calculator.Calculate(input, weights));

            //customers per hour. indicating number of customers from the interval start time till the next interval
            //9 - .5 - 10 - .5 - 11 - .5 - 12 - .5 - 13 - .5 - 14 - .5 - 15 - .5 - 16 - .5 - 17 - .5
            Assert.All(customersForMonth, (spread) => Assert.Equal(18, spread.Count));

            var totalCustomersPerDay = customersForMonth.Select(spread => spread.Sum());

            Assert.True(Math.Abs(50 - totalCustomersPerDay.Average()) < 1);
        }
        public void GetIdealBodyWeightFromDataSource_Using_FakeItEasy()
        {
            List <WeightCalculator> weights = new List <WeightCalculator>()
            {
                new WeightCalculator {
                    Height = 175, Sex = 'w'
                },                                               // 62.5
                new WeightCalculator {
                    Height = 167, Sex = 'm'
                },                                               // 62.75
            };

            IDataRepository repo = A.Fake <IDataRepository>();

            A.CallTo(() => repo.GetWeights()).Returns(weights);

            WeightCalculator calculator = new WeightCalculator(repo);

            var actual = calculator.GetIdealBodyWeightFromDataSource();

            double[] expected = { 62.5, 62.75 };

            actual.Should().Equal(expected);
        }
Beispiel #19
0
        public static bool AStar <V, E>(
            this Graph <V, E> graph,
            int from,
            int to,
            Heuristics heuristics,
            WeightCalculator <E> calculator,
            out GraphPath <V, E> path,
            ExplorationCallbacks <V, E> callbacks = default
            )
        {
            var gScore = new Dictionary <int, float> {
                { from, 0 }
            };
            var fScore = new Dictionary <int, float> {
                { from, heuristics(from, to) }
            };
            var open = new SortedSet <int>(Comparer <int> .Create((first, second) => {
                var a = fScore[first];
                var b = fScore[second];
                return(a.CompareTo(b));
            }))
            {
                from
            };

            var history = new Dictionary <int, int>();

            while (!open.IsEmpty())
            {
                var i = open.First();
                if (i == to)
                {
                    path = ReTrace(history, i, graph);
                    return(true);
                }

                open.Remove(i);
                var edges = graph.EdgesFrom(i).ToArray();
                foreach (var(edge, neighborIndex) in edges)
                {
                    callbacks.OnVisit?.Invoke(i, neighborIndex, edge);
                    var found = callbacks.EdgeFilter?.Invoke(i, neighborIndex, edge);
                    if (!found.GetValueOrDefault(true))
                    {
                        continue;
                    }

                    var attempt = gScore[i] + calculator(i, neighborIndex, edge);
                    if (!gScore.ContainsKey(neighborIndex) || attempt < gScore[neighborIndex])
                    {
                        history[neighborIndex] = i;
                        gScore[neighborIndex]  = attempt;
                        fScore[neighborIndex]  = attempt + heuristics(neighborIndex, to);
                        callbacks.OnSelected?.Invoke(i, neighborIndex, edge);
                        if (!open.Contains(neighborIndex))
                        {
                            open.Add(neighborIndex);
                        }
                    }
                }
            }

            path = null;
            return(false);
        }
 public WeightConverter()
 {
     WeightCalc = new WeightCalculator();
     InitializeComponent();
 }