Skip to content
This repository has been archived by the owner on Nov 21, 2017. It is now read-only.

Commit

Permalink
Implement swift scheduler tests.
Browse files Browse the repository at this point in the history
Summary: This new test case uses scoped classes to create a self-contained unit test. This is part of a push to improve the ease with which tests can be understood.

Reviewers: O4 Material Motion Apple platform reviewers, O2 Material Motion, markwei

Reviewed By: O4 Material Motion Apple platform reviewers, O2 Material Motion, markwei

Tags: #material_motion

Differential Revision: http://codereview.cc/D1589
  • Loading branch information
jverkoey committed Sep 10, 2016
1 parent f6a3337 commit a76a62d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 47 deletions.
10 changes: 5 additions & 5 deletions examples/apps/Catalog/Catalog.xcodeproj/project.pbxproj
Expand Up @@ -13,14 +13,14 @@
4489E3B5A134470DCF97D0CD /* Pods_MaterialMotionRuntime_UnitTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2B624803B0AE3BEB727C4F2 /* Pods_MaterialMotionRuntime_UnitTests.framework */; };
661369711D5BE7CB00F6830F /* ComposedPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 661369701D5BE7CB00F6830F /* ComposedPerformanceTests.swift */; };
6624C6431D466D7C00DF3108 /* DelegatedPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6624C6421D466D7C00DF3108 /* DelegatedPerformanceTests.swift */; };
66251F1E1D360C8E006EBC89 /* MDMRuntimeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 66251F1C1D360C87006EBC89 /* MDMRuntimeTests.m */; };
6625A5531D467EBD00FD10F7 /* TestSchedulerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6625A5521D467EBD00FD10F7 /* TestSchedulerDelegate.swift */; };
66876C601D25ED610054CED4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 66876C5F1D25ED610054CED4 /* main.m */; };
66876C631D25ED610054CED4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 66876C621D25ED610054CED4 /* AppDelegate.m */; };
66876C6B1D25ED610054CED4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 66876C6A1D25ED610054CED4 /* Assets.xcassets */; };
66876C6E1D25ED610054CED4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 66876C6C1D25ED610054CED4 /* LaunchScreen.storyboard */; };
66DBB8D21D341BFB0048FC80 /* PlanFadeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 66DBB8CF1D341BFB0048FC80 /* PlanFadeViewController.m */; };
66DBB8D31D341BFB0048FC80 /* Tween.m in Sources */ = {isa = PBXBuildFile; fileRef = 66DBB8D11D341BFB0048FC80 /* Tween.m */; };
66F0320F1D8336C70094B9C9 /* SchedulerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66F0320E1D8336C70094B9C9 /* SchedulerTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -46,7 +46,6 @@
661369701D5BE7CB00F6830F /* ComposedPerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComposedPerformanceTests.swift; sourceTree = "<group>"; };
6624C6421D466D7C00DF3108 /* DelegatedPerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DelegatedPerformanceTests.swift; sourceTree = "<group>"; };
66251F111D360C65006EBC89 /* UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
66251F1C1D360C87006EBC89 /* MDMRuntimeTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MDMRuntimeTests.m; sourceTree = "<group>"; };
6625A5511D467D1C00FD10F7 /* UnitTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "UnitTests-Bridging-Header.h"; path = "UnitTests/UnitTests-Bridging-Header.h"; sourceTree = SOURCE_ROOT; };
6625A5521D467EBD00FD10F7 /* TestSchedulerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestSchedulerDelegate.swift; sourceTree = "<group>"; };
66876C5B1D25ED610054CED4 /* Catalog.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Catalog.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -60,6 +59,7 @@
66DBB8CF1D341BFB0048FC80 /* PlanFadeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlanFadeViewController.m; sourceTree = "<group>"; };
66DBB8D01D341BFB0048FC80 /* Tween.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Tween.h; sourceTree = "<group>"; };
66DBB8D11D341BFB0048FC80 /* Tween.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Tween.m; sourceTree = "<group>"; };
66F0320E1D8336C70094B9C9 /* SchedulerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulerTests.swift; sourceTree = "<group>"; };
75F2F4A20A51B559BDF137E9 /* Pods-MaterialMotionRuntime-Catalog.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MaterialMotionRuntime-Catalog.debug.xcconfig"; path = "../../../Pods/Target Support Files/Pods-MaterialMotionRuntime-Catalog/Pods-MaterialMotionRuntime-Catalog.debug.xcconfig"; sourceTree = "<group>"; };
B2B624803B0AE3BEB727C4F2 /* Pods_MaterialMotionRuntime_UnitTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MaterialMotionRuntime_UnitTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C0EA85F5845AC624D40CFF3B /* Pods-MaterialMotionRuntime-Catalog.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MaterialMotionRuntime-Catalog.release.xcconfig"; path = "../../../Pods/Target Support Files/Pods-MaterialMotionRuntime-Catalog/Pods-MaterialMotionRuntime-Catalog.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -97,7 +97,8 @@
66251F1B1D360C87006EBC89 /* unit */ = {
isa = PBXGroup;
children = (
66251F1C1D360C87006EBC89 /* MDMRuntimeTests.m */,
6625A5511D467D1C00FD10F7 /* UnitTests-Bridging-Header.h */,
66F0320E1D8336C70094B9C9 /* SchedulerTests.swift */,
3630F1AE1D3E9B82001E1C83 /* RuntimeTestTypes.h */,
3630F1AB1D3E99CF001E1C83 /* RuntimeTestTypes.m */,
661369701D5BE7CB00F6830F /* ComposedPerformanceTests.swift */,
Expand Down Expand Up @@ -137,7 +138,6 @@
66876C6A1D25ED610054CED4 /* Assets.xcassets */,
66876C6C1D25ED610054CED4 /* LaunchScreen.storyboard */,
66876C6F1D25ED610054CED4 /* Info.plist */,
6625A5511D467D1C00FD10F7 /* UnitTests-Bridging-Header.h */,
66876C5E1D25ED610054CED4 /* Supporting Files */,
);
path = src;
Expand Down Expand Up @@ -388,10 +388,10 @@
buildActionMask = 2147483647;
files = (
6625A5531D467EBD00FD10F7 /* TestSchedulerDelegate.swift in Sources */,
66F0320F1D8336C70094B9C9 /* SchedulerTests.swift in Sources */,
661369711D5BE7CB00F6830F /* ComposedPerformanceTests.swift in Sources */,
6624C6431D466D7C00DF3108 /* DelegatedPerformanceTests.swift in Sources */,
3630F1AF1D3E9BC1001E1C83 /* RuntimeTestTypes.m in Sources */,
66251F1E1D360C8E006EBC89 /* MDMRuntimeTests.m in Sources */,
3696FD981D41363000535C4E /* TwoDifferentPlansTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
42 changes: 0 additions & 42 deletions tests/unit/MDMRuntimeTests.m

This file was deleted.

66 changes: 66 additions & 0 deletions tests/unit/SchedulerTests.swift
@@ -0,0 +1,66 @@
/*
Copyright 2016-present The Material Motion Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import XCTest
import MaterialMotionRuntime

class SchedulerTests: XCTestCase {

// Verify that a plan committed to a scheduler immediately executes its add(plan:) logic.
func testAddPlanInvokedImmediately() {
let state = State()
state.boolean = false

let plan = ChangeBoolean(desiredBoolean: true)

let transaction = Transaction()
transaction.add(plan: plan, to: state)

let scheduler = Scheduler()
scheduler.commit(transaction: transaction)

XCTAssertEqual(state.boolean, plan.desiredBoolean)
}

// Simple instantiable target with a mutable boolean property.
private class State {
var boolean = false
}

private class ChangeBoolean: NSObject, Plan {
var desiredBoolean: Bool

init(desiredBoolean: Bool) {
self.desiredBoolean = desiredBoolean
}

func performerClass() -> AnyClass {
return Performer.self
}

private class Performer: NSObject, Performing, PlanPerforming {
let target: State
required init(target: Any) {
self.target = target as! State
}

func add(plan: Plan) {
let testPlan = plan as! ChangeBoolean
target.boolean = testPlan.desiredBoolean
}
}
}
}

0 comments on commit a76a62d

Please sign in to comment.