Permalink
Browse files

Test and fix for masked equality descriptors.

  • Loading branch information...
1 parent 9acf5c6 commit 0f07514d493f1237133b65f60dea1fb9079c6b36 Jim Dovey committed Jun 29, 2011
@@ -64,7 +64,7 @@ - (id)initWithRanges: (NSArray *) ranges masks: (NSArray *) masks matchingValues
}
else
{
- NSMutableIndexSet * mutable = [_mask.indexSet mutableCopy];
+ NSMutableIndexSet * mutable = [mask.indexSet mutableCopy];
[mutable shiftIndexesStartingAtIndex: 0 by: rng.location];
[_mask.indexSet addIndexes: mutable];
}
@@ -271,7 +271,7 @@ - (id) initWithRange: (NSRange) range matchingValue: (AQBitfield *) value withMa
@autoreleasepool
{
- self = [self initWithRanges: [NSArray arrayWithObject: rng] masks: [NSArray arrayWithObject: value] matchingValues: [NSArray arrayWithObject: mask]];
+ self = [self initWithRanges: [NSArray arrayWithObject: rng] masks: [NSArray arrayWithObject: mask] matchingValues: [NSArray arrayWithObject: value]];
}
#if !USING_ARC
@@ -124,4 +124,29 @@ - (void) testSimpleEquality
STAssertFalse([desc matchesBitfield: bitfield], @"Expected equality descriptor %@ NOT to match bitfield %@", desc, bitfield);
}
+- (void) testZeroEquality
+{
+ AQBitfield * bitfield = [[AQBitfield alloc] initWith64BitField: 0xFFFF00000000FFFF];
+ AQStateMaskedEqualityMatchingDescriptor * desc = [[AQStateMaskedEqualityMatchingDescriptor alloc] initWith32BitValue: 0 forRange: NSMakeRange(16, 32)];
+
+ STAssertTrue([desc matchesBitfield: bitfield], @"Expected equality descriptor %@ to match bitfield %@", desc, bitfield);
+
+ [bitfield flipBitAtIndex: 32];
+ STAssertFalse([desc matchesBitfield: bitfield], @"Expected equality descriptor %@ NOT to match bitfield %@", desc, bitfield);
+}
+
+- (void) testMaskedEquality
+{
+ AQBitfield * bitfield = [[AQBitfield alloc] initWith64BitField: 0xFFFF00000000FFFF];
+ AQStateMaskedEqualityMatchingDescriptor * desc = [[AQStateMaskedEqualityMatchingDescriptor alloc] initWith32BitValue: 0x000000FF forRange: NSMakeRange(0, 32) matchingMask: 0xFFFF00FF];
+
+ STAssertTrue([desc matchesBitfield: bitfield], @"Expected equality descriptor %@ to match bitfield %@", desc, bitfield);
+
+ [bitfield flipBitAtIndex: 12];
+ STAssertTrue([desc matchesBitfield: bitfield], @"Expected equality descriptor %@ to match bitfield %@", desc, bitfield);
+
+ [bitfield flipBitAtIndex: 24];
+ STAssertFalse([desc matchesBitfield: bitfield], @"Expected equality descriptor %@ NOT to match bitfield %@", desc, bitfield);
+}
+
@end

0 comments on commit 0f07514

Please sign in to comment.