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
3 changes: 3 additions & 0 deletions ConverterApp/ConverterViewController/ConverterModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import <Foundation/Foundation.h>
#import "MathBase.h"

extern NSString *const kConverterModelDidUpdateNotification;

Expand All @@ -26,4 +27,6 @@ extern NSString *const kConverterModelDidUpdateNotification;

- (void)convertValue;

- (id<MathProtocol>)currentMathModel;

@end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="5056" systemVersion="13D65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6154.17" systemVersion="13D65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6153.11"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ConverterViewController">
Expand All @@ -19,7 +19,6 @@
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Value" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="X3T-Qk-3g7">
<rect key="frame" x="20" y="10" width="56" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" keyboardType="decimalPad"/>
<connections>
Expand All @@ -28,7 +27,6 @@
</textField>
<pickerView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="wr3-KX-eYl">
<rect key="frame" x="0.0" y="50" width="320" height="162"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<constraints>
<constraint firstAttribute="height" constant="162" id="mcD-Ih-6Gw"/>
</constraints>
Expand All @@ -39,7 +37,6 @@
</pickerView>
<button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="300" horizontalCompressionResistancePriority="800" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="l19-ss-2a4">
<rect key="frame" x="86" y="10" width="55" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Convert">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
Expand Down
2 changes: 1 addition & 1 deletion ConverterApp/Math/MathCelsiusToK.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

#import "MathBase.h"

@interface MathCelsiusToK : MathBase
@interface MathCelsiusToK : MathBase<MathProtocol>

@end
2 changes: 2 additions & 0 deletions ConverterApp/Math/MathCelsiusToK.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

#import "MathCelsiusToK.h"

//TODO: Need to review this constant, seems should be 273.15
static float const kCelsiusAdd = 274.15;


@implementation MathCelsiusToK

- (NSNumber *)convertNumber:(NSNumber *)number
Expand Down
2 changes: 1 addition & 1 deletion ConverterApp/Math/MathInchesToCm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

#import "MathBase.h"

@interface MathInchesToCm : MathBase
@interface MathInchesToCm : MathBase<MathProtocol>

@end
74 changes: 67 additions & 7 deletions ConverterAppTests/ConverterViewController/ConverterModelTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

#import <XCTest/XCTest.h>
#import "ConverterModel_Internal.h"

#import "MathBase.h"
#import "MathLitersToGal.h"
#import "OCMock.h"
@interface ConverterModelTests : XCTestCase
{
ConverterModel* sut;
Expand All @@ -35,19 +37,26 @@ - (void)tearDown
- (void)testModelHasMathListAfterInit
{
// Arrange

BOOL ModelHasMathListAfterInit = [sut mathModelList] != nil && [[sut mathModelList] count] != 0;
// Act

// Assert
XCTAssert(ModelHasMathListAfterInit);
}

- (void)testListOfDefaultModelsReturnsAnArrayWithMathObjects
{
// Arrange

NSArray *list = [sut mathModelList];
int MathObjectsCount = 0;
// Act

for(id object in list){
if([object isKindOfClass:[MathBase class]]){
++MathObjectsCount;
}
}
// Assert
XCTAssertEqual(MathObjectsCount, [list count]);
}

- (void)testCurrentMathModelReturnsCorrectResult
Expand All @@ -56,70 +65,121 @@ - (void)testCurrentMathModelReturnsCorrectResult

// Act

//Select second(LitersToGal) math model
sut.selectedMathModel = 1;

//Get selected math model
id<MathProtocol> CurrentMathModel = [sut currentMathModel];

// Assert
XCTAssert([CurrentMathModel isKindOfClass:[MathLitersToGal class]]);
}

- (void)testConvertedValueWithMathModelReturnsCorrectResult
{
// Arrange
const float accuracy = .1f;
//Select second(LitersToGal) math model
sut.selectedMathModel = 1;

// Act
NSNumber *convertedValue = [[sut currentMathModel] convertNumber:[NSNumber numberWithFloat:.3f]];

// Assert
XCTAssertEqualWithAccuracy(convertedValue.floatValue, .08f, accuracy);
}

- (void)testConvertValueUpdatesSelfWithCorrectText
{
// Arrange

//Select second(LitersToGal) math model
sut.selectedMathModel = 1;
[sut updateWithText:@"4.3"];

// Act
[sut convertValue];
NSString *convertedString = [sut text];

// Assert
XCTAssert([convertedString isEqualToString:@"1.13594" ]);

}

- (void)testUpdateWithTextCreatesFormatterIfItIsNil
{
// Arrange
sut.selectedMathModel = 1;

// Act
[sut updateWithText:@".3"];
id formatter = [sut valueForKey:@"_numberFormatter"];

// Assert
XCTAssertNotNil(formatter);

}

- (void)testUpdateWithTextAllowsNumbersWithDot
{


// Arrange
sut.selectedMathModel = 2;

// Act
[sut updateWithText:@".4"];
[sut convertValue];

NSString *result = [sut text];
// Assert
XCTAssertEqualObjects(result, @"1.016");
}

- (void)testUpdateWithTextUpdatesText
{
// Arrange

// Act

[sut updateWithText:@"666"];
NSString *toAssert = [sut text];
// Assert
XCTAssertEqualObjects(toAssert, @"666");
}

- (void)testUpdateWithTextUpdatesValue
{
// Arrange

sut.selectedMathModel = 3;
// Act

[sut updateWithText:@"130"];
NSNumber *value = [sut valueForKey:@"_value"];
// Assert
XCTAssertEqualObjects(value, [NSNumber numberWithInt:130]);

}

- (void)testUpdateWithTextAlwaysPostsUpdateNotification
{
// Arrange

sut.selectedMathModel = 3;

id myMock = [OCMockObject observerMock];
[[NSNotificationCenter defaultCenter] addMockObserver:myMock
name:kConverterModelDidUpdateNotification
object:sut];

[[myMock expect] notificationWithName:kConverterModelDidUpdateNotification
object:sut];

// Act

[sut updateWithText:@"16.36"];

// Assert
[myMock verify];
[[NSNotificationCenter defaultCenter] removeObserver:myMock];
}


Expand Down
Loading