Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
@邻家的橘猫
Iosswift
提交
a0d6015a
I
Iosswift
项目概览
@邻家的橘猫
/
Iosswift
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Iosswift
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a0d6015a
编写于
3月 05, 2019
作者:
J
John Hampton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added data model and tests
上级
27f9a9b0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
17 deletion
+63
-17
iOSTemplate.xcodeproj/project.pbxproj
iOSTemplate.xcodeproj/project.pbxproj
+4
-0
iOSTemplate/Meal.swift
iOSTemplate/Meal.swift
+35
-0
iOSTemplateTests/iOSTemplateTests.swift
iOSTemplateTests/iOSTemplateTests.swift
+24
-17
未找到文件。
iOSTemplate.xcodeproj/project.pbxproj
浏览文件 @
a0d6015a
...
...
@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
37154FE2222CBCFE006731A8
/* RatingControl.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
37154FE1222CBCFE006731A8
/* RatingControl.swift */
;
};
37154FE4222F1EF7006731A8
/* Meal.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
37154FE3222F1EF7006731A8
/* Meal.swift */
;
};
3775361422234238005EE5FE
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3775361322234238005EE5FE
/* AppDelegate.swift */
;
};
3775361622234238005EE5FE
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3775361522234238005EE5FE
/* ViewController.swift */
;
};
3775361922234238005EE5FE
/* Main.storyboard in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3775361722234238005EE5FE
/* Main.storyboard */
;
};
...
...
@@ -36,6 +37,7 @@
/* Begin PBXFileReference section */
37154FE1222CBCFE006731A8
/* RatingControl.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
RatingControl.swift
;
sourceTree
=
"<group>"
;
};
37154FE3222F1EF7006731A8
/* Meal.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Meal.swift
;
sourceTree
=
"<group>"
;
};
3775361022234238005EE5FE
/* iOSTemplate.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
iOSTemplate.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
3775361322234238005EE5FE
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
3775361522234238005EE5FE
/* ViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ViewController.swift
;
sourceTree
=
"<group>"
;
};
...
...
@@ -101,6 +103,7 @@
children
=
(
3775361322234238005EE5FE
/* AppDelegate.swift */
,
3775361522234238005EE5FE
/* ViewController.swift */
,
37154FE3222F1EF7006731A8
/* Meal.swift */
,
3775361722234238005EE5FE
/* Main.storyboard */
,
37154FE1222CBCFE006731A8
/* RatingControl.swift */
,
3775361A22234238005EE5FE
/* Assets.xcassets */
,
...
...
@@ -258,6 +261,7 @@
isa
=
PBXSourcesBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
37154FE4222F1EF7006731A8
/* Meal.swift in Sources */
,
3775361622234238005EE5FE
/* ViewController.swift in Sources */
,
37154FE2222CBCFE006731A8
/* RatingControl.swift in Sources */
,
3775361422234238005EE5FE
/* AppDelegate.swift in Sources */
,
...
...
iOSTemplate/Meal.swift
0 → 100644
浏览文件 @
a0d6015a
//
// Meal.swift
// iOSTemplate
//
// Created by John Hampton on 3/5/19.
//
import
UIKit
class
Meal
{
// MARK: Properties
var
name
:
String
var
photo
:
UIImage
?
var
rating
:
Int
// MARK: Initialization
init
?(
name
:
String
,
photo
:
UIImage
?,
rating
:
Int
)
{
// The name must not be empty
guard
!
name
.
isEmpty
else
{
return
nil
}
// The rating must be between 0 and 5 inclusively
guard
(
rating
>=
0
)
&&
(
rating
<=
5
)
else
{
return
nil
}
// Initialize stored properties.
self
.
name
=
name
self
.
photo
=
photo
self
.
rating
=
rating
}
}
iOSTemplateTests/iOSTemplateTests.swift
浏览文件 @
a0d6015a
...
...
@@ -10,24 +10,31 @@ import XCTest
class
iOSTemplateTests
:
XCTestCase
{
override
func
setUp
()
{
// Put setup code here. This method is called before the invocation of each test method in the class.
}
// MARK: Meal Class Tests
override
func
tearDown
()
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
// Confirm that the Meal initializer returns a Meal object when passed valid parameters.
func
testMealInitializationSucceeds
()
{
// Zero rating
let
zeroRatingMeal
=
Meal
.
init
(
name
:
"Zero"
,
photo
:
nil
,
rating
:
0
)
XCTAssertNotNil
(
zeroRatingMeal
)
// Highest positive rating
let
positiveRatingMeal
=
Meal
.
init
(
name
:
"Positive"
,
photo
:
nil
,
rating
:
5
)
XCTAssertNotNil
(
positiveRatingMeal
)
}
func
testExample
()
{
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Confirm that the Meal initialier returns nil when passed a negative rating or an empty name.
func
testMealInitializationFails
()
{
// Negative rating
let
negativeRatingMeal
=
Meal
.
init
(
name
:
"Negative"
,
photo
:
nil
,
rating
:
-
1
)
XCTAssertNil
(
negativeRatingMeal
)
// Empty String
let
emptyStringMeal
=
Meal
.
init
(
name
:
""
,
photo
:
nil
,
rating
:
0
)
XCTAssertNil
(
emptyStringMeal
)
// Rating exceeds maximum
let
largeRatingMeal
=
Meal
.
init
(
name
:
"Large"
,
photo
:
nil
,
rating
:
6
)
XCTAssertNil
(
largeRatingMeal
)
}
func
testPerformanceExample
()
{
// This is an example of a performance test case.
self
.
measure
{
// Put the code you want to measure the time of here.
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录