Skip to content

Commit

Permalink
finished 1/2 - building ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Bao authored and Thomas Bao committed May 31, 2016
1 parent 3f91044 commit 21e4f10
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
8 changes: 8 additions & 0 deletions FoodTracker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
A71B0A461CFD50E10044F41A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A71B0A441CFD50E10044F41A /* LaunchScreen.storyboard */; };
A71B0A511CFD50E10044F41A /* FoodTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A71B0A501CFD50E10044F41A /* FoodTrackerTests.swift */; };
A71B0A5C1CFD65F40044F41A /* RatingControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = A71B0A5B1CFD65F40044F41A /* RatingControl.swift */; };
A7CEBF391CFD7694008A606F /* Meal.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7CEBF381CFD7694008A606F /* Meal.swift */; };
A7CEBF3A1CFD7694008A606F /* Meal.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7CEBF381CFD7694008A606F /* Meal.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -38,6 +40,7 @@
A71B0A501CFD50E10044F41A /* FoodTrackerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodTrackerTests.swift; sourceTree = "<group>"; };
A71B0A521CFD50E10044F41A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A71B0A5B1CFD65F40044F41A /* RatingControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RatingControl.swift; sourceTree = "<group>"; };
A7CEBF381CFD7694008A606F /* Meal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Meal.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -81,6 +84,7 @@
children = (
A71B0A3B1CFD50E10044F41A /* AppDelegate.swift */,
A71B0A3D1CFD50E10044F41A /* ViewController.swift */,
A7CEBF381CFD7694008A606F /* Meal.swift */,
A71B0A3F1CFD50E10044F41A /* Main.storyboard */,
A71B0A421CFD50E10044F41A /* Assets.xcassets */,
A71B0A5B1CFD65F40044F41A /* RatingControl.swift */,
Expand Down Expand Up @@ -200,6 +204,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A7CEBF391CFD7694008A606F /* Meal.swift in Sources */,
A71B0A3E1CFD50E10044F41A /* ViewController.swift in Sources */,
A71B0A5C1CFD65F40044F41A /* RatingControl.swift in Sources */,
A71B0A3C1CFD50E10044F41A /* AppDelegate.swift in Sources */,
Expand All @@ -210,6 +215,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A7CEBF3A1CFD7694008A606F /* Meal.swift in Sources */,
A71B0A511CFD50E10044F41A /* FoodTrackerTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -394,6 +400,7 @@
A71B0A571CFD50E10044F41A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
A71B0A581CFD50E10044F41A /* Build configuration list for PBXNativeTarget "FoodTrackerTests" */ = {
isa = XCConfigurationList;
Expand All @@ -402,6 +409,7 @@
A71B0A5A1CFD50E10044F41A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
33 changes: 33 additions & 0 deletions FoodTracker/Meal.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Meal.swift
// FoodTracker
//
// Created by Thomas Bao on 5/31/16.
// Copyright © 2016 Thomas Bao. All rights reserved.
//

import UIKit

class Meal {
// MARK: Properties

var name: String
var photo: UIImage?
var rating: Int

// MARK: Initialization

init?(name: String, photo: UIImage?, rating: Int) {
// Initialize stored properties.
self.name = name
self.photo = photo
self.rating = rating

// Initialization should fail if there is no name or if the rating is negative.
if name.isEmpty || rating < 0 {
return nil
}
}
}


35 changes: 14 additions & 21 deletions FoodTrackerTests/FoodTrackerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,19 @@ import XCTest

class FoodTrackerTests: XCTestCase {

override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}

func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
// Put the code you want to measure the time of here.
}
// MARK: FoodTracker Tests

// Tests to confirm that the Meal initializer returns when no name or a negative rating is provided.
func testMealInitialization() {
// Success case.
let potentialItem = Meal(name: "Newest meal", photo: nil, rating: 5)
XCTAssertNotNil(potentialItem)

// Failure cases.
let noName = Meal(name: "", photo: nil, rating: 0)
XCTAssertNil(noName, "Empty name is invalid")

let badRating = Meal(name: "Really bad rating", photo: nil, rating: -1)
XCTAssertNil(badRating)
}

}

0 comments on commit 21e4f10

Please sign in to comment.