Exemple #1
0
        public void State_factory_rejects_uneven_rows()
        {
            IStateReader sr = _container.GetInstance <IFactory>().CreateReader(
                new StringReader(
                    "101" + Environment.NewLine +
                    "10" + Environment.NewLine +
                    "111" + Environment.NewLine));

            sr.Read();
        }
Exemple #2
0
        public void Ensure_parse_good_input()
        {
            string input =
                "01000" + Environment.NewLine +
                "10011" + Environment.NewLine +
                "11001" + Environment.NewLine +
                "01000" + Environment.NewLine +
                "10001" + Environment.NewLine;

            IStateReader sr = _container.GetInstance <IFactory>().CreateReader(new StringReader(input));
            IState       s  = sr.Read();

            Assert.False(s[0, 0]);
            Assert.True(s[0, 1]);
            Assert.False(s[0, 2]);
            Assert.False(s[0, 3]);
            Assert.False(s[0, 4]);

            Assert.True(s[1, 0]);
            Assert.False(s[1, 1]);
            Assert.False(s[1, 2]);
            Assert.True(s[1, 3]);
            Assert.True(s[1, 4]);

            Assert.True(s[2, 0]);
            Assert.True(s[2, 1]);
            Assert.False(s[2, 2]);
            Assert.False(s[2, 3]);
            Assert.True(s[2, 4]);

            Assert.False(s[3, 0]);
            Assert.True(s[3, 1]);
            Assert.False(s[3, 2]);
            Assert.False(s[3, 3]);
            Assert.False(s[3, 4]);

            Assert.True(s[4, 0]);
            Assert.False(s[4, 1]);
            Assert.False(s[4, 2]);
            Assert.False(s[4, 3]);
            Assert.True(s[4, 4]);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            if (null == args || 1 != args.Length)
            {
                Console.Out.WriteLine("Life expects one parameter, a path to a file containing a regular grid of");
                Console.Out.WriteLine("ones and zeros.  Life is finicky like that.");
                Console.Out.WriteLine();
                Console.Out.WriteLine("Life was brought to you by with the musical assistance of Front 242.");
                return;
            }

            var container = new Container(_ => _.For <IFactory>().Use <Factory>().Singleton());

            IState s;

            try
            {
                using (FileLoader fl = new FileLoader(args[0]))
                {
                    IStateReader sr = container.GetInstance <IFactory>().CreateReader(fl.Open());
                    s = sr.Read();
                }
            }
            catch (FileAccessException fae)
            {
                Console.Out.WriteLine("Life could not access the file located at:");
                Console.Out.WriteLine(args[0]);
                return;
            }

            IStateWriter sw = container.GetInstance <IFactory>().CreateWriter(Console.Out);
            IStateEngine se = container.GetInstance <IFactory>().CreateEngine();

            sw.Write(s);
            Console.Out.WriteLine();

            se.Iterate(s);

            sw.Write(s);
            Console.Out.WriteLine();
        }
Exemple #4
0
        public void State_factory_rejects_empty_string_input()
        {
            IStateReader sr = _container.GetInstance <IFactory>().CreateReader(new StringReader(string.Empty));

            sr.Read();
        }
Exemple #5
0
        public void State_factory_rejects_null_input()
        {
            IStateReader sr = _container.GetInstance <IFactory>().CreateReader(null);

            sr.Read();
        }