Exemplo n.º 1
0
        public async Task <PokemonStatisticsList> GetPokemons_Statistics(List <string> names)
        {
            // Get statistics about a group of pokemon (avg, min, max), filter by names

            // Search for pokemon by name, if one doesn't exist, it is skipped
            List <Pokemon> results = new List <Pokemon>();

            foreach (var name in names)
            {
                var result = await _pokemonRepository.GetPokemon_ByName(name);

                if (result != null)
                {
                    results.Add(result);
                }
            }

            // Calculate statistics for group of Pokemon
            if (results.Count <= 0)
            {
                return(null);
            }
            PokemonStatisticsList statObj = PokemonCalculator.Calculate_Statistics(results);

            return(statObj);
        }
Exemplo n.º 2
0
        public void UnitTest_GetPokemonStatistics()
        {
            var p1 = new Pokemon()
            {
                Name           = "pokemon 1",
                PokedexEntry   = 1,
                Generation     = 1,
                Classification = "testing pokemon",
                EggGroup       = "tester",
                Hp             = 25,
                Attack         = 20,
                Defense        = 15,
                SpAtk          = 60,
                SpDef          = 50,
                Speed          = 65
            };

            var p2 = new Pokemon()
            {
                Name           = "pokemon 2",
                PokedexEntry   = 2,
                Generation     = 1,
                Classification = "testing pokemon",
                EggGroup       = "tester",
                Hp             = 39,
                Attack         = 52,
                Defense        = 43,
                SpAtk          = 105,
                SpDef          = 55,
                Speed          = 90
            };

            var list = new List <Pokemon>()
            {
                p1, p2
            };
            var statObj = PokemonCalculator.Calculate_Statistics(list);

            Assert.Equal <double>(25, statObj.Statistics["Hp"].Minimum);
            Assert.Equal <double>(32, statObj.Statistics["Hp"].Average);
            Assert.Equal <double>(39, statObj.Statistics["Hp"].Maximum);

            Assert.Equal <double>(20, statObj.Statistics["Attack"].Minimum);
            Assert.Equal <double>(36, statObj.Statistics["Attack"].Average);
            Assert.Equal <double>(52, statObj.Statistics["Attack"].Maximum);

            Assert.Equal <double>(15, statObj.Statistics["Defense"].Minimum);
            Assert.Equal <double>(29, statObj.Statistics["Defense"].Average);
            Assert.Equal <double>(43, statObj.Statistics["Defense"].Maximum);

            Assert.Equal <double>(60, statObj.Statistics["SpAtk"].Minimum);
            Assert.Equal <double>(82.5, statObj.Statistics["SpAtk"].Average);
            Assert.Equal <double>(105, statObj.Statistics["SpAtk"].Maximum);

            Assert.Equal <double>(50, statObj.Statistics["SpDef"].Minimum);
            Assert.Equal <double>(52.5, statObj.Statistics["SpDef"].Average);
            Assert.Equal <double>(55, statObj.Statistics["SpDef"].Maximum);

            Assert.Equal <double>(65, statObj.Statistics["Speed"].Minimum);
            Assert.Equal <double>(77.5, statObj.Statistics["Speed"].Average);
            Assert.Equal <double>(90, statObj.Statistics["Speed"].Maximum);
        }