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

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

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

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

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

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

                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[] { "chwan2", "jwan4" };
                String[] pinyinArray         = PinyinHelper.toYalePinyinStringArray('传');

                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.toYalePinyinStringArray('绿');

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

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