Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        public void Ensure_iterate_returns_object()
        {
            // Initial state:
            // 100
            // 110
            IState s0 = _container.GetInstance <IFactory>().CreateState(2, 3);

            s0.Reset(new[, ] {
                { true, false, false }, { true, true, false }
            });

            IState s = _engine.Iterate(s0);

            Assert.NotNull(s);
            Assert.True(ReferenceEquals(s0, s));
        }