Example #1
0
        public void BigMemoryTest()
        {
            var str = "长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长";

            var v1 = PinyinConvert.ToPinyins(str);

            Assert.AreEqual(10000, v1.Length);


            var v2 = PinyinConvert.ToPinyinInitials(str);

            Assert.AreEqual(10000, v1.Length);
            var v3 = PinyinConvert.ToPinyinSearchFomat(str, maxLength: 20000);

            Assert.AreEqual(20000, v3.Length);
        }
Example #2
0
        public void ToPinyinInitialsTest()
        {
            var v = PinyinConvert.ToPinyinInitials("行行好吧");

            Assert.AreEqual(4, v.Length);
            Assert.AreEqual(0, System.Array.IndexOf(v, "HHHB"));
            Assert.AreEqual(1, System.Array.IndexOf(v, "XHHB"));
            Assert.AreEqual(2, System.Array.IndexOf(v, "HXHB"));
            Assert.AreEqual(3, System.Array.IndexOf(v, "XXHB"));


            v = PinyinConvert.ToPinyinInitials("行行好吧", true);
            Assert.AreEqual(4, v.Length);
            Assert.AreEqual(0, System.Array.IndexOf(v, "HHHB".ToLower()));
            Assert.AreEqual(1, System.Array.IndexOf(v, "XHHB".ToLower()));
            Assert.AreEqual(2, System.Array.IndexOf(v, "HXHB".ToLower()));
            Assert.AreEqual(3, System.Array.IndexOf(v, "XXHB".ToLower()));


            try
            {
                v = PinyinConvert.ToPinyinInitials(null);
                Assert.Fail("这里应该抛出异常");
            }
            catch
            {
            }

            try
            {
                v = PinyinConvert.ToPinyinInitials("");
                Assert.Fail("这里应该抛出异常");
            }
            catch
            {
            }
        }
Example #3
0
        public void ToPinyinInitials_WithLower_Letter()
        {
            var r = PinyinConvert.ToPinyinInitials("张s");

            Assert.AreEqual("ZS", r[0]);
        }
Example #4
0
        public void ToPinyinInitials_WithUpper_Letter()
        {
            var r = PinyinConvert.ToPinyinInitials("张S", true);

            Assert.AreEqual("zs", r[0]);
        }