Ejemplo n.º 1
0
        public void ADL_Mask_CombineMasks_Test()
        {
            BitMask <TestEnum> bm1 = new BitMask <TestEnum>(TestEnum.B | TestEnum.D | TestEnum.F);
            BitMask <TestEnum> bm2 = new BitMask <TestEnum>(TestEnum.B | TestEnum.E | TestEnum.G);
            BitMask            ret = BitMask.CombineMasks(MaskCombineType.BitAnd, bm1, bm2);

            Assert.True(ret == 2);
            ret = BitMask.CombineMasks(MaskCombineType.BitOr, bm1, bm2);
            Assert.True(BitMask.IsContainedInMask(ret, 16, false));
            Assert.True(BitMask.IsContainedInMask(ret, 2, false));
        }
Ejemplo n.º 2
0
        public void ADL_Mask_FlagOperations_Test()
        {
            BitMask bm = new BitMask(true);

            bm.SetAllFlags(2 | 4);
            Assert.Equal(6, (int)bm);

            bm.SetFlag(2 | 4, false);
            bm.SetFlag(16 | 8, true);
            Assert.Equal((int)bm, 16 | 8);


            Assert.True(bm.HasFlag(16, MaskMatchType.MatchOne));
            Assert.False(bm.HasFlag(24 | 4, MaskMatchType.MatchAll));
            bm.SetAllFlags(0);
            bm.Flip();
            Assert.True(-1 == bm);

            Assert.True(BitMask.CombineMasks(MaskCombineType.BitAnd) == 0);
            Assert.True(BitMask.IsUniqueMask(2));
            Assert.False(BitMask.IsUniqueMask(3));
            Assert.False(BitMask.IsUniqueMask(0));
            BitMask <TestEnum> gbm = new BitMask <TestEnum>(TestEnum.A, TestEnum.B);

            Assert.False(BitMask.IsUniqueMask(bm));
            Assert.True(gbm.HasFlag(TestEnum.A, MaskMatchType.MatchOne));

            gbm.SetFlag(TestEnum.C, true);

            //BitMask<TestEnum> gbm1 = TestEnum.C;

            Assert.False(gbm.HasFlag(TestEnum.C, MaskMatchType.MatchOne));

            gbm.SetFlag(TestEnum.C, false);

            Assert.False(gbm.HasFlag(TestEnum.C, MaskMatchType.MatchOne));

            gbm.SetAllFlags(TestEnum.C | TestEnum.A);
            Assert.True(gbm.HasFlag(TestEnum.C | TestEnum.A, MaskMatchType.MatchAll));
        }