Merge branch 'charlesmchen/brokenSignalTests'

This commit is contained in:
Matthew Chen 2018-09-19 13:54:43 -04:00
commit 27023c9d83
6 changed files with 17 additions and 129 deletions

View File

@ -456,7 +456,6 @@
768A1A2B17FC9CD300E00ED8 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 768A1A2A17FC9CD300E00ED8 /* libz.dylib */; };
76C87F19181EFCE600C4ACAB /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 76C87F18181EFCE600C4ACAB /* MediaPlayer.framework */; };
76EB054018170B33006006FC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB03C318170B33006006FC /* AppDelegate.m */; };
76EB063A18170B33006006FC /* FunctionalUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB04EB18170B33006006FC /* FunctionalUtil.m */; };
954AEE6A1DF33E01002E5410 /* ContactsPickerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954AEE681DF33D32002E5410 /* ContactsPickerTest.swift */; };
A10FDF79184FB4BB007FF963 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 76C87F18181EFCE600C4ACAB /* MediaPlayer.framework */; };
A11CD70D17FA230600A2D1B1 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A11CD70C17FA230600A2D1B1 /* QuartzCore.framework */; };
@ -1152,8 +1151,6 @@
76C87F18181EFCE600C4ACAB /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; };
76EB03C218170B33006006FC /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
76EB03C318170B33006006FC /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
76EB04EA18170B33006006FC /* FunctionalUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FunctionalUtil.h; sourceTree = "<group>"; };
76EB04EB18170B33006006FC /* FunctionalUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FunctionalUtil.m; sourceTree = "<group>"; };
8981C8F64D94D3C52EB67A2C /* Pods-SignalTests.test.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalTests.test.xcconfig"; path = "Pods/Target Support Files/Pods-SignalTests/Pods-SignalTests.test.xcconfig"; sourceTree = "<group>"; };
8EEE74B0753448C085B48721 /* Pods-SignalMessaging.app store release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalMessaging.app store release.xcconfig"; path = "Pods/Target Support Files/Pods-SignalMessaging/Pods-SignalMessaging.app store release.xcconfig"; sourceTree = "<group>"; };
948239851C08032C842937CC /* Pods-SignalMessaging.test.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalMessaging.test.xcconfig"; path = "Pods/Target Support Files/Pods-SignalMessaging/Pods-SignalMessaging.test.xcconfig"; sourceTree = "<group>"; };
@ -1200,7 +1197,6 @@
B660F69E1C29868000687D6E /* SignalTests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "SignalTests-Info.plist"; sourceTree = "<group>"; };
B660F69F1C29868000687D6E /* whisperFake.cer */ = {isa = PBXFileReference; lastKnownFileType = file; path = whisperFake.cer; sourceTree = "<group>"; };
B660F6A01C29868000687D6E /* TestUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestUtil.h; sourceTree = "<group>"; };
B660F6AC1C29868000687D6E /* FunctionalUtilTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FunctionalUtilTest.h; sourceTree = "<group>"; };
B660F6AD1C29868000687D6E /* FunctionalUtilTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FunctionalUtilTest.m; sourceTree = "<group>"; };
B660F6B31C29868000687D6E /* UtilTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UtilTest.h; sourceTree = "<group>"; };
B660F6B41C29868000687D6E /* UtilTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UtilTest.m; sourceTree = "<group>"; };
@ -2200,8 +2196,6 @@
children = (
B90418E4183E9DD40038554A /* DateUtil.h */,
B90418E5183E9DD40038554A /* DateUtil.m */,
76EB04EA18170B33006006FC /* FunctionalUtil.h */,
76EB04EB18170B33006006FC /* FunctionalUtil.m */,
34B0796C1FCF46B000E248C2 /* MainAppContext.h */,
34B0796B1FCF46B000E248C2 /* MainAppContext.m */,
34D99C911F2937CC00D284D6 /* OWSAnalytics.swift */,
@ -2371,7 +2365,6 @@
3421981B21061D2E00C57195 /* ByteParserTest.swift */,
3491D9A021022DB7001EF5A1 /* CDSSigningCertificateTest.m */,
45E7A6A61E71CA7E00D44FB5 /* DisplayableTextFilterTest.swift */,
B660F6AC1C29868000687D6E /* FunctionalUtilTest.h */,
B660F6AD1C29868000687D6E /* FunctionalUtilTest.m */,
455AC69D1F4F8B0300134004 /* ImageCacheTest.swift */,
34DB0BEB2011548A007B313F /* OWSDatabaseConverterTest.h */,
@ -3341,7 +3334,6 @@
3496744F2076ACD000080B5F /* LongTextViewController.swift in Sources */,
34FD93701E3BD43A00109093 /* OWSAnyTouchGestureRecognizer.m in Sources */,
34B3F8931E8DF1710035BE1A /* SignalsNavigationController.m in Sources */,
76EB063A18170B33006006FC /* FunctionalUtil.m in Sources */,
34F308A21ECB469700BB7697 /* OWSBezierPathView.m in Sources */,
45B27B862037FFB400A539DF /* DebugUIFileBrowser.swift in Sources */,
34CE88E71F2FB9A10098030F /* ProfileViewController.m in Sources */,

View File

@ -1,25 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
@interface NSArray (FunctionalUtil)
/// Returns true when any of the items in this array match the given predicate.
- (bool)any:(int (^)(id item))predicate;
/// Returns true when all of the items in this array match the given predicate.
- (bool)all:(int (^)(id item))predicate;
/// Returns the first item in this array that matches the given predicate, or else returns nil if none match it.
- (id)firstMatchingElseNil:(int (^)(id item))predicate;
/// Returns an array of all the results of passing items from this array through the given projection function.
- (NSArray *)map:(id (^)(id item))projection;
/// Returns an array of all the results of passing items from this array through the given projection function.
- (NSArray *)filter:(int (^)(id item))predicate;
- (NSDictionary *)keyedBy:(id (^)(id))keySelector;
- (NSDictionary *)groupBy:(id (^)(id value))keySelector;
@end

View File

@ -1,86 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "FunctionalUtil.h"
@implementation NSArray (FunctionalUtil)
- (bool)any:(int (^)(id item))predicate {
OWSAssertDebug(predicate != nil);
for (id e in self) {
if (predicate(e)) {
return true;
}
}
return false;
}
- (bool)all:(int (^)(id item))predicate {
OWSAssertDebug(predicate != nil);
for (id e in self) {
if (!predicate(e)) {
return false;
}
}
return true;
}
- (id)firstMatchingElseNil:(int (^)(id item))predicate {
OWSAssertDebug(predicate != nil);
for (id e in self) {
if (predicate(e)) {
return e;
}
}
return nil;
}
- (NSArray *)map:(id (^)(id item))projection {
OWSAssertDebug(projection != nil);
NSMutableArray *r = [NSMutableArray arrayWithCapacity:self.count];
for (id e in self) {
[r addObject:projection(e)];
}
return r;
}
- (NSArray *)filter:(int (^)(id item))predicate {
OWSAssertDebug(predicate != nil);
NSMutableArray *r = [NSMutableArray array];
for (id e in self) {
if (predicate(e)) {
[r addObject:e];
}
}
return r;
}
- (NSDictionary *)keyedBy:(id (^)(id value))keySelector {
OWSAssertDebug(keySelector != nil);
NSMutableDictionary *result = [NSMutableDictionary dictionary];
for (id value in self) {
result[keySelector(value)] = value;
}
OWSAssertDebug(result.count == self.count);
return result;
}
- (NSDictionary *)groupBy:(id (^)(id value))keySelector {
OWSAssertDebug(keySelector != nil);
NSMutableDictionary *result = [NSMutableDictionary dictionary];
for (id item in self) {
id key = keySelector(item);
NSMutableArray *group = result[key];
if (group == nil) {
group = [NSMutableArray array];
result[key] = group;
}
[group addObject:item];
}
return result;
}
@end

View File

@ -1,9 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "SignalBaseTest.h"
@interface FunctionalUtilTest : SignalBaseTest
@end

View File

@ -2,11 +2,18 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "FunctionalUtilTest.h"
#import "FunctionalUtil.h"
#import "SignalBaseTest.h"
#import "TestUtil.h"
@interface FunctionalUtilTest : SignalBaseTest
@end
#pragma mark -
@implementation FunctionalUtilTest
-(void) testAny {
test(![@[] any:^(id x) { return false; }]);
test(![@[] any:^(id x) { return true; }]);
@ -16,11 +23,13 @@
test([(@[@2, @3, @5]) any:^(NSNumber* x) { return x.intValue == 3; }]);
test(![(@[@2, @4, @5]) any:^(NSNumber* x) { return x.intValue == 3; }]);
}
-(void) testMap {
test([[@[] map:^(id x) { return x; }] isEqualToArray:@[]]);
test([[(@[@1,@2]) map:^(id x) { return x; }] isEqualToArray:(@[@1,@2])]);
test([[(@[@1,@2]) map:^(NSNumber* x) { return @(x.intValue + 1); }] isEqualToArray:(@[@2,@3])]);
}
-(void) testFilter {
test([[@[] filter:^(id x) { return true; }] isEqualToArray:@[]]);
test([[(@[@1,@2]) filter:^(NSNumber* x) { return true; }] isEqualToArray:(@[@1,@2])]);
@ -28,6 +37,7 @@
test([[(@[@1,@2]) filter:^(NSNumber* x) { return x.intValue == 1; }] isEqualToArray:(@[@1])]);
test([[(@[@1,@2]) filter:^(NSNumber* x) { return x.intValue == 2; }] isEqualToArray:(@[@2])]);
}
-(void) testKeyedBy {
test([[@[] keyedBy:^id(id value) { return @true; }] isEqual:@{}]);
test([[@[@1] keyedBy:^id(id value) { return @true; }] isEqual:@{@true : @1}]);
@ -36,6 +46,7 @@
testThrows([(@[@1, @1, @2, @3, @5]) keyedBy:^id(NSNumber* value) { return @(value.intValue/2); }]);
test([[(@[@3, @5, @7, @11, @13]) keyedBy:^id(NSNumber* value) { return @(value.intValue/2); }] isEqual:(@{@1 : @3, @2 : @5, @3 : @7, @5 : @11, @6 : @13})]);
}
-(void) testGroupBy {
test([[@[] groupBy:^id(id value) { return @true; }] isEqual:@{}]);
test([[@[@1] groupBy:^id(id value) { return @true; }] isEqual:@{@true : @[@1]}]);
@ -43,4 +54,5 @@
test([[(@[@1, @2]) groupBy:^id(id value) { return value; }] isEqual:(@{@1 : @[@1], @2 : @[@2]})]);
test([[(@[@1, @1, @2, @3, @5]) groupBy:^id(NSNumber* value) { return @(value.intValue/2); }] isEqual:(@{@0 : @[@1, @1], @1 : @[@2, @3], @2 : @[@5]})]);
}
@end

View File

@ -19,6 +19,8 @@
@implementation OWSOrphanDataCleanerTest
#ifdef BROKEN_TESTS
- (void)setUp
{
[super setUp];
@ -227,4 +229,6 @@
XCTAssertEqual(0, [self numberOfItemsInAttachmentsFolder]);
}
#endif
@end