コード例 #1
0
        public void testToMPS2PinyinStringArray()
        {
            // any input of non-Chinese characters will return null
            {
                Assert.IsNull(PinyinHelper.ToMPS2PinyinStringArray('A'));
                Assert.IsNull(PinyinHelper.ToMPS2PinyinStringArray('z'));
                Assert.IsNull(PinyinHelper.ToMPS2PinyinStringArray(','));
                Assert.IsNull(PinyinHelper.ToMPS2PinyinStringArray('。'));
            }

            // Chinese characters
            // single pronounciation
            {
                string[] expectedPinyinArray = new string[] { "li3" };
                string[] pinyinArray         = PinyinHelper.ToMPS2PinyinStringArray('李');

                Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length);

                for (int i = 0; i < expectedPinyinArray.Length; i++)
                {
                    Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]);
                }
            }
            {
                string[] expectedPinyinArray = new string[] { "chiou2" };
                string[] pinyinArray         = PinyinHelper.ToMPS2PinyinStringArray('球');

                Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length);

                for (int i = 0; i < expectedPinyinArray.Length; i++)
                {
                    Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]);
                }
            }
            {
                string[] expectedPinyinArray = new string[] { "juang1" };
                string[] pinyinArray         = PinyinHelper.ToMPS2PinyinStringArray('桩');

                Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length);

                for (int i = 0; i < expectedPinyinArray.Length; i++)
                {
                    Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]);
                }
            }

            // multiple pronounciations
            {
                string[] expectedPinyinArray = new string[] { "chuan2", "juan4" };
                string[] pinyinArray         = PinyinHelper.ToMPS2PinyinStringArray('传');

                Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length);

                for (int i = 0; i < expectedPinyinArray.Length; i++)
                {
                    Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]);
                }
            }

            {
                string[] expectedPinyinArray = new string[] { "liu4", "lu4" };
                string[] pinyinArray         = PinyinHelper.ToMPS2PinyinStringArray('绿');

                Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length);

                for (int i = 0; i < expectedPinyinArray.Length; i++)
                {
                    Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]);
                }
            }
        }