Esempio n. 1
0
 public override void OnCreate()
 {
     base.OnCreate();
     UnitFloat.Clear();
     UnitString.Clear();
     String.Clear();
 }
        public void SplitUnitStringOnlyTextTest()
        {
            var unitstr  = new UnitString();
            var elements = new List <UnitString.Element>();

            elements = unitstr.Split("a")?.ToList();
            Assert.AreEqual(1, elements.Count());
            Assert.IsFalse(elements.First().IsNumeric);

            elements = unitstr.Split("  abc     ")?.ToList();
            Assert.AreEqual(1, elements.Count());
            Assert.IsFalse(elements.First().IsNumeric);

            elements = unitstr.Split(" a   b  c  ")?.ToList();
            Assert.AreEqual(1, elements.Count());
            Assert.IsFalse(elements.First().IsNumeric);

            elements = unitstr.Split("abc   def")?.ToList();
            Assert.AreEqual(1, elements.Count());
            Assert.IsFalse(elements.First().IsNumeric);

            elements = unitstr.Split("-a.e+x")?.ToList();
            Assert.AreEqual(1, elements.Count());
            Assert.IsFalse(elements.First().IsNumeric);
        }
        public void SplitUnitStringComplexTest()
        {
            var unitstr  = new UnitString();
            var elements = new List <UnitString.Element>();

            elements = unitstr.Split("123 45 6")?.ToList();
            Assert.AreEqual(5, elements.Count());
            Assert.AreEqual(2, elements.Count(p => p.IsNumeric == false));
            Assert.AreEqual(3, elements.Count(p => p.IsNumeric == true));

            elements = unitstr.Split("abcd-4.56")?.ToList();
            Assert.AreEqual(2, elements.Count());
            Assert.AreEqual(1, elements.Count(p => p.IsNumeric == false));
            Assert.AreEqual(1, elements.Count(p => p.IsNumeric == true));

            elements = unitstr.Split("2e+3qwerty")?.ToList();
            Assert.AreEqual(2, elements.Count());
            Assert.AreEqual(1, elements.Count(p => p.IsNumeric == false));
            Assert.AreEqual(1, elements.Count(p => p.IsNumeric == true));

            elements = unitstr.Split(".12345;'+{}(-*-0.5e+1")?.ToList();
            Assert.AreEqual(3, elements.Count());
            Assert.AreEqual(2, elements.Count(p => p.IsNumeric == true));
            Assert.AreEqual(1, elements.Count(p => p.IsNumeric == false));

            elements = unitstr.Split("a33bc5.4 qwerty-7e-2xyz")?.ToList();
            Assert.AreEqual(7, elements.Count());
            Assert.AreEqual(3, elements.Count(p => p.IsNumeric == true));
            Assert.AreEqual(4, elements.Count(p => p.IsNumeric == false));
        }
Esempio n. 4
0
 public void AddUnitString(string key, Func <BaseUnit, string> data)
 {
     if (UnitString.ContainsKey(key))
     {
         return;
     }
     UnitString.Add(key, data);
 }
Esempio n. 5
0
 public string GetUnitString(string key, BaseUnit unit)
 {
     if (unit == null)
     {
         CLog.Error("BaseRefMgr:GetUnitFloat:Unit为Null");
         return(Const.STR_Inv);
     }
     if (!UnitString.ContainsKey(key))
     {
         CLog.Error("BaseRefMgr:GetUnitString:没有RefKey:{0}", key);
         return(Const.STR_Inv);
     }
     return(UnitString[key].Invoke(unit));
 }
        public void SplitUnitStringBasicTests()
        {
            var unitstr = new UnitString();

            var elements = new List <UnitString.Element>();

            elements = unitstr.Split(null)?.ToList();
            Assert.AreEqual(0, elements.Count());

            elements = unitstr.Split("")?.ToList();
            Assert.AreEqual(0, elements.Count());

            elements = unitstr.Split("    ")?.ToList();
            Assert.AreEqual(0, elements.Count());
        }
        public void SplitUnitStringBasicNumbersTest()
        {
            var unitstr  = new UnitString();
            var elements = new List <UnitString.Element>();

            elements = unitstr.Split("123")?.ToList();
            Assert.AreEqual(1, elements.Count());
            Assert.IsTrue(elements.First().IsNumeric);

            elements = unitstr.Split("-4.56")?.ToList();
            Assert.AreEqual(1, elements.Count());
            Assert.IsTrue(elements.First().IsNumeric);

            elements = unitstr.Split("2e+3")?.ToList();
            Assert.AreEqual(1, elements.Count());
            Assert.IsTrue(elements.First().IsNumeric);

            elements = unitstr.Split(".12345")?.ToList();
            Assert.AreEqual(1, elements.Count());

            elements = unitstr.Split("-.5e+2")?.ToList();
            Assert.AreEqual(1, elements.Count());
            Assert.IsTrue(elements.First().IsNumeric);
        }