Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
102 changes: 87 additions & 15 deletions TestAssessment/TestViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,59 @@ @implementation TestViewController
This method should return any positive NSInteger
(hint: cannot be 0)
*/
- (void)shouldReturnAPositiveNSInteger {

- (NSInteger)shouldReturnAPositiveNSInteger {
NSInteger i = 10;
return i;
}

/*
This method should return any negative CGFloat
(hint: cannot be 0)
*/
- (void)shouldReturnANegativeCGFloat {

- (CGFloat)shouldReturnANegativeCGFloat {
CGFloat i;
i = -1.001;
return i;
}

/*
This method should return a falsy boolean
Falsey: Something which evaluates to FALSE.
*/
- (void)shouldReturnAFalseyBool {

- (BOOL)shouldReturnAFalseyBool {
return NO;
}

/*
This method should return a single char from a - z
*/
- (void)shouldReturnACharAtoZ {
- (char)shouldReturnACharAtoZ {
return 'a';
}

/*
This method should return the sum of all numbers from
0 - 99 using a loop (. 1 + 2 + 3 + ... + 98 + 99)
*/
- (NSInteger)shouldReturnSumOf0To100 {
return 0;
NSInteger sum=0;
for(int i =0; i<=99; i++){
sum+=i;
}
return sum;
}

/*
Given a c array (int[]) and a count, return the sum of the numbers within the arr
(eg. arr[0] + arr[1] ...)
*/
- (NSInteger)shouldReturnSumOfArrayValues:(int *)arr withSize:(int)count {
return 0;
NSInteger sum=0;
for (int i =0; i<count; i++){
sum+=arr[i];
}
return sum;

}

/*
Expand All @@ -67,28 +80,47 @@ Provided a C string (array of chars), return the character
(hint: while loop)
*/
- (char)shouldReturnCharBeforeQ:(char *)str {
char holder=str[0];
if(holder =='q'){
return '\0';
}

for(int i=1; i<strlen(str); i++){
if(str[i]=='q'){
return holder;
}
holder = str[i];
}

return '\0';
}

/*
This method should return the sum of aNumber + bNumber
*/
- (NSInteger)sumOfAnInteger:(NSInteger)aNumber andAnotherInteger:(NSInteger)bNumber {
return 0;

return aNumber+bNumber;
}


/*
This method should return a YES if aNumber is odd
*/
- (BOOL)isOdd:(NSInteger)aNumber {
if(aNumber%2==1){
return YES;
}
return NO;
}

/*
This method should return YES if aNumber is a multiple of 5
*/
- (BOOL)isMultipleOfFive:(NSInteger)aNumber {
if(aNumber%5==0){
return YES;
}
return NO;
}

Expand All @@ -97,6 +129,10 @@ - (BOOL)isMultipleOfFive:(NSInteger)aNumber {
*/
- (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber
andThisNumberIsEven:(NSInteger)bNumber {

if (aNumber%2==1 && bNumber%2==0){
return YES;
}
return NO;
}

Expand All @@ -105,14 +141,20 @@ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber
parameter (hint: command + click on class name to jump to the interface.
*/
- (NSString *)shouldReturnPersonsName:(Person *)person {
return @"";
if([person name]==nil){
return @"";
}

return [person name];
}

/*
This method should change the person name to "Ada Lovelace"
*/
- (void)changePersonsNameToAdaLovelace:(Person *)person {

[person setName:@"Ada Lovelace"];

}

/*
Expand All @@ -122,7 +164,10 @@ - (void)changePersonsNameToAdaLovelace:(Person *)person {
3) Set the person's age to 1823
*/
- (Person *)createAndReturnPersonWithSomeProperties {
return [[Person alloc] init];
Person *santaPaws = [[Person alloc] init];
[santaPaws setName:@"Santa Clause"];
[santaPaws setAge:1823];
return santaPaws;
}

/*
Expand All @@ -133,6 +178,8 @@ - (Person *)createAndReturnPersonWithSomeProperties {

*/
- (void)makePersonSitInChair:(Chair *)chair {
Person *squaglemire = [[Person alloc] init];
[squaglemire sitInChair:chair];

}

Expand All @@ -141,15 +188,16 @@ - (void)makePersonSitInChair:(Chair *)chair {
Send a message to this Person object telling it to stand up
*/
- (void)makePersonStandUp:(Person *)person {

[person standUp];
}

/*
Create and return an NSArray containing 6 NSString objects
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/
*/
- (NSArray *)createAndReturnNSArray {
return [[NSArray alloc] init];
NSArray *words = [[NSArray alloc] initWithObjects:@"Blue", @"Red", @"Banana", @"Hardyharhar",@"Argh matey", @"toodleloo", nil];
return words;
}

// BONUS
Expand All @@ -160,6 +208,7 @@ - (NSArray *)createAndReturnNSArray {
*/
- (void)changeValueOfIndexFourInArray:(NSMutableArray *)arr
toPersonsName:(Person *)person {
[arr replaceObjectAtIndex:4 withObject:[person name]];

}

Expand All @@ -172,7 +221,18 @@ - (void)changeValueOfIndexFourInArray:(NSMutableArray *)arr

- (NSString *)repeatString:(NSString *)str
numberOfTimes:(NSInteger)x {
return @"";
NSString *c = [NSString stringWithFormat:@"%@",str];
if(x==0){
return @"";
}
if(x==1){
return str;
}

for (int i=2; i<=x; i++){
str = [str stringByAppendingString:c];
}
return str;
}

// BONUS
Expand All @@ -184,6 +244,18 @@ - (NSString *)repeatString:(NSString *)str
(ex: [200, 500, 100, 400] returns 800)
*/
- (int)returnSumWhileSumIsLessThan1050:(int *)arr {
if(arr[0]>1050){
return 0;
}
int sum = arr[0];
int holder = sum;
int i=1;
while(sum<=1050){
holder=sum;
sum+=arr[i];
i++;
}
return holder;
return 0;
}

Expand Down