Why not write a custom assert?
Easy way:
public static class BitAsserts
{
public static void IsSet(int actualValue, int bit)
{
Assert.IsTrue((value & (1 << bit)) != 0), "Expected bit {0} of
actual value 0x{1:x8} to be set.", bit, value);
}
}
Alternately you can implement the assertion using the AssertionHelper
pattern of MbUnit v3.0.4.
Jeff.
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Jordan
Sent: Tuesday, October 21, 2008 9:25 AM
To: MbUnit.User
Subject: MbUnit Assert Ideas for bit testing
I am trying to check if a bit is set, or not set, in a 32-bit word. I made
an enumeration to name the bits, Bits.Bit1, Bits.Bit2 etc. Since I have to
test for a lot of these I would like it to be as straight forward and simple
an assertion as possible without requiring all this typecasting.
Right now I have been doing the following which I consider to be rather
blunt.
Assert.AreEqual(0, data & (int)Bits.BIT11, "Bit 11 is set"); and the reverse
Assert.AreEqual((int) Bits.BIT11, data & (int)Bits.BIT11, "Bit 11 is not
set");
One problem with this is that when it fails I get the integer value of the
expected value and the result of the bitwise & on the data when I would
prefer to get expected 0, was 1, expected 1 was 0. I know I could shift the
bits but that complicates the assert when I want to change the bit I am
testing.
Is this something where I should write my own assertion or is there a neat
trick anyone knows of that would help?
Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/MbUnitUser?hl=en
-~----------~----~----~----~------~----~------~--~---