Esempio n. 1
0
        static void Main()
        {
            #region to convert to characters and back
            Console.OutputEncoding = Encoding.Unicode;
            Painting yang = new Painting(
                YinYang.Yang);                            // 阳
            Painting shaoYin = new Painting(
                YinYang.Yang, YinYang.Yin);               // 少阴
            Painting li = new Painting(
                YinYang.Yang, YinYang.Yin, YinYang.Yang); // 离
            Painting qian = new Painting(
                YinYang.Yin, YinYang.Yin, YinYang.Yang,
                YinYang.Yin, YinYang.Yin, YinYang.Yin); // 谦
            Console.Write($"{yang}-{shaoYin}-{li}-{qian} ");
            var  characterConverter = new CharacterConverter();
            char characterOfQian    = characterConverter.ConvertTo(qian);
            Console.Write($"{characterConverter.ConvertTo(yang)}-" +
                          $"{characterConverter.ConvertTo(shaoYin)}-" +
                          $"{characterConverter.ConvertTo(li)}-" +
                          $"{characterOfQian} ");
            _ = characterConverter.TryConvertFrom(characterOfQian, out Painting result);
            Console.WriteLine(result);
            Console.WriteLine();
            // Output: 1-10-101-001000 ⚊-⚍-☲-䷎ 001000
            #endregion

            #region to convert to string
            StringConverter stringConverter = new StringConverter(
                "-----", "-- --", Environment.NewLine);
            Console.WriteLine(stringConverter.ConvertTo(qian));
            Console.WriteLine();

            /*
             * Outputs:
             * -- --
             * -- --
             * -- --
             * -----
             * -- --
             * -- --
             */
            #endregion
        }
        public void ConvertToTest()
        {
            IConverterTo <char> c = new CharacterConverter();
            var yang = c.ConvertTo(new Core.Painting(Core.YinYang.Yang));

            Assert.AreEqual('⚊', yang);
            var yin = c.ConvertTo(new Core.Painting(Core.YinYang.Yin));

            Assert.AreEqual('⚋', yin);
            var yangyang = c.ConvertTo(new Core.Painting(Core.YinYang.Yang, Core.YinYang.Yang));

            Assert.AreEqual('⚌', yangyang);
            var yangyin = c.ConvertTo(new Core.Painting(Core.YinYang.Yang, Core.YinYang.Yin));

            Assert.AreEqual('⚍', yangyin);
            var yinyang = c.ConvertTo(new Core.Painting(Core.YinYang.Yin, Core.YinYang.Yang));

            Assert.AreEqual('⚎', yinyang);
            var yinyin = c.ConvertTo(new Core.Painting(Core.YinYang.Yin, Core.YinYang.Yin));

            Assert.AreEqual('⚏', yinyin);
            var xun = c.ConvertTo(new Core.Painting(
                                      Core.YinYang.Yin, Core.YinYang.Yang, Core.YinYang.Yang));

            Assert.AreEqual('☴', xun);
            var qian = c.ConvertTo(new Core.Painting(
                                       Core.YinYang.Yang, Core.YinYang.Yang, Core.YinYang.Yang));

            Assert.AreEqual('☰', qian);
            var kun = c.ConvertTo(new Core.Painting(
                                      Core.YinYang.Yin, Core.YinYang.Yin, Core.YinYang.Yin));

            Assert.AreEqual('☷', kun);
            var dui = c.ConvertTo(new Core.Painting(
                                      Core.YinYang.Yang, Core.YinYang.Yang, Core.YinYang.Yin));

            Assert.AreEqual('☱', dui);
            var ze = c.ConvertTo(new Core.Painting(
                                     Core.YinYang.Yin, Core.YinYang.Yang, Core.YinYang.Yin));

            Assert.AreEqual('☵', ze);

            var qian6 = c.ConvertTo(new Core.Painting(
                                        Core.YinYang.Yang, Core.YinYang.Yang, Core.YinYang.Yang,
                                        Core.YinYang.Yang, Core.YinYang.Yang, Core.YinYang.Yang));

            Assert.AreEqual('䷀', qian6);
            var weiji = c.ConvertTo(new Core.Painting(
                                        Core.YinYang.Yin, Core.YinYang.Yang, Core.YinYang.Yin,
                                        Core.YinYang.Yang, Core.YinYang.Yin, Core.YinYang.Yang));

            Assert.AreEqual('䷿', weiji);
            var r = c.ConvertTo(new Core.Painting(
                                    Core.YinYang.Yin, Core.YinYang.Yang, Core.YinYang.Yang,
                                    Core.YinYang.Yin, Core.YinYang.Yin, Core.YinYang.Yin));

            Assert.AreEqual('䷭', r);
        }