Esempio n. 1
0
        public static void Main(string[] args)
        {
            void ThrowInstructions()
            => throw new InvalidOperationException("You must indicate if 'build' or 'unbuild'");

            if (!Console.IsInputRedirected)
            {
                throw new InvalidOperationException("You must redirect the input to this application.");
            }

            if (args?.Length != 1)
            {
                ThrowInstructions();
            }

            switch (args[0].ToLowerInvariant())
            {
            case "build":
            {
                var words = GetLines().ToHashSet();
                var wdawg = Dawg.Create(words);
                Dawg.Verify(words, wdawg);
                Dawg.Write(wdawg, Console.OpenStandardOutput());
                break;
            }

            case "unbuild":
            {
                var rdawg   = Dawg.Read(Console.OpenStandardInput());
                var isFirst = true;
                using var writer = new StreamWriter(Console.OpenStandardOutput());
                foreach (var word in rdawg)
                {
                    if (!isFirst)
                    {
                        writer.WriteLine();
                    }
                    isFirst = false;
                    writer.Write(word);
                }
                break;
            }

            default:
            {
                ThrowInstructions();
                break;
            }
            }
        }
Esempio n. 2
0
        public static void Verify(ISet <string> words, Dawg dawg)
        {
            var d = dawg.ToHashSet();

            if (words.Count != d.Count || !words.IsSubsetOf(d))
            {
Esempio n. 3
0
 public static void Verify(IEnumerable <string> words, Dawg dawg)
 => Verify(words.ToHashSet(), dawg);