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
6 changes: 3 additions & 3 deletions TestAssessment/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController">
<viewController id="vXZ-lx-hvc" customClass="ViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
Expand Down
186 changes: 121 additions & 65 deletions TestAssessment/TestViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,176 +15,232 @@ @implementation TestViewController


/*
This method should return any positive NSInteger
(hint: cannot be 0)
This method should return any positive NSInteger
(hint: cannot be 0)
*/
- (void)shouldReturnAPositiveNSInteger {

- (NSInteger)shouldReturnAPositiveNSInteger {
return 5;
}

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

- (CGFloat)shouldReturnANegativeCGFloat {
return -2.7;
}

/*
This method should return a falsy boolean
Falsey: Something which evaluates to FALSE.
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
This method should return a single char from a - z
*/
- (void)shouldReturnACharAtoZ {
- (char)shouldReturnACharAtoZ {
return 'm';
}

/*
This method should return the sum of all numbers from
0 - 99 using a loop (. 1 + 2 + 3 + ... + 98 + 99)
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 += 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] ...)
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 sum=0;
for(int i=0;i<count;i++){
sum += arr[i];
}

return sum;
}

/*
Provided a C string (array of chars), return the character
that immediately preceeds the letter q
(ex. "aionkljajvqlkjaml" would return the letter 'v')
(hint: while loop)
Provided a C string (array of chars), return the character
that immediately preceeds the letter q
(ex. "aionkljajvqlkjaml" would return the letter 'v')
(hint: while loop)
*/
- (char)shouldReturnCharBeforeQ:(char *)str {
return '\0';
int i=0;
while(true){
if(str[0]=='q'){
return '\0';
}
if(str[i] != 'q'){
i++;
}
else if(str[i] == 'q'){
break;
}
}
return str[i-1];
}

/*
This method should return the sum of aNumber + bNumber
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
This method should return a YES if aNumber is odd
*/
- (BOOL)isOdd:(NSInteger)aNumber {
if(aNumber % 2 != 0){
return YES;
}
return NO;
}

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

/*
This method should return YES is aNumber is odd and bNumber is even
This method should return YES if aNumber is odd and bNumber is even
*/
- (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber
andThisNumberIsEven:(NSInteger)bNumber {

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

return NO;
}

/*
This method should return the name property of the person
parameter (hint: command + click on class name to jump to the interface.
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 @"";
return [person name];
}

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

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

/*
This method should do the following:
1) Create an instance of Person
2) Set the person's name to "Santa Clause"
3) Set the person's age to 1823
This method should do the following:
1) Create an instance of Person
2) Set the person's name to "Santa Clause"
3) Set the person's age to 1823
*/
- (Person *)createAndReturnPersonWithSomeProperties {
return [[Person alloc] init];
Person *person = [[Person alloc] init];
[person setName:@"Santa Clause"];
[person setAge:1823];

return person;
}

/*
This method provides you an instance of Chair as a parameter
1) Create an instance of Person
2) Tell the person to sit in the chair
(hint: take a look at the methods on the Person class)
This method provides you an instance of Chair as a parameter
1) Create an instance of Person
2) Tell the person to sit in the chair
(hint: take a look at the methods on the Person class)

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

[person 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
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/
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 = @[@"Mike",@"Mark",@"Mary",@"Marty",@"Martin",@"Mekdel"];

return myArray;
}

// BONUS
/*
Update the array item at index 4 to be the name of the person passed
as a parameter
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/
/*
Update the array item at index 4 to be the name of the person passed
as a parameter
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/
*/
- (void)changeValueOfIndexFourInArray:(NSMutableArray *)arr
toPersonsName:(Person *)person {
// [arr[4] setName:person.name];

arr[4] = person.name;
}

// BONUS
/*
Given a string, return the string repeated x times
Example: mike, 5 => mikemikemikemikemike
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableString_Class/
/*
Given a string, return the string repeated x times
Example: mike, 5 => mikemikemikemikemike
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableString_Class/
*/

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

return [@"" stringByPaddingToLength:[str length]*x withString:str startingAtIndex:0];

}

// BONUS
/*
Given an array of numbers, sum each number in the array UNTIL
the sum is greater than 1050. The returned value of this method
should never be greater than 1050.
(ex: [500, 500, 500] returns 1000)
(ex: [200, 500, 100, 400] returns 800)
Given an array of numbers, sum each number in the array UNTIL
the sum is greater than 1050. The returned value of this method
should never be greater than 1050.
(ex: [500, 500, 500] returns 1000)
(ex: [200, 500, 100, 400] returns 800)
*/
- (int)returnSumWhileSumIsLessThan1050:(int *)arr {
return 0;
int sum=0;
int i=0;

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

@end