Пример #1
0
        public void testToTongyongPinyinStringArray()
        {
            // any input of non-Chinese characters will return null
            {
                Assert.IsNull(PinyinHelper.ToTongyongPinyinStringArray('A'));
                Assert.IsNull(PinyinHelper.ToTongyongPinyinStringArray('z'));
                Assert.IsNull(PinyinHelper.ToTongyongPinyinStringArray(','));
                Assert.IsNull(PinyinHelper.ToTongyongPinyinStringArray('。'));
            }

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

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

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

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

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

                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", "jhuan4" };
                string[] pinyinArray         = PinyinHelper.ToTongyongPinyinStringArray('传');

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

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

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

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

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