Exemplo n.º 1
0
 public BadgeCommands(
     IBadgeRepo badgeRepo,
     IUserRepo userRepo,
     IMessageSender messageSender,
     IImmutableSet <PkmnSpecies> knownSpecies,
     HashSet <PkmnSpecies>?whitelist = null
     )
 {
     _badgeRepo          = badgeRepo;
     _userRepo           = userRepo;
     _messageSender      = messageSender;
     _knownSpecies       = knownSpecies;
     _whitelist          = whitelist;
     _pokedexModeRegions = new Dictionary <string, RegionInformation>()
     {
         { "kanto", new RegionInformation(Generation.Gen1, _knownSpecies.Count(pokemon => pokemon.GetGeneration() == Generation.Gen1)) },
         { "johto", new RegionInformation(Generation.Gen2, _knownSpecies.Count(pokemon => pokemon.GetGeneration() == Generation.Gen2)) },
         { "hoenn", new RegionInformation(Generation.Gen3, _knownSpecies.Count(pokemon => pokemon.GetGeneration() == Generation.Gen3)) },
         { "sinnoh", new RegionInformation(Generation.Gen4, _knownSpecies.Count(pokemon => pokemon.GetGeneration() == Generation.Gen4)) },
         { "unova", new RegionInformation(Generation.Gen5, _knownSpecies.Count(pokemon => pokemon.GetGeneration() == Generation.Gen5)) },
         { "kalos", new RegionInformation(Generation.Gen6, _knownSpecies.Count(pokemon => pokemon.GetGeneration() == Generation.Gen6)) },
         { "alola", new RegionInformation(Generation.Gen7, _knownSpecies.Count(pokemon => pokemon.GetGeneration() == Generation.Gen7)) },
         { "galar", new RegionInformation(Generation.Gen8, _knownSpecies.Count(pokemon => pokemon.GetGeneration() == Generation.Gen8)) },
         { "fakemons", new RegionInformation(Generation.GenFake, _knownSpecies.Count(pokemon => pokemon.GetGeneration() == Generation.GenFake)) },
         { PokedexModeNational, new RegionInformation(Generation.GenFake, _knownSpecies.Count(pokemon => pokemon.GetGeneration() != Generation.GenFake)) }
     };
 }
Exemplo n.º 2
0
        /// <summary>
        /// Tests various aspects of a set.  This should be called only from the unordered or sorted overloads of this method.
        /// </summary>
        /// <typeparam name="T">The type of element stored in the set.</typeparam>
        /// <param name="emptySet">The empty set.</param>
        protected void EmptyTestHelper <T>(IImmutableSet <T> emptySet)
        {
            Contract.Requires(emptySet != null);

            Assert.Equal(0, emptySet.Count);   //, "Empty set should have a Count of 0");
            Assert.Equal(0, emptySet.Count()); //, "Enumeration of an empty set yielded elements.");
            Assert.Same(emptySet, emptySet.Clear());
        }
        public void DeserializeHashSetInterface()
        {
            string json = @"[
  ""One"",
  ""II"",
  ""3""
]";

            IImmutableSet <string> l = JsonConvert.DeserializeObject <IImmutableSet <string> >(json);

            Assert.AreEqual(3, l.Count());
            Assert.IsTrue(l.Contains("3"));
            Assert.IsTrue(l.Contains("II"));
            Assert.IsTrue(l.Contains("One"));
        }
Exemplo n.º 4
0
        public static void ReadPrimitiveIImmutableSetT()
        {
            IImmutableSet <int> result   = JsonSerializer.Parse <IImmutableSet <int> >(Encoding.UTF8.GetBytes(@"[1,2]"));
            List <int>          expected = new List <int> {
                1, 2
            };

            foreach (int i in result)
            {
                expected.Remove(i);
            }

            Assert.Equal(0, expected.Count);

            result = JsonSerializer.Parse <IImmutableSet <int> >(Encoding.UTF8.GetBytes(@"[]"));
            Assert.Equal(0, result.Count());
        }
        public static void ReadPrimitiveIImmutableSetT()
        {
            IImmutableSet <int> result   = JsonSerializer.Deserialize <IImmutableSet <int> >(Encoding.UTF8.GetBytes(@"[1,2]"));
            List <int>          expected = new List <int> {
                1, 2
            };

            foreach (int i in result)
            {
                expected.Remove(i);
            }

            Assert.Equal(0, expected.Count);

            result = JsonSerializer.Deserialize <IImmutableSet <int> >(Encoding.UTF8.GetBytes(@"[]"));
            Assert.Equal(0, result.Count());

            Assert.Throws <JsonException>(() => JsonSerializer.Deserialize <StringIImmutableSetWrapper>(@"[""1"",""2""]"));
            Assert.Throws <JsonException>(() => JsonSerializer.Deserialize <StringIImmutableSetWrapper>(@"[]"));
        }
Exemplo n.º 6
0
        public async Task ReadPrimitiveIImmutableSetT()
        {
            IImmutableSet <int> result = await JsonSerializerWrapperForString.DeserializeWrapper <IImmutableSet <int> >(@"[1,2]");

            List <int> expected = new List <int> {
                1, 2
            };

            foreach (int i in result)
            {
                expected.Remove(i);
            }

            Assert.Equal(0, expected.Count);

            result = await JsonSerializerWrapperForString.DeserializeWrapper <IImmutableSet <int> >(@"[]");

            Assert.Equal(0, result.Count());

            await Assert.ThrowsAsync <NotSupportedException>(async() => await JsonSerializerWrapperForString.DeserializeWrapper <StringIImmutableSetWrapper>(@"[""1"",""2""]"));

            await Assert.ThrowsAsync <NotSupportedException>(async() => await JsonSerializerWrapperForString.DeserializeWrapper <StringIImmutableSetWrapper>(@"[]"));
        }
Exemplo n.º 7
0
 public static int length <T>(IImmutableSet <T> set) =>
 set.Count();