コード例 #1
0
        public void Chemical_Parse_works(int qty, string nam, string text)
        {
            var expected = new Chemical(qty, nam);
            var parsed   = Chemical.Parse(text);

            Assert.Equal(expected, parsed);
        }
コード例 #2
0
                public static Reaction Parse(string s)
                {
                    // FOrmat is eg: 5 VJHF, 7 MNCFX, 9 VPVL, 37 CXFTF => 6 GNMV
                    // Except ORE:
                    // 157 ORE => 5 NZVS
                    // 165 ORE => 6 DCFZ
                    var react = s.Split("=>", StringSplitOptions.RemoveEmptyEntries);

                    return(new Reaction
                    {
                        Output = Chemical.Parse(react[1]),
                        Inputs = react[0].Split(',').Select(Chemical.Parse).ToArray()
                    });
                }
コード例 #3
0
        private static List <Reaction> ParseReactions(string data)
        {
            var lines     = data.Split("\r\n");
            var reactions = new List <Reaction>();

            foreach (var line in lines)
            {
                var parts  = line.Split(" => ");
                var inputs = parts[0].Split(", ").Select(Chemical.Parse).ToList();
                var output = Chemical.Parse(parts[1]);
                reactions.Add(new Reaction(inputs, output));
            }

            return(reactions);
        }