From afd7e1887053aa05507602055febc48fdd38426e Mon Sep 17 00:00:00 2001 From: shena yoshida Date: Sun, 12 Jul 2015 16:34:13 -0400 Subject: [PATCH] completed test --- TestAssessment/TestViewController.m | 88 ++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 19 deletions(-) diff --git a/TestAssessment/TestViewController.m b/TestAssessment/TestViewController.m index 1f111c4..664c83c 100644 --- a/TestAssessment/TestViewController.m +++ b/TestAssessment/TestViewController.m @@ -19,39 +19,44 @@ @implementation TestViewController This method should return any negative NSInteger (hint: cannot be 0) */ -- (void)shouldReturnANegativeNSInteger { - +- (NSInteger)shouldReturnANegativeNSInteger { + return -1; } /* This method should return any positive CGFloat (hint: cannot be 0) */ -- (void)shouldReturnAPositiveCGFloat { - +- (CGFloat)shouldReturnAPositiveCGFloat { + return 2; } /* This method should return a truthy boolean Truthy: Something which evaluates to TRUE. */ -- (void)shouldReturnAPositiveBool { - +- (BOOL)shouldReturnAPositiveBool { + return YES; } /* This method should return any single char from c - l */ -- (void)shouldReturnACharCtoL { - +- (char)shouldReturnACharCtoL { + 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; + + NSInteger sum = 0; + for (int i = 0; i <= 1000; i++) + sum = sum + i; + + return sum; } /* @@ -59,10 +64,18 @@ Given a c array (int[]) and a count, return the average of the numbers within th (hint: average = sum / number of elements) */ - (NSInteger)shouldReturnAverageOfArrayValues :(int *)arr - withSize:(int)count { - return 0; + withSize:(int)count { + + int sum = 0; + + for (int i = 0; i < count; i++) { + sum += arr[i]; + + } + return sum / count; } + /* Provided a C string (array of chars), return the character that immediately succeed the letter g @@ -70,6 +83,14 @@ Provided a C string (array of chars), return the character (hint: assume there will be a char after g) */ - (char)shouldReturnCharAfterG:(char *)str { + + for (int i = 0; i < strlen(str); i++) { + printf("%c", str[i]); + if (str[i] == 'g') { + return str[i + 1]; + } + } + return '\0'; } @@ -79,14 +100,17 @@ - (char)shouldReturnCharAfterG:(char *)str { */ - (NSInteger)productOfAnInteger:(NSInteger)aNumber andAnotherInteger:(NSInteger)bNumber { - return 0.0; + + return aNumber * bNumber; } - /* This method should return a YES if aNumber is Even */ - (BOOL)isEven:(NSInteger)aNumber { + if (aNumber % 2 == 0) { + return YES; + } return NO; } @@ -94,7 +118,8 @@ - (BOOL)isEven:(NSInteger)aNumber { This method should return YES if aNumber is a multiple of 10 */ - (BOOL)isMultipleOfTen:(NSInteger)aNumber { - return NO; + + return aNumber % 10 == 0; } /* @@ -102,6 +127,9 @@ - (BOOL)isMultipleOfTen:(NSInteger)aNumber { */ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber andThisNumberIsEven:(NSInteger)bNumber { + if (aNumber % 2 != 0 && bNumber % 2 == 0) { + return YES; + } return NO; } @@ -110,21 +138,26 @@ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber (hint: command + click on the class name to see what methods are available) */ - (NSString *)shouldReturnCarModel:(Car *)car { - return @""; + return [car model]; } /* This method should change the model of the car to "Firebird" */ + - (void)changeCarModelToFirebird:(Car *)car { + + [car setModel:@"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]; + return [car fuelLevel]; } /* @@ -134,12 +167,29 @@ - (CGFloat)tellCarToDrive4MilesAndReturnFuelLevel:(Car *)car { 3) Drive the car 6 miles 4) Return the car */ + - (Car *)createAndReturnANewCar { - return [[Car alloc] init]; + + Car *myCar = [[Car alloc] init]; + + [myCar setModel: @"Honda Pilot"]; + [myCar drive: 6]; + + return myCar; + } - (int)returnSumOfAllItemsGreaterThan100:(int *)arr withSize:(int)size { - return 0; + + int sum = 0; + + for (int i = 0; i < size; i ++) { + if (arr[i] > 100 ) { + sum += arr[i]; + } + } + return sum; + } @end