Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added tests for NSDictionary+Helpers and UIColor+CustomColors categories

  • Loading branch information...
commit 363c9c77cd6322f5687380015a64b82a7d411c79 1 parent 444e949
@royclarkson royclarkson authored
View
18 Greenhouse.xcodeproj/project.pbxproj
@@ -11,6 +11,8 @@
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
2892E4100DC94CBA00A64D0F /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2892E40F0DC94CBA00A64D0F /* CoreGraphics.framework */; };
811BA5D0120C58E40045BB34 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 811BA5CF120C58E40045BB34 /* CoreLocation.framework */; };
+ 818C666115D95A1700594B97 /* NSDictionary_HelpersTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 818C666015D95A1700594B97 /* NSDictionary_HelpersTests.m */; };
+ 818C666215D95C6600594B97 /* NSDictionary+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 81E42DE015ADE82F001FA72D /* NSDictionary+Helpers.m */; };
819E443C11FF1FA600DBC0BB /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 819E443B11FF1FA600DBC0BB /* MapKit.framework */; };
81A1BD1915D5AF9D0028A2D3 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81A1BD1815D5AF9D0028A2D3 /* SenTestingKit.framework */; };
81A1BD1A15D5AF9D0028A2D3 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
@@ -22,6 +24,8 @@
81A1BD3815D5B44E0028A2D3 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
81A1BD3E15D5B44E0028A2D3 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 81A1BD3C15D5B44E0028A2D3 /* InfoPlist.strings */; };
81A1BD4115D5B44E0028A2D3 /* GreenhouseApplicationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 81A1BD4015D5B44E0028A2D3 /* GreenhouseApplicationTests.m */; };
+ 81A1BD4F15D5BA760028A2D3 /* UIColor+CustomColors.m in Sources */ = {isa = PBXBuildFile; fileRef = 81E42E0D15ADE82F001FA72D /* UIColor+CustomColors.m */; };
+ 81A1BD5215D5BAE30028A2D3 /* UIColor_CustomColorsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 81A1BD5115D5BAE30028A2D3 /* UIColor_CustomColorsTests.m */; };
81E42E1B15ADE82F001FA72D /* GHActivityAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = 81E42D5F15ADE82F001FA72D /* GHActivityAlertView.m */; };
81E42E1C15ADE82F001FA72D /* GHActivityIndicatorTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 81E42D6115ADE82F001FA72D /* GHActivityIndicatorTableViewCell.m */; };
81E42E1D15ADE82F001FA72D /* GHAppSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = 81E42D6315ADE82F001FA72D /* GHAppSettings.m */; };
@@ -162,6 +166,8 @@
2892E40F0DC94CBA00A64D0F /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
811BA5CF120C58E40045BB34 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
811F8CF015D1B4AB00208CA7 /* GHOAuthResponseDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHOAuthResponseDelegate.h; sourceTree = "<group>"; };
+ 818C665F15D95A1700594B97 /* NSDictionary_HelpersTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSDictionary_HelpersTests.h; sourceTree = "<group>"; };
+ 818C666015D95A1700594B97 /* NSDictionary_HelpersTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSDictionary_HelpersTests.m; sourceTree = "<group>"; };
819E443B11FF1FA600DBC0BB /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
81A1BD1715D5AF9D0028A2D3 /* GreenhouseLogicTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GreenhouseLogicTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
81A1BD1815D5AF9D0028A2D3 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
@@ -176,6 +182,8 @@
81A1BD3F15D5B44E0028A2D3 /* GreenhouseApplicationTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GreenhouseApplicationTests.h; sourceTree = "<group>"; };
81A1BD4015D5B44E0028A2D3 /* GreenhouseApplicationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GreenhouseApplicationTests.m; sourceTree = "<group>"; };
81A1BD4215D5B44E0028A2D3 /* GreenhouseApplicationTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "GreenhouseApplicationTests-Prefix.pch"; sourceTree = "<group>"; };
+ 81A1BD5015D5BAE30028A2D3 /* UIColor_CustomColorsTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIColor_CustomColorsTests.h; sourceTree = "<group>"; };
+ 81A1BD5115D5BAE30028A2D3 /* UIColor_CustomColorsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIColor_CustomColorsTests.m; sourceTree = "<group>"; };
81E42D5E15ADE82F001FA72D /* GHActivityAlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHActivityAlertView.h; sourceTree = "<group>"; };
81E42D5F15ADE82F001FA72D /* GHActivityAlertView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHActivityAlertView.m; sourceTree = "<group>"; };
81E42D6015ADE82F001FA72D /* GHActivityIndicatorTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHActivityIndicatorTableViewCell.h; sourceTree = "<group>"; };
@@ -464,7 +472,11 @@
children = (
81A1BD2215D5AF9D0028A2D3 /* GreenhouseLogicTests.h */,
81A1BD2315D5AF9D0028A2D3 /* GreenhouseLogicTests.m */,
+ 818C665F15D95A1700594B97 /* NSDictionary_HelpersTests.h */,
+ 818C666015D95A1700594B97 /* NSDictionary_HelpersTests.m */,
81A1BD1D15D5AF9D0028A2D3 /* Supporting Files */,
+ 81A1BD5015D5BAE30028A2D3 /* UIColor_CustomColorsTests.h */,
+ 81A1BD5115D5BAE30028A2D3 /* UIColor_CustomColorsTests.m */,
);
path = GreenhouseLogicTests;
sourceTree = "<group>";
@@ -1068,6 +1080,10 @@
buildActionMask = 2147483647;
files = (
81A1BD2415D5AF9D0028A2D3 /* GreenhouseLogicTests.m in Sources */,
+ 81A1BD4F15D5BA760028A2D3 /* UIColor+CustomColors.m in Sources */,
+ 81A1BD5215D5BAE30028A2D3 /* UIColor_CustomColorsTests.m in Sources */,
+ 818C666115D95A1700594B97 /* NSDictionary_HelpersTests.m in Sources */,
+ 818C666215D95C6600594B97 /* NSDictionary+Helpers.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2255,6 +2271,7 @@
81A1BD2F15D5AF9D0028A2D3 /* App Store Distribution */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = "Release [localhost]";
};
81A1BD4315D5B44E0028A2D3 /* Build configuration list for PBXNativeTarget "GreenhouseApplicationTests" */ = {
isa = XCConfigurationList;
@@ -2270,6 +2287,7 @@
81A1BD4C15D5B44E0028A2D3 /* App Store Distribution */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = "Release [localhost]";
};
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Greenhouse" */ = {
isa = XCConfigurationList;
View
52 Greenhouse/NSDictionary+Helpers.m
@@ -27,17 +27,13 @@ @implementation NSDictionary (NSDictionary_Helpers)
- (NSString *)stringForKey:(id)aKey
{
- NSString *s;
+ NSString *s = nil;
@try
{
NSObject *o = [self objectForKey:aKey];
- if (o == nil || o == [NSNull null])
- {
- s = nil;
- }
- else
+ if (o != nil && o != [NSNull null])
{
if ([o isKindOfClass:[NSString class]])
{
@@ -52,7 +48,6 @@ - (NSString *)stringForKey:(id)aKey
@catch (NSException *e)
{
DLog(@"Caught %@%@", [e name], [e reason]);
- s = nil;
}
@finally
{
@@ -62,17 +57,13 @@ - (NSString *)stringForKey:(id)aKey
- (NSString *)stringByReplacingPercentEscapesForKey:(id)aKey usingEncoding:(NSStringEncoding)encoding
{
- NSString *s;
+ NSString *s = nil;
@try
{
NSObject *o = [self objectForKey:aKey];
- if (o == nil || o == [NSNull null])
- {
- s = nil;
- }
- else
+ if (o != nil && o != [NSNull null])
{
s = [[NSString stringWithString:(NSString *)o] stringByReplacingPercentEscapesUsingEncoding:encoding];
}
@@ -80,7 +71,6 @@ - (NSString *)stringByReplacingPercentEscapesForKey:(id)aKey usingEncoding:(NSSt
@catch (NSException *e)
{
DLog(@"Caught %@%@", [e name], [e reason]);
- s = nil;
}
@finally
{
@@ -90,17 +80,13 @@ - (NSString *)stringByReplacingPercentEscapesForKey:(id)aKey usingEncoding:(NSSt
- (NSInteger)integerForKey:(id)aKey
{
- NSInteger i;
+ NSInteger i = 0;
@try
{
NSObject *o = [self objectForKey:aKey];
- if (o == nil || o == [NSNull null])
- {
- i = 0;
- }
- else
+ if (o != nil && o != [NSNull null])
{
i = [(NSNumber *)o integerValue];
}
@@ -108,7 +94,6 @@ - (NSInteger)integerForKey:(id)aKey
@catch (NSException *e)
{
DLog(@"Caught %@%@", [e name], [e reason]);
- i = 0;
}
@finally
{
@@ -118,17 +103,13 @@ - (NSInteger)integerForKey:(id)aKey
- (double)doubleForKey:(id)aKey
{
- double d;
+ double d = 0.0f;
@try
{
NSObject *o = [self objectForKey:aKey];
- if (o == nil || o == [NSNull null])
- {
- d = 0.0f;
- }
- else
+ if (o != nil && o != [NSNull null])
{
d = [(NSNumber *)o doubleValue];
}
@@ -136,7 +117,6 @@ - (double)doubleForKey:(id)aKey
@catch (NSException *e)
{
DLog(@"Caught %@%@", [e name], [e reason]);
- d = 0.0f;
}
@finally
{
@@ -144,19 +124,16 @@ - (double)doubleForKey:(id)aKey
}
}
+// any nonzero value will be interpreted as YES or true
- (BOOL)boolForKey:(id)aKey
{
- BOOL b;
+ BOOL b = NO;
@try
{
NSObject *o = [self objectForKey:aKey];
- if (o == nil || o == [NSNull null])
- {
- b = NO;
- }
- else
+ if (o != nil && o != [NSNull null])
{
b = [(NSNumber *)o boolValue];
}
@@ -164,7 +141,6 @@ - (BOOL)boolForKey:(id)aKey
@catch (NSException * e)
{
DLog(@"Caught %@%@", [e name], [e reason]);
- b = NO;
}
@finally
{
@@ -174,7 +150,7 @@ - (BOOL)boolForKey:(id)aKey
- (NSDate *)dateWithMillisecondsSince1970ForKey:(id)aKey
{
- NSDate *date;
+ NSDate *date = nil;
@try
{
@@ -185,7 +161,6 @@ - (NSDate *)dateWithMillisecondsSince1970ForKey:(id)aKey
@catch (NSException *e)
{
DLog(@"Caught %@%@", [e name], [e reason]);
- date = nil;
}
@finally
{
@@ -195,7 +170,7 @@ - (NSDate *)dateWithMillisecondsSince1970ForKey:(id)aKey
- (NSURL *)urlForKey:(id)aKey
{
- NSURL *url;
+ NSURL *url = nil;
@try
{
@@ -204,7 +179,6 @@ - (NSURL *)urlForKey:(id)aKey
@catch (NSException * e)
{
DLog(@"Caught %@%@", [e name], [e reason]);
- url = nil;
}
@finally
{
View
3  GreenhouseLogicTests/GreenhouseLogicTests-Prefix.pch
@@ -5,4 +5,7 @@
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
+
+ //Debug Logging
+ #import "DLog.h"
#endif
View
2  GreenhouseLogicTests/GreenhouseLogicTests.m
@@ -26,7 +26,7 @@ - (void)tearDown
- (void)testExample
{
- STFail(@"Unit tests are not implemented yet in GreenhouseLogicTests");
+// STFail(@"Unit tests are not implemented yet in GreenhouseLogicTests");
}
@end
View
28 GreenhouseLogicTests/NSDictionary_HelpersTests.h
@@ -0,0 +1,28 @@
+//
+// Copyright 2012 the original author or authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//
+// NSDictionary_HelpersTests.h
+// Greenhouse
+//
+// Created by Roy Clarkson on 8/13/12.
+//
+
+#import <SenTestingKit/SenTestingKit.h>
+#import "NSDictionary+Helpers.h"
+
+@interface NSDictionary_HelpersTests : SenTestCase
+
+@end
View
297 GreenhouseLogicTests/NSDictionary_HelpersTests.m
@@ -0,0 +1,297 @@
+//
+// Copyright 2012 the original author or authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//
+// NSDictionary_HelpersTests.m
+// Greenhouse
+//
+// Created by Roy Clarkson on 8/13/12.
+//
+
+#import "NSDictionary_HelpersTests.h"
+
+#define KEY_STRING @"string"
+#define KEY_INTEGER @"integer"
+#define KEY_INTEGER_AS_STRING @"integerAsString"
+#define KEY_FLOAT @"float"
+#define KEY_BOOL_YES_AS_STRING @"boolYesAsString"
+#define KEY_BOOL_YES_AS_NUMBER @"boolYesAsNumber"
+#define KEY_BOOL_NO_AS_STRING @"boolNoAsString"
+#define KEY_BOOL_NO_AS_NUMBER @"boolNoAsNumber"
+#define KEY_NULL @"null"
+#define KEY_NOT_FOUND @"notFound"
+
+@interface NSDictionary_HelpersTests()
+
+@property (nonatomic, strong) NSDictionary *testData;
+
+@end
+
+@implementation NSDictionary_HelpersTests
+
+@synthesize testData;
+
+- (void)setUp
+{
+ [super setUp];
+
+ self.testData = [[NSDictionary alloc] initWithObjectsAndKeys:
+ @"testing123", KEY_STRING,
+ [NSNumber numberWithInt:1001], KEY_INTEGER,
+ @"1299", KEY_INTEGER_AS_STRING,
+ [NSNumber numberWithFloat:1.123f] , KEY_FLOAT,
+ @"YES", KEY_BOOL_YES_AS_STRING,
+ [NSNumber numberWithBool:YES], KEY_BOOL_YES_AS_NUMBER,
+ @"NO", KEY_BOOL_NO_AS_STRING,
+ [NSNumber numberWithBool:NO], KEY_BOOL_NO_AS_NUMBER,
+ [NSNull null], @"null",
+ nil];
+}
+
+- (void)tearDown
+{
+ self.testData = nil;
+
+ [super tearDown];
+}
+
+#pragma mark -
+#pragma mark stringForKey tests
+
+- (void)testStringForKey
+{
+ NSString *expected = @"testing123";
+ NSString *actual = [testData stringForKey:KEY_STRING];
+ STAssertEqualObjects(expected, actual, @"strings are not equal");
+}
+
+- (void)testStringForKeyInteger
+{
+ NSString *expected = @"1001";
+ NSString *actual = [testData stringForKey:KEY_INTEGER];
+ STAssertEqualObjects(expected, actual, @"strings are not equal");
+}
+
+- (void)testStringForKeyFloat
+{
+ NSString *expected = @"1.123";
+ NSString *actual = [testData stringForKey:KEY_FLOAT];
+ STAssertEqualObjects(expected, actual, @"strings are not equal");
+}
+
+- (void)testStringForKeyNil
+{
+ NSString *actual = [testData stringForKey:KEY_NULL];
+ STAssertNil(actual, @"should be nil");
+}
+
+- (void)testStringForKeyNotFound
+{
+ NSString *s = [testData stringForKey:KEY_NOT_FOUND];
+ STAssertNil(s, @"should be nil");
+}
+
+
+#pragma mark -
+#pragma mark stringByReplacingPercentEscapesForKey tests
+
+// TODO: ADD TESTS
+
+
+#pragma mark -
+#pragma mark integerForKey tests
+
+- (void)testIntegerForKey
+{
+ NSInteger expected = 1001;
+ NSInteger actual = [testData integerForKey:KEY_INTEGER];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+// can't convert an alpha-numeric string to an integer
+- (void)testIntegerForKeyString
+{
+ NSInteger expected = 0;
+ NSInteger actual = [testData integerForKey:KEY_STRING];
+ STAssertEquals(expected, actual, @"should be 0");
+}
+
+// if an integer is stored as a string, then it is converted
+- (void)testIntegerForKeyIntegerAsString
+{
+ NSInteger expected = 1299;
+ NSInteger actual = [testData integerForKey:KEY_INTEGER_AS_STRING];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+// floats are reduced to integers, truncating the decimal value
+- (void)testIntegerForKeyFloat
+{
+ NSInteger expected = 1;
+ NSInteger actual = [testData integerForKey:KEY_FLOAT];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+// if the value for a key is nil, then zero is returned
+- (void)testIntegerForKeyNil
+{
+ NSInteger expected = 0;
+ NSInteger actual = [testData integerForKey:KEY_NULL];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+- (void)testIntegerForKeyNotFound
+{
+ NSInteger expected = 0;
+ NSInteger actual = [testData integerForKey:KEY_NOT_FOUND];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+
+#pragma mark -
+#pragma mark doubleForKey tests
+
+- (void)testDoubleForKey
+{
+ double expected = 1.123f;
+ double actual = [testData doubleForKey:KEY_FLOAT];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+- (void)testDoubleForKeyString
+{
+ double expected = 0.0f;
+ double actual = [testData doubleForKey:KEY_STRING];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+- (void)testDoubleForKeyInteger
+{
+ double expected = 1001;
+ double actual = [testData doubleForKey:KEY_INTEGER];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+- (void)testDoubleForKeyNil
+{
+ double expected = 0.0f;
+ double actual = [testData doubleForKey:KEY_NULL];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+- (void)testDoubleForKeyNotFound
+{
+ double expected = 0.0f;
+ double actual = [testData doubleForKey:KEY_NOT_FOUND];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+
+#pragma mark -
+#pragma mark boolForKey tests
+
+- (void)testBoolForKeyYesAsString
+{
+ BOOL expected = YES;
+ BOOL actual = [testData boolForKey:KEY_BOOL_YES_AS_STRING];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+- (void)testBoolForKeyNoAsString
+{
+ BOOL expected = NO;
+ BOOL actual = [testData boolForKey:KEY_BOOL_NO_AS_STRING];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+- (void)testBoolForKeyYesAsNumber
+{
+ BOOL expected = YES;
+ BOOL actual = [testData boolForKey:KEY_BOOL_YES_AS_NUMBER];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+- (void)testBoolForKeyNoAsNumber
+{
+ BOOL expected = NO;
+ BOOL actual = [testData boolForKey:KEY_BOOL_NO_AS_NUMBER];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+// non zero values are interpretted as true
+- (void)testBoolForKeyString
+{
+ BOOL expected = YES;
+ BOOL actual = [testData boolForKey:KEY_STRING];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+// non zero values are interpretted as true
+- (void)testBoolForKeyInteger
+{
+ BOOL expected = YES;
+ BOOL actual = [testData boolForKey:KEY_INTEGER];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+// non zero values are interpretted as true
+- (void)testBoolForKeyIntegerAsString
+{
+ BOOL expected = YES;
+ BOOL actual = [testData boolForKey:KEY_INTEGER_AS_STRING];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+// non zero values are interpretted as true
+- (void)testBoolForKeyDouble
+{
+ BOOL expected = YES;
+ BOOL actual = [testData boolForKey:KEY_FLOAT];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+- (void)testBoolForKeyNil
+{
+ BOOL expected = NO;
+ BOOL actual = [testData boolForKey:KEY_NULL];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+- (void)testBoolForKeyNotFound
+{
+ BOOL expected = NO;
+ BOOL actual = [testData boolForKey:KEY_NOT_FOUND];
+ STAssertEquals(expected, actual, @"values are not equal");
+}
+
+
+#pragma mark -
+#pragma mark dateWithMillisecondsSince1970ForKey tests
+
+// TODO: ADD TESTS
+
+
+#pragma mark -
+#pragma mark urlForKey tests
+
+// TODO: ADD TESTS
+
+
+
+
+
+
+
+@end
View
28 GreenhouseLogicTests/UIColor_CustomColorsTests.h
@@ -0,0 +1,28 @@
+//
+// Copyright 2012 the original author or authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//
+// UIColor_CustomColorsTests.h
+// Greenhouse
+//
+// Created by Roy Clarkson on 8/10/12.
+//
+
+#import <SenTestingKit/SenTestingKit.h>
+#import "UIColor+CustomColors.h"
+
+@interface UIColor_CustomColorsTests : SenTestCase
+
+@end
View
77 GreenhouseLogicTests/UIColor_CustomColorsTests.m
@@ -0,0 +1,77 @@
+//
+// Copyright 2012 the original author or authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//
+// UIColor_CustomColorsTests.m
+// Greenhouse
+//
+// Created by Roy Clarkson on 8/10/12.
+//
+
+#import "UIColor_CustomColorsTests.h"
+
+@interface UIColor_CustomColorsTests()
+
+- (UIColor *)colorFromHexString:(NSString *)hexString;
+
+@end
+
+@implementation UIColor_CustomColorsTests
+
+- (void)testSpringDarkGreenColor
+{
+ UIColor *expected = [self colorFromHexString:@"#387C2C"];
+ UIColor *actual = [UIColor springDarkGreenColor];
+ STAssertEqualObjects(expected, actual, @"colors are not equal");
+}
+
+- (void)testSpringLightGreenColor
+{
+ UIColor *expected = [self colorFromHexString:@"#6DB33F"];
+ UIColor *actual = [UIColor springLightGreenColor];
+ STAssertEqualObjects(expected, actual, @"colors are not equal");
+}
+
+
+#pragma mark -
+#pragma mark Helpers
+
+// As answered by Dave DeLong in the following StackOverflow question
+// http://stackoverflow.com/questions/3805177/how-to-convert-hex-rgb-color-codes-to-uicolor
+- (UIColor *)colorFromHexString:(NSString *)hexString
+{
+ NSString *cleanString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""];
+ if([cleanString length] == 3) {
+ cleanString = [NSString stringWithFormat:@"%@%@%@%@%@%@",
+ [cleanString substringWithRange:NSMakeRange(0, 1)],[cleanString substringWithRange:NSMakeRange(0, 1)],
+ [cleanString substringWithRange:NSMakeRange(1, 1)],[cleanString substringWithRange:NSMakeRange(1, 1)],
+ [cleanString substringWithRange:NSMakeRange(2, 1)],[cleanString substringWithRange:NSMakeRange(2, 1)]];
+ }
+ if([cleanString length] == 6) {
+ cleanString = [cleanString stringByAppendingString:@"ff"];
+ }
+
+ unsigned int baseValue;
+ [[NSScanner scannerWithString:cleanString] scanHexInt:&baseValue];
+
+ float red = ((baseValue >> 24) & 0xFF)/255.0f;
+ float green = ((baseValue >> 16) & 0xFF)/255.0f;
+ float blue = ((baseValue >> 8) & 0xFF)/255.0f;
+ float alpha = ((baseValue >> 0) & 0xFF)/255.0f;
+
+ return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
+}
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.