Exemple #1
0
        public void BadCardCodes()
        {
            List <CardCodeAndCount> deck = new List <CardCodeAndCount>();

            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE02", Count = 1
            });

            try
            {
                string code = LoRDeckEncoder.GetCodeFromDeck(deck);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }
            catch
            {
                Assert.Fail();
            }

            deck = new List <CardCodeAndCount>();
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01XX002", Count = 1
            });

            try
            {
                string code = LoRDeckEncoder.GetCodeFromDeck(deck);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }
            catch
            {
                Assert.Fail();
            }

            deck = new List <CardCodeAndCount>();
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = 0
            });

            try
            {
                string code = LoRDeckEncoder.GetCodeFromDeck(deck);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }
            catch
            {
                Assert.Fail();
            }
        }
Exemple #2
0
        public void MtTargonSet()
        {
            List <CardCodeAndCount> deck = new List <CardCodeAndCount>();

            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "03MT003", Count = 2
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "03MT010", Count = 3
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "02BW004", Count = 5
            });

            string code = LoRDeckEncoder.GetCodeFromDeck(deck);
            List <CardCodeAndCount> decoded = LoRDeckEncoder.GetDeckFromCode(code);

            Assert.True(VerifyRehydration(deck, decoded));
        }
Exemple #3
0
        public void BadCardCodes()
        {
            var decks = new[]
            {
                new List <CardCodeAndCount>
                {
                    new CardCodeAndCount {
                        CardCode = "01DE02", Count = 1
                    }
                },
                new List <CardCodeAndCount>
                {
                    new CardCodeAndCount {
                        CardCode = "01XX002", Count = 1
                    }
                },
                new List <CardCodeAndCount>
                {
                    new CardCodeAndCount {
                        CardCode = "01DE002", Count = 0
                    }
                }
            };

            foreach (var deck in decks)
            {
                Assert.ThrowsException <ArgumentException>(() => LoRDeckEncoder.GetCodeFromDeck(deck));
            }
        }
        private string GetDeckCode()
        {
            if (this.expeditionsState != null &&
                this.expeditionsState.Deck?.Any() == true)
            {
                var cards = new List <CardCodeAndCount>();
                foreach (var cardCode in this.expeditionsState.Deck)
                {
                    var card = cards.Find(c => c.CardCode == cardCode);
                    if (card == null)
                    {
                        cards.Add(new CardCodeAndCount {
                            CardCode = cardCode, Count = 1
                        });
                    }
                    else
                    {
                        card.Count++;
                    }
                }

                cards.Sort(new CardComparer());

                var deckCode = LoRDeckEncoder.GetCodeFromDeck(cards);

                this.logger.Debug($"Retrieved active expedition deck code: {deckCode}");

                cards.Print(this.logger);

                return(deckCode);
            }

            return(null);
        }
        public static string GetCodeFromDeck(List <CardCodeAndCount> cardCodeAndCounts)
        {
            bool isValid = LoRDeckEncoder.ValidCardCodesAndCounts(cardCodeAndCounts);

            if (!isValid)
            {
                return("");
            }

            return(LoRDeckEncoder.GetCodeFromDeck(cardCodeAndCounts));
        }
        public string ToLor()
        {
            var cardCounts        = GetCardCounts();
            var cardCodeAndCounts = cardCounts.Select(
                cardCount => new CardCodeAndCount()
            {
                CardCode = cardCount.Key.Id, Count = cardCount.Value
            }).ToList();

            return(LoRDeckEncoder.GetCodeFromDeck(cardCodeAndCounts) + Environment.NewLine);
        }
Exemple #7
0
        public void SmallDeck()
        {
            List <CardCodeAndCount> deck = new List <CardCodeAndCount>();

            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = 1
            });

            string code = LoRDeckEncoder.GetCodeFromDeck(deck);
            List <CardCodeAndCount> decoded = LoRDeckEncoder.GetDeckFromCode(code);

            Assert.True(VerifyRehydration(deck, decoded));
        }
Exemple #8
0
        public void SmallDeck()
        {
            var deck = new List <CardCodeAndCount>
            {
                new CardCodeAndCount {
                    CardCode = "01DE002", Count = 1
                }
            };

            string code    = LoRDeckEncoder.GetCodeFromDeck(deck);
            var    decoded = LoRDeckEncoder.GetDeckFromCode(code);

            Assert.IsTrue(VerifyRehydration(deck, decoded));
        }
Exemple #9
0
        public void OrderShouldNotMatter2()
        {
            //importantly this order test includes more than 1 card with counts >3, which are sorted by card code and appending to the <=3 encodings.
            List <CardCodeAndCount> deck1 = new List <CardCodeAndCount>();

            deck1.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = 4
            });
            deck1.Add(new CardCodeAndCount()
            {
                CardCode = "01DE003", Count = 2
            });
            deck1.Add(new CardCodeAndCount()
            {
                CardCode = "02DE003", Count = 3
            });
            deck1.Add(new CardCodeAndCount()
            {
                CardCode = "01DE004", Count = 5
            });

            List <CardCodeAndCount> deck2 = new List <CardCodeAndCount>();

            deck2.Add(new CardCodeAndCount()
            {
                CardCode = "01DE004", Count = 5
            });
            deck2.Add(new CardCodeAndCount()
            {
                CardCode = "01DE003", Count = 2
            });
            deck2.Add(new CardCodeAndCount()
            {
                CardCode = "02DE003", Count = 3
            });
            deck2.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = 4
            });

            string code1 = LoRDeckEncoder.GetCodeFromDeck(deck1);
            string code2 = LoRDeckEncoder.GetCodeFromDeck(deck2);

            Assert.Equal(code1, code2);
        }
Exemple #10
0
        public void BadVersion()
        {
            // make sure that a deck with an invalid version fails

            List <CardCodeAndCount> deck = new List <CardCodeAndCount>();

            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE003", Count = 2
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "02DE003", Count = 3
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE004", Count = 5
            });

            List <byte> bytesFromDeck = Base32.Decode(LoRDeckEncoder.GetCodeFromDeck(deck)).ToList();

            List <byte> result = new List <byte>();

            byte[] formatAndVersion = new byte[] { 88 }; // arbitrary invalid format/version
            result.AddRange(formatAndVersion);

            bytesFromDeck.RemoveAt(0);    // remove the actual format/version
            result.Concat(bytesFromDeck); // replace with invalid one

            try
            {
                string badVersionDeckCode       = Base32.Encode(result.ToArray());
                List <CardCodeAndCount> deckBad = LoRDeckEncoder.GetDeckFromCode(badVersionDeckCode);
            }
            catch (ArgumentException e)
            {
                string expectedErrorMessage = "The provided code requires a higher version of this library; please update.";
                Console.WriteLine(e.Message);
                Assert.Equal(expectedErrorMessage, e.Message);
            }
        }
Exemple #11
0
        public void BadCount()
        {
            List <CardCodeAndCount> deck = new List <CardCodeAndCount>();

            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = 0
            });
            bool failed = false;

            try
            {
                string code = LoRDeckEncoder.GetCodeFromDeck(deck);
            }
            catch (ArgumentException)
            {
                failed = true;
            }
            catch (Exception e)
            {
                Assert.True(false, $"Expected to throw an ArgumentException, but it threw {e}.");
            }
            Assert.True(failed, "Expected to throw an ArgumentException, but it succeeded.");

            failed = false;
            deck   = new List <CardCodeAndCount>();
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = -1
            });
            try
            {
                string code = LoRDeckEncoder.GetCodeFromDeck(deck);
            }
            catch (ArgumentException)
            {
                failed = true;
            }
            catch (Exception e)
            {
                Assert.True(false, $"Expected to throw an ArgumentException, but it threw {e}.");
            }
            Assert.True(failed, "Expected to throw an ArgumentException, but it succeeded.");
        }
Exemple #12
0
        public void DeckVersionIsTheMinimumLibraryVersionThatSupportsTheContainedFactions(string faction, int expectedVersion)
        {
            List <CardCodeAndCount> deck = new List <CardCodeAndCount>();

            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE001", Count = 1
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = $"01{faction}002", Count = 1
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01FR001", Count = 1
            });
            string deckCode = LoRDeckEncoder.GetCodeFromDeck(deck);

            int minSupportedLibraryVersion = ExtractVersionFromDeckCode(deckCode);

            Assert.Equal(expectedVersion, minSupportedLibraryVersion);
        }
Exemple #13
0
        public void EncodeDecodeRecommendedDecks()
        {
            List <string> codes = new List <string>();
            List <List <CardCodeAndCount> > decks = new List <List <CardCodeAndCount> >();

            //Load the test data from file.
            string line;

            using (StreamReader myReader = new StreamReader(GetTestDataFilePath()))
            {
                while ((line = myReader.ReadLine()) != null)
                {
                    codes.Add(line);
                    List <CardCodeAndCount> newDeck = new List <CardCodeAndCount>();
                    while (!string.IsNullOrEmpty(line = myReader.ReadLine()))
                    {
                        string[] parts = line.Split(new char[] { ':' });
                        newDeck.Add(new CardCodeAndCount()
                        {
                            Count = int.Parse(parts[0]), CardCode = parts[1]
                        });
                    }
                    decks.Add(newDeck);
                }
            }

            //Encode each test deck and ensure it's equal to the correct string.
            //Then decode and ensure the deck is unchanged.
            for (int i = 0; i < decks.Count; i++)
            {
                string encoded = LoRDeckEncoder.GetCodeFromDeck(decks[i]);
                Assert.Equal(codes[i], encoded);

                List <CardCodeAndCount> decoded = LoRDeckEncoder.GetDeckFromCode(encoded);
                Assert.True(VerifyRehydration(decks[i], decoded));
            }
        }
Exemple #14
0
        public void LargeDeck()
        {
            var deck = new List <CardCodeAndCount>
            {
                new CardCodeAndCount {
                    CardCode = "01DE002", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE003", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE004", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE005", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE006", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE007", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE008", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE009", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE010", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE011", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE012", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE013", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE014", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE015", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE016", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE017", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE018", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE019", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE020", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE021", Count = 3
                }
            };

            string code    = LoRDeckEncoder.GetCodeFromDeck(deck);
            var    decoded = LoRDeckEncoder.GetDeckFromCode(code);

            Assert.IsTrue(VerifyRehydration(deck, decoded));
        }
Exemple #15
0
        public void WorstCaseLength()
        {
            List <CardCodeAndCount> deck = new List <CardCodeAndCount>();

            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE003", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE004", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE005", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE006", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE007", Count = 5
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE008", Count = 6
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE009", Count = 7
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE010", Count = 8
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE011", Count = 9
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE012", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE013", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE014", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE015", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE016", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE017", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE018", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE019", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE020", Count = 4
            });
            deck.Add(new CardCodeAndCount()
            {
                CardCode = "01DE021", Count = 4
            });

            string code = LoRDeckEncoder.GetCodeFromDeck(deck);
            List <CardCodeAndCount> decoded = LoRDeckEncoder.GetDeckFromCode(code);

            Assert.True(VerifyRehydration(deck, decoded));
        }
Exemple #16
0
        public void OrderShouldNotMatter1()
        {
            var deck1 = new List <CardCodeAndCount>
            {
                new CardCodeAndCount {
                    CardCode = "01DE002", Count = 1
                },
                new CardCodeAndCount {
                    CardCode = "01DE003", Count = 2
                },
                new CardCodeAndCount {
                    CardCode = "02DE003", Count = 3
                }
            };

            var deck2 = new List <CardCodeAndCount>
            {
                new CardCodeAndCount {
                    CardCode = "01DE003", Count = 2
                },
                new CardCodeAndCount {
                    CardCode = "02DE003", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE002", Count = 1
                }
            };

            string code1 = LoRDeckEncoder.GetCodeFromDeck(deck1);
            string code2 = LoRDeckEncoder.GetCodeFromDeck(deck2);

            Assert.AreEqual(code1, code2);

            var deck3 = new List <CardCodeAndCount>
            {
                new CardCodeAndCount {
                    CardCode = "01DE002", Count = 4
                },
                new CardCodeAndCount {
                    CardCode = "01DE003", Count = 2
                },
                new CardCodeAndCount {
                    CardCode = "02DE003", Count = 3
                }
            };

            var deck4 = new List <CardCodeAndCount>
            {
                new CardCodeAndCount {
                    CardCode = "01DE003", Count = 2
                },
                new CardCodeAndCount {
                    CardCode = "02DE003", Count = 3
                },
                new CardCodeAndCount {
                    CardCode = "01DE002", Count = 4
                }
            };

            string code3 = LoRDeckEncoder.GetCodeFromDeck(deck1);
            string code4 = LoRDeckEncoder.GetCodeFromDeck(deck2);

            Assert.AreEqual(code3, code4);
        }
Exemple #17
0
        public void OrderShouldNotMatter1()
        {
            List <CardCodeAndCount> deck1 = new List <CardCodeAndCount>();

            deck1.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = 1
            });
            deck1.Add(new CardCodeAndCount()
            {
                CardCode = "01DE003", Count = 2
            });
            deck1.Add(new CardCodeAndCount()
            {
                CardCode = "02DE003", Count = 3
            });

            List <CardCodeAndCount> deck2 = new List <CardCodeAndCount>();

            deck2.Add(new CardCodeAndCount()
            {
                CardCode = "01DE003", Count = 2
            });
            deck2.Add(new CardCodeAndCount()
            {
                CardCode = "02DE003", Count = 3
            });
            deck2.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = 1
            });

            string code1 = LoRDeckEncoder.GetCodeFromDeck(deck1);
            string code2 = LoRDeckEncoder.GetCodeFromDeck(deck2);

            Assert.Equal(code1, code2);

            List <CardCodeAndCount> deck3 = new List <CardCodeAndCount>();

            deck3.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = 4
            });
            deck3.Add(new CardCodeAndCount()
            {
                CardCode = "01DE003", Count = 2
            });
            deck3.Add(new CardCodeAndCount()
            {
                CardCode = "02DE003", Count = 3
            });

            List <CardCodeAndCount> deck4 = new List <CardCodeAndCount>();

            deck4.Add(new CardCodeAndCount()
            {
                CardCode = "01DE003", Count = 2
            });
            deck4.Add(new CardCodeAndCount()
            {
                CardCode = "02DE003", Count = 3
            });
            deck4.Add(new CardCodeAndCount()
            {
                CardCode = "01DE002", Count = 4
            });

            string code3 = LoRDeckEncoder.GetCodeFromDeck(deck1);
            string code4 = LoRDeckEncoder.GetCodeFromDeck(deck2);

            Assert.Equal(code3, code4);
        }