Пример #1
0
        public void CountTest()
        {
            Assert.AreEqual(3, UniEnum.GetCount <Types>());

            CheckNotGCAlloc(() =>
            {
                UniEnum.GetCount <Types>();
            });
        }
Пример #2
0
        public void UlongEnum_S1_1_GetNameTest()
        {
            Assert.AreEqual("Type1", UniEnum.GetName <UlongEnum_S1_1>(UlongEnum_S1_1.Type1));
            Assert.AreEqual("Type2", UniEnum.GetName <UlongEnum_S1_1>(UlongEnum_S1_1.Type2));
            Assert.AreEqual("Type32", UniEnum.GetName <UlongEnum_S1_1>(UlongEnum_S1_1.Type32));

            var typeNotFound = (UlongEnum_S1_1)Enum.ToObject(typeof(UlongEnum_S1_1), 99999);

            Assert.AreEqual(null, UniEnum.GetName <UlongEnum_S1_1>(typeNotFound));
        }
Пример #3
0
        public void Int2Enum_S1_2_GetNameTest()
        {
            Assert.AreEqual("Type1", UniEnum.GetName <Int2Enum_S1_2>(Int2Enum_S1_2.Type1));
            Assert.AreEqual("Type2", UniEnum.GetName <Int2Enum_S1_2>(Int2Enum_S1_2.Type2));
            Assert.AreEqual("Type32", UniEnum.GetName <Int2Enum_S1_2>(Int2Enum_S1_2.Type32));

            var typeNotFound = (Int2Enum_S1_2)Enum.ToObject(typeof(Int2Enum_S1_2), 99999);

            Assert.AreEqual(null, UniEnum.GetName <Int2Enum_S1_2>(typeNotFound));
        }
Пример #4
0
        public int UniEnum_Values()
        {
            int sum = 0;

            foreach (var v in UniEnum.GetValues <IntEnum1>())
            {
                sum += (int)v;
            }

            return(sum);
        }
Пример #5
0
        public void GetValuesTest()
        {
            var values1 = (Types[])Enum.GetValues(typeof(Types));
            var values2 = UniEnum.GetValues <Types>();

            Assert.AreEqual(values1, values2);

            CheckNotGCAlloc(() =>
            {
                UniEnum.GetValues <Types>();
            });
        }
Пример #6
0
        public void GetNamesTest()
        {
            var names1 = Enum.GetNames(typeof(Types));
            var names2 = UniEnum.GetNames <Types>();

            Assert.AreEqual(names1, names2);

            CheckNotGCAlloc(() =>
            {
                UniEnum.GetNames <Types>();
            });
        }
Пример #7
0
        public void IsDefinedTest()
        {
            Assert.IsTrue(UniEnum.IsDefined <Int2Enum_S1_2>(3));
            Assert.IsTrue(UniEnum.IsDefined <Int2Enum_S1_2>(5));

            Assert.IsFalse(UniEnum.IsDefined <Int2Enum_S1_2>(4));
            Assert.IsFalse(UniEnum.IsDefined <Int2Enum_S1_2>(6));

            CheckNotGCAlloc(() =>
            {
                UniEnum.IsDefined <Int2Enum_S1_2>(6);
                UniEnum.IsDefined <Int2Enum_S1_2>(5);
            });
        }
Пример #8
0
        public void UlongEnum_S1_1_IsDefineTest()
        {
            Assert.AreEqual(true, UniEnum.IsDefined <UlongEnum_S1_1>((ulong)1));
            Assert.AreEqual(true, UniEnum.IsDefined <UlongEnum_S1_1>((ulong)2));
            //Assert.AreEqual(false, UniEnum.IsDefined<UlongEnum_S1_1>((ulong)-1));
            Assert.AreEqual(false, UniEnum.IsDefined <UlongEnum_S1_1>((ulong)33));

            var type1   = (UlongEnum_S1_1)Enum.ToObject(typeof(UlongEnum_S1_1), 1);
            var unknown = (UlongEnum_S1_1)Enum.ToObject(typeof(UlongEnum_S1_1), -1);

            Assert.AreEqual(true, UniEnum.IsDefined(type1));
            Assert.AreEqual(false, UniEnum.IsDefined(unknown));

            Assert.AreEqual(true, UniEnum.IsDefined <UlongEnum_S1_1>(UlongEnum_S1_1.Type1 | UlongEnum_S1_1.Type2));
        }
Пример #9
0
        public void Int2Enum_S1_2_IsDefineTest()
        {
            Assert.AreEqual(true, UniEnum.IsDefined <Int2Enum_S1_2>((int)1));
            Assert.AreEqual(true, UniEnum.IsDefined <Int2Enum_S1_2>((int)3));
            Assert.AreEqual(false, UniEnum.IsDefined <Int2Enum_S1_2>((int)-1));
            Assert.AreEqual(false, UniEnum.IsDefined <Int2Enum_S1_2>((int)65));

            var type1   = (Int2Enum_S1_2)Enum.ToObject(typeof(Int2Enum_S1_2), 1);
            var unknown = (Int2Enum_S1_2)Enum.ToObject(typeof(Int2Enum_S1_2), -1);

            Assert.AreEqual(true, UniEnum.IsDefined(type1));
            Assert.AreEqual(false, UniEnum.IsDefined(unknown));

            Assert.AreEqual(true, UniEnum.IsDefined <Int2Enum_S1_2>(Int2Enum_S1_2.Type1 | Int2Enum_S1_2.Type2));
        }
Пример #10
0
        public void SbyteEnum_S1_1_IsDefineTest()
        {
            Assert.AreEqual(true, UniEnum.IsDefined <SbyteEnum_S1_1>((sbyte)1));
            Assert.AreEqual(true, UniEnum.IsDefined <SbyteEnum_S1_1>((sbyte)2));
            Assert.AreEqual(false, UniEnum.IsDefined <SbyteEnum_S1_1>((sbyte)-1));
            Assert.AreEqual(false, UniEnum.IsDefined <SbyteEnum_S1_1>((sbyte)33));

            var type1   = (SbyteEnum_S1_1)Enum.ToObject(typeof(SbyteEnum_S1_1), 1);
            var unknown = (SbyteEnum_S1_1)Enum.ToObject(typeof(SbyteEnum_S1_1), -1);

            Assert.AreEqual(true, UniEnum.IsDefined(type1));
            Assert.AreEqual(false, UniEnum.IsDefined(unknown));

            Assert.AreEqual(true, UniEnum.IsDefined <SbyteEnum_S1_1>(SbyteEnum_S1_1.Type1 | SbyteEnum_S1_1.Type2));
        }
Пример #11
0
        public void Int2Enum_S1_2_TryParseTest()
        {
            Int2Enum_S1_2 value;
            bool          result;

            result = UniEnum.TryParse("1", out value);
            Assert.AreEqual(true, result);
            Assert.AreEqual(Int2Enum_S1_2.Type1, value);

            result = UniEnum.TryParse("+1", out value);
            Assert.AreEqual(true, result);
            Assert.AreEqual(Int2Enum_S1_2.Type1, value);

            result = UniEnum.TryParse("3", out value);
            Assert.AreEqual(true, result);
            Assert.AreEqual(Int2Enum_S1_2.Type2, value);

            result = UniEnum.TryParse("-1", out value);
            Assert.AreEqual(true, result);


            result = UniEnum.TryParse("type1", out value);
            Assert.AreEqual(false, result);

            result = UniEnum.TryParse("type1", true, out value);
            Assert.AreEqual(true, result);
            Assert.AreEqual(Int2Enum_S1_2.Type1, value);

            result = UniEnum.TryParse("Type1", out value);
            Assert.AreEqual(true, result);
            Assert.AreEqual(Int2Enum_S1_2.Type1, value);

            result = UniEnum.TryParse("Type1", false, out value);
            Assert.AreEqual(true, result);
            Assert.AreEqual(Int2Enum_S1_2.Type1, value);

            result = UniEnum.TryParse("type0", out value);
            Assert.AreEqual(false, result);
        }
Пример #12
0
        public void UlongEnum_S1_1_TryParseTest()
        {
            UlongEnum_S1_1 value;
            bool           result;

            result = UniEnum.TryParse("1", out value);
            Assert.AreEqual(true, result);
            Assert.AreEqual(UlongEnum_S1_1.Type1, value);

            result = UniEnum.TryParse("+1", out value);
            Assert.AreEqual(true, result);
            Assert.AreEqual(UlongEnum_S1_1.Type1, value);

            result = UniEnum.TryParse("2", out value);
            Assert.AreEqual(true, result);
            Assert.AreEqual(UlongEnum_S1_1.Type2, value);

            result = UniEnum.TryParse("-1", out value);
            Assert.AreEqual(false, result);


            result = UniEnum.TryParse("type1", out value);
            Assert.AreEqual(false, result);

            result = UniEnum.TryParse("type1", true, out value);
            Assert.AreEqual(true, result);
            Assert.AreEqual(UlongEnum_S1_1.Type1, value);

            result = UniEnum.TryParse("Type1", out value);
            Assert.AreEqual(true, result);
            Assert.AreEqual(UlongEnum_S1_1.Type1, value);

            result = UniEnum.TryParse("Type1", false, out value);
            Assert.AreEqual(true, result);
            Assert.AreEqual(UlongEnum_S1_1.Type1, value);

            result = UniEnum.TryParse("type0", out value);
            Assert.AreEqual(false, result);
        }
Пример #13
0
 public ReadOnlyArray <IntEnum1> UniEnum_Values()
 {
     return(UniEnum.GetValues <IntEnum1>());
 }
Пример #14
0
 public void Setup()
 {
     UniEnum.TryParse <IntEnum1>("Type1", out _);
     FastEnum.TryParse <IntEnum1>("Type1", out _);
 }
Пример #15
0
 public void Int2Enum_S1_2_MinMaxTest()
 {
     Assert.AreEqual(Int2Enum_S1_2.Type1, UniEnum.GetMinValue <Int2Enum_S1_2>());
     Assert.AreEqual(Int2Enum_S1_2.Type32, UniEnum.GetMaxValue <Int2Enum_S1_2>());
 }
Пример #16
0
 public void UshortEnum_S1_1_MinMaxTest()
 {
     Assert.AreEqual(UshortEnum_S1_1.Type1, UniEnum.GetMinValue <UshortEnum_S1_1>());
     Assert.AreEqual(UshortEnum_S1_1.Type32, UniEnum.GetMaxValue <UshortEnum_S1_1>());
 }
Пример #17
0
 public bool UniEnum_Discontinuous_IsDefined()
 {
     return(UniEnum.IsDefined <IntEnum2>(1000));
 }
Пример #18
0
 public bool UniEnum_TryParse_CaseSensitive_500()
 {
     return(UniEnum.TryParse <IntEnum1>("Type500", out _));
 }
Пример #19
0
 public void Setup()
 {
     UniEnum.IsDefined <IntEnum2>(1000);
     FastEnum.IsDefined <IntEnum2>(1000);
 }
Пример #20
0
 public bool UniEnum_Short_IsDefined()
 {
     return(UniEnum.IsDefined <ShortEnum1>((short)1000));
 }
Пример #21
0
 public void Setup()
 {
     UniEnum.IsDefined <ShortEnum1>(1000);
     FastEnum.IsDefined <ShortEnum1>(1000);
 }
Пример #22
0
 public bool UniEnum_Continuous_IsDefined()
 {
     return(UniEnum.IsDefined <IntEnum1>(1));
 }
Пример #23
0
 public void Setup()
 {
     _ = UniEnum.GetValues <IntEnum1>();
     _ = FastEnum.GetValues <IntEnum1>();
     _ = Enum.GetValues(typeof(IntEnum1));
 }
Пример #24
0
 public bool UniEnum_TryParse_IgnoreCase_500()
 {
     return(UniEnum.TryParse <IntEnum1>("Type500", true, out _));
 }
Пример #25
0
 public void ByteEnum_S1_1_MinMaxTest()
 {
     Assert.AreEqual(ByteEnum_S1_1.Type1, UniEnum.GetMinValue <ByteEnum_S1_1>());
     Assert.AreEqual(ByteEnum_S1_1.Type32, UniEnum.GetMaxValue <ByteEnum_S1_1>());
 }