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
1 change: 1 addition & 0 deletions TestAssessment/Person.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- (void)setName:(NSString *)name;
- (NSString *)name;


- (void)setAge:(NSInteger)age;
- (NSInteger)age;

Expand Down
107 changes: 84 additions & 23 deletions TestAssessment/TestViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,57 @@ @implementation TestViewController
This method should return any positive NSInteger
(hint: cannot be 0)
*/
- (void)shouldReturnAPositiveNSInteger {
- (NSInteger)shouldReturnAPositiveNSInteger {
return 22;

}

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

- (CGFloat)shouldReturnANegativeCGFloat {
float negativeF = -2.66f;
return negativeF;
}

/*
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;
int sum=0;
for (int i=0; i<100; i++){
sum = 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;
int sumOfArrayValues = 0;
for (int i=0; i<count; i++){
sumOfArrayValues = sumOfArrayValues + arr[i];
}
return sumOfArrayValues;
}

/*
Expand All @@ -66,29 +77,51 @@ Provided a C string (array of chars), return the character
(ex. "aionkljajvqlkjaml" would return the letter 'v')
(hint: while loop)
*/


- (char)shouldReturnCharBeforeQ:(char *)str {
return '\0';

NSInteger length = strlen(str);
char charBeforeQ;
int i = 0;
while (i < length) {
if (str[i] == 'q') {
charBeforeQ = str[i-1];
break;
}
i++;
}

return charBeforeQ;
}

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


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

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

Expand All @@ -97,22 +130,25 @@ - (BOOL)isMultipleOfFive:(NSInteger)aNumber {
*/
- (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber
andThisNumberIsEven:(NSInteger)bNumber {
return NO;
if ((aNumber % 2 == 1) && (bNumber % 2 == 0) )
return YES;
else
return NO;
}

/*
This method should return the name property of the person
parameter (hint: command + click on class name to jump to the interface.
*/
- (NSString *)shouldReturnPersonsName:(Person *)person {
return @"";
}
- (NSString *)shouldReturnPersonsName:(Person *)person {
return [person name];
}

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

return [person setName:@"Ada Lovelace"];
}

/*
Expand All @@ -122,7 +158,11 @@ - (void)changePersonsNameToAdaLovelace:(Person *)person {
3) Set the person's age to 1823
*/
- (Person *)createAndReturnPersonWithSomeProperties {
return [[Person alloc] init];

Person *santa = [[Person alloc] init];
[santa setName:@"Santa Clause"];
[santa setAge:1823];
return santa;
}

/*
Expand All @@ -133,23 +173,25 @@ - (Person *)createAndReturnPersonWithSomeProperties {

*/
- (void)makePersonSitInChair:(Chair *)chair {

Person *newPerson = [[Person alloc] init];
[newPerson sitInChair:chair];
}

/*
This method provides you an instance of Person as a parameter
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 *myArray = @[@"this", @"is", @"access", @"code", @"first", @"assessment"];
return myArray;
}

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

}

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

- (NSString *)repeatString:(NSString *)str
numberOfTimes:(NSInteger)x {
return @"";

NSMutableString *myString = [NSMutableString stringWithString:str];

for (int i = 1; i < x; i++) {
[myString appendString:str];
}
return [NSString stringWithString:myString];
}

// BONUS
Expand All @@ -184,7 +233,19 @@ - (NSString *)repeatString:(NSString *)str
(ex: [200, 500, 100, 400] returns 800)
*/
- (int)returnSumWhileSumIsLessThan1050:(int *)arr {
return 0;

int sum = 0;
int i = 0;
while (sum <= 1050) {

sum = sum + arr[i];

if (sum >= 1050)
break;
else
i++;
}
sum = sum - arr[i];
return sum;
}

@end