Example #1
0
        public void testToWadeGilesPinyinStringArray()
        {
            // any input of non-Chinese characters will return null
            {
                Assert.IsNull(PinyinHelper.toWadeGilesPinyinStringArray('A'));
                Assert.IsNull(PinyinHelper.toWadeGilesPinyinStringArray('z'));
                Assert.IsNull(PinyinHelper.toWadeGilesPinyinStringArray(','));
                Assert.IsNull(PinyinHelper.toWadeGilesPinyinStringArray('。'));
            }

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

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

                for (int i = 0; i < expectedPinyinArray.Length; i++)
                {
                    Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]);
                }
            }
            {
                String[] expectedPinyinArray = new String[] { "ch`iu2" };
                String[] pinyinArray         = PinyinHelper.toWadeGilesPinyinStringArray('球');

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

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

                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[] { "ch`uan2", "chuan4" };
                String[] pinyinArray         = PinyinHelper.toWadeGilesPinyinStringArray('传');

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

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

            {
                String[] expectedPinyinArray = new String[] { "lu:4", "lu4" };
                String[] pinyinArray         = PinyinHelper.toWadeGilesPinyinStringArray('绿');

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

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