Skip to content

Commit

Permalink
Implement CGFloat+AirBar tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
foxacid7cd committed Jul 11, 2017
1 parent 8dfcfd6 commit d45b89f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions AirBar.xcodeproj/project.pbxproj
Expand Up @@ -47,6 +47,7 @@
6AF8FBD21F14E1E800C1D6CB /* StateRangeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AF8FBD11F14E1E800C1D6CB /* StateRangeTests.swift */; };
6AF8FBD41F14E29400C1D6CB /* ConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AF8FBD31F14E29400C1D6CB /* ConfigurationTests.swift */; };
6AF8FBD71F14E69200C1D6CB /* KVObservableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AF8FBD61F14E69200C1D6CB /* KVObservableTests.swift */; };
6AF8FBDC1F14ECC400C1D6CB /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AF8FBDB1F14ECC400C1D6CB /* CGFloatTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -125,6 +126,7 @@
6AF8FBD11F14E1E800C1D6CB /* StateRangeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StateRangeTests.swift; sourceTree = "<group>"; };
6AF8FBD31F14E29400C1D6CB /* ConfigurationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurationTests.swift; sourceTree = "<group>"; };
6AF8FBD61F14E69200C1D6CB /* KVObservableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KVObservableTests.swift; sourceTree = "<group>"; };
6AF8FBDB1F14ECC400C1D6CB /* CGFloatTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloatTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -197,6 +199,7 @@
6A9BA6031F0FAD870017C3F9 /* Reducer */,
6AF8FBCE1F14DE7100C1D6CB /* Models */,
6AF8FBD51F14E5EB00C1D6CB /* Observables */,
6AF8FBDA1F14EC9700C1D6CB /* Helpers */,
6A243AD41E6028D500AC0D40 /* Info.plist */,
);
path = AirBarTests;
Expand Down Expand Up @@ -317,6 +320,14 @@
path = Observables;
sourceTree = "<group>";
};
6AF8FBDA1F14EC9700C1D6CB /* Helpers */ = {
isa = PBXGroup;
children = (
6AF8FBDB1F14ECC400C1D6CB /* CGFloatTests.swift */,
);
path = Helpers;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -490,6 +501,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6AF8FBDC1F14ECC400C1D6CB /* CGFloatTests.swift in Sources */,
6A9BA6091F0FB4C90017C3F9 /* CutOutStateRangeDeltaYTransformerTests.swift in Sources */,
6AF8FBD71F14E69200C1D6CB /* KVObservableTests.swift in Sources */,
6AF8FBD21F14E1E800C1D6CB /* StateRangeTests.swift in Sources */,
Expand Down
35 changes: 35 additions & 0 deletions AirBarTests/Helpers/CGFloatTests.swift
@@ -0,0 +1,35 @@
//
// CGFloatTests.swift
// AirBar
//
// Created by Евгений Матвиенко on 7/11/17.
// Copyright © 2017 uptechteam. All rights reserved.
//

import XCTest
@testable import AirBar

class CGFloatTests: XCTestCase {
func testIsNear() {
let testFloat: CGFloat = 0

XCTAssertTrue(testFloat.isNear(to: 0.1, delta: 0.2))
XCTAssertTrue(testFloat.isNear(to: 0.2, delta: 0.2))
XCTAssertFalse(testFloat.isNear(to: 0.3, delta: 0.2))
XCTAssertFalse(testFloat.isNear(to: 0.4, delta: 0.2))
}

func testMap() {
XCTAssertEqual((0 as CGFloat).map(from: (0, 1), to: (1, 2)), 1)
XCTAssertEqual((1 as CGFloat).map(from: (0, 1), to: (1, 2)), 2)
XCTAssertEqual((2 as CGFloat).map(from: (0, 4), to: (1, 2)), 1.5)
XCTAssertEqual((0 as CGFloat).map(from: (2, 4), to: (1, 2)), 1)
XCTAssertEqual((10 as CGFloat).map(from: (2, 4), to: (1, 2)), 2)
}

func testBounded() {
XCTAssertEqual((0 as CGFloat).bounded(by: (1, 2)), 1)
XCTAssertEqual((1 as CGFloat).bounded(by: (-10, -8)), -8)
XCTAssertEqual((1 as CGFloat).bounded(by: (0, 2)), 1)
}
}

0 comments on commit d45b89f

Please sign in to comment.