public void FlagEnumOperations() { // CombineFlags ~ bitwise OR Assert.AreEqual(DaysOfWeek.Monday | DaysOfWeek.Wednesday, DaysOfWeek.Monday.CombineFlags(DaysOfWeek.Wednesday)); Assert.AreEqual(DaysOfWeek.Monday | DaysOfWeek.Wednesday | DaysOfWeek.Friday, FlagEnums.CombineFlags(DaysOfWeek.Monday, DaysOfWeek.Wednesday, DaysOfWeek.Friday)); // HasAnyFlags Assert.IsTrue(DaysOfWeek.Monday.HasAnyFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday)); Assert.IsFalse((DaysOfWeek.Monday | DaysOfWeek.Wednesday).HasAnyFlags(DaysOfWeek.Friday)); // HasAllFlags Assert.IsTrue((DaysOfWeek.Monday | DaysOfWeek.Wednesday | DaysOfWeek.Friday).HasAllFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday)); Assert.IsFalse(DaysOfWeek.Monday.HasAllFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday)); // CommonFlags ~ bitwise AND Assert.AreEqual(DaysOfWeek.Monday, DaysOfWeek.Monday.CommonFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday)); Assert.AreEqual(DaysOfWeek.None, DaysOfWeek.Monday.CommonFlags(DaysOfWeek.Wednesday)); // RemoveFlags Assert.AreEqual(DaysOfWeek.Wednesday, (DaysOfWeek.Monday | DaysOfWeek.Wednesday).RemoveFlags(DaysOfWeek.Monday)); Assert.AreEqual(DaysOfWeek.None, (DaysOfWeek.Monday | DaysOfWeek.Wednesday).RemoveFlags(DaysOfWeek.Monday | DaysOfWeek.Wednesday)); // GetFlags, splits out the individual flags in increasing value order List <DaysOfWeek> flags = DaysOfWeek.Weekend.GetFlags().ToList(); Assert.AreEqual(2, flags.Count); Assert.AreEqual(DaysOfWeek.Sunday, flags[0]); Assert.AreEqual(DaysOfWeek.Saturday, flags[1]); // GetAllFlags Assert.AreEqual(DaysOfWeek.All, FlagEnums.GetAllFlags <DaysOfWeek>()); }
public void GetAllFlags_Test() { Assert.AreEqual(ColorFlagEnum.All, FlagEnums.GetAllFlags <ColorFlagEnum>()); }