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.
124 changes: 109 additions & 15 deletions TestAssessment/TestViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,63 @@ @implementation TestViewController
This method should return any negative NSInteger
(hint: cannot be 0)
*/
- (void)shouldReturnANegativeNSInteger {
- (NSInteger)shouldReturnANegativeNSInteger {

NSInteger num = -2;

return num;
}

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

CGFloat num = 5.0;

return num;

}

/*
This method should return a truthy boolean
Truthy: Something which evaluates to TRUE.
*/
- (void)shouldReturnAPositiveBool {
- (BOOL)shouldReturnAPositiveBool {

BOOL bum =YES;

return bum;

}

/*
This method should return any single char from c - l
*/
- (void)shouldReturnACharCtoL {
- (char)shouldReturnACharCtoL {

char c = 'c';

return c;

}

/*
This method should return the product of all numbers from
This method should return the sum of all numbers from
0 - 1000 using a loop (eg. 1 + 2 + 3 + ... + 998 + 999)
*/
- (NSInteger)shouldReturnSumOf0To1000 {
return 0;

int i = 0;
NSInteger sum = 0;

for (i = 0; i <1000; i++) {

sum = sum + i;

}
return sum;
}

/*
Expand All @@ -60,7 +84,17 @@ Given a c array (int[]) and a count, return the average of the numbers within th
*/
- (NSInteger)shouldReturnAverageOfArrayValues :(int *)arr
withSize:(int)count {
return 0;

int i = 0;
NSInteger sum = 0;
NSInteger avg = 0;

for (i = 0; i < count; i++) {

sum = sum + arr[i];
avg = sum / count;
}
return avg;
}

/*
Expand All @@ -70,6 +104,16 @@ Provided a C string (array of chars), return the character
(hint: assume there will be a char after g)
*/
- (char)shouldReturnCharAfterG:(char *)str {

int i = 0;
while (str[i] != 'g') {

i++;
if (str[i] == 'g') {
return str[i +1];
}
}

return '\0';
}

Expand All @@ -79,52 +123,88 @@ - (char)shouldReturnCharAfterG:(char *)str {
*/
- (NSInteger)productOfAnInteger:(NSInteger)aNumber
andAnotherInteger:(NSInteger)bNumber {
return 0.0;

NSInteger result = aNumber * bNumber;

return result;
}


/*
This method should return a YES if aNumber is Even
*/
- (BOOL)isEven:(NSInteger)aNumber {
return NO;

BOOL isEven;

if (aNumber % 2 == 0) {

isEven = YES;
} else {
isEven = NO;
}

return isEven;
}

/*
This method should return YES if aNumber is a multiple of 10
*/
- (BOOL)isMultipleOfTen:(NSInteger)aNumber {
return NO;

BOOL isMultipleOfTen;

if (aNumber % 10 == 0) {
isMultipleOfTen = YES;
} else {
isMultipleOfTen = NO;
}
return isMultipleOfTen;
}

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

BOOL returnYesIfThisNumberIsOdd;

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

/*
This method should return the model of the Car
(hint: command + click on the class name to see what methods are available)
*/
- (NSString *)shouldReturnCarModel:(Car *)car {
return @"";

NSString * model = car.model;
return model;
}

/*
This method should change the model of the car to "Firebird"
*/
- (void)changeCarModelToFirebird:(Car *)car {

car.model = @"Firebird";
}

/*
This method should ask the car to drive 4 miles and then return
the car's current fuel level
*/
- (CGFloat)tellCarToDrive4MilesAndReturnFuelLevel:(Car *)car {
return 0.0;

[car drive:4];
CGFloat num = [car fuelLevel];
return num;
}

/*
Expand All @@ -135,11 +215,25 @@ - (CGFloat)tellCarToDrive4MilesAndReturnFuelLevel:(Car *)car {
4) Return the car
*/
- (Car *)createAndReturnANewCar {
return [[Car alloc] init];

Car *car = [[Car alloc] init];
car.model = @"Honda Pilot";
[car drive:6];

return car;
}

- (int)returnSumOfAllItemsGreaterThan100:(int *)arr withSize:(int)size {
return 0;

int i = 0;
int sum = 0;

for (i = 0; i < size; i++) {
if (arr[i] > 100) {
sum = sum + arr[i];
}
}
return sum;
}

@end