Skip to content

Commit

Permalink
Use Makefile for build
Browse files Browse the repository at this point in the history
  • Loading branch information
bradhowes committed Jul 6, 2023
1 parent a4eddfb commit 9174be7
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 97 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Run monitor tests
run: xcodebuild -workspace JoyStickView.xcworkspace test -destination 'name=iPhone 11' -scheme 'JoyStickView'
- name: Run view tests
run: xcodebuild -workspace JoyStickView.xcworkspace test -destination 'name=iPhone 11' -scheme 'JoyStickView App'
- name: Build, test, and code coverage
run make
- name: Create Coverage Badge
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GIST_UPDATE }}
gistID: 4739895cbf46573cc4b63ab776c74899
filename: Joystick-coverage.json
label: Coverage
message: ${{ env.PERCENTAGE }}
color: success
8 changes: 8 additions & 0 deletions JoyStickView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
BD0E7DB92A55F57E00181929 /* Polar.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD0E7DB82A55F57E00181929 /* Polar.swift */; };
BD0E7DBC2A575B6500181929 /* CoreGraphics+AdditionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD0E7DBA2A575A9200181929 /* CoreGraphics+AdditionsTests.swift */; };
BD0E7DBF2A57618100181929 /* Bundle+AdditionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD0E7DBD2A57617300181929 /* Bundle+AdditionsTests.swift */; };
BD4CAF182210696000DECD93 /* JoyStickViewMonitorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD4CAF172210696000DECD93 /* JoyStickViewMonitorTests.swift */; };
BDA7F8E8218B1DE400A9AB5B /* Bundle+Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDA7F8E7218B1DE400A9AB5B /* Bundle+Additions.swift */; };
BDBB51BA220ADE1E00C579B2 /* JoyStickViewMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDBB51B9220ADE1E00C579B2 /* JoyStickViewMonitor.swift */; };
Expand All @@ -30,6 +32,8 @@

/* Begin PBXFileReference section */
BD0E7DB82A55F57E00181929 /* Polar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Polar.swift; sourceTree = "<group>"; };
BD0E7DBA2A575A9200181929 /* CoreGraphics+AdditionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreGraphics+AdditionsTests.swift"; sourceTree = "<group>"; };
BD0E7DBD2A57617300181929 /* Bundle+AdditionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bundle+AdditionsTests.swift"; sourceTree = "<group>"; };
BD4CAF172210696000DECD93 /* JoyStickViewMonitorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JoyStickViewMonitorTests.swift; sourceTree = "<group>"; };
BD75800B215B66F000B787D2 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
BDA7F8E7218B1DE400A9AB5B /* Bundle+Additions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+Additions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -76,6 +80,8 @@
isa = PBXGroup;
children = (
BD4CAF172210696000DECD93 /* JoyStickViewMonitorTests.swift */,
BD0E7DBA2A575A9200181929 /* CoreGraphics+AdditionsTests.swift */,
BD0E7DBD2A57617300181929 /* Bundle+AdditionsTests.swift */,
BDBB51D3220B0D9900C579B2 /* Info.plist */,
);
name = Tests;
Expand Down Expand Up @@ -252,6 +258,8 @@
buildActionMask = 2147483647;
files = (
BD4CAF182210696000DECD93 /* JoyStickViewMonitorTests.swift in Sources */,
BD0E7DBF2A57618100181929 /* Bundle+AdditionsTests.swift in Sources */,
BD0E7DBC2A575B6500181929 /* CoreGraphics+AdditionsTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ class JoyStickView_AppUITests: XCTestCase {

XCTAssertEqual(Float(dispLabel.label)!, 0.707, accuracy: 0.001)
XCTAssertEqual(Float(angleLabel.label)!, 0.0, accuracy: 0.001)

constrainMode.tap()

// Move diagonally to upper-left.
start.press(forDuration: 0.25,
thenDragTo: start.withOffset(CGVector(dx: -200, dy: -200.0)),
withVelocity: .fast,
thenHoldForDuration: 0.25)

XCTAssertEqual(Float(dispLabel.label)!, 1.0, accuracy: 0.001)
XCTAssertEqual(Float(angleLabel.label)!, 315.0, accuracy: 0.001)

}

func testDoubleTapReturnsToOrigin() {
Expand Down
2 changes: 1 addition & 1 deletion Sources/JoyStickView/Bundle+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension Bundle {
one of the "s.resource_bundles" keys from the podspec file that defines the CocoPod.
- returns: the resource Bundle or `self` if resource bundle was not found
*/
func podResource(name: String) -> Bundle {
public func podResource(name: String) -> Bundle {
guard let bundleUrl = self.url(forResource: name, withExtension: "bundle") else { return self }
return Bundle(url: bundleUrl) ?? self
}
Expand Down
84 changes: 0 additions & 84 deletions Sources/JoyStickView/CoreGraphics+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@ public extension CGRect {
/// Convenience functions for CGVector.
public extension CGVector {

/**
Multiply the components of a CGVector by a scalar
- parameter lhs: the CGVector to multiply
- parameter rhs: the scalar to multiply
- returns new CGVector
*/
@inlinable
static func * (lhs: CGVector, rhs: CGFloat) -> CGVector { .init(dx: lhs.dx * rhs, dy: lhs.dy * rhs) }

/**
Multiply the components of a CGVector by a scalar
- parameter lhs: the CGVector to multiply
- parameter rhs: the scalar to multiply
- returns new CGVector
*/
@inlinable
static func * (lhs: CGVector, rhs: Double) -> CGVector { lhs * CGFloat(rhs) }

/// Obtain the squared magnitude of the CGVector
@inlinable
var magnitude2: CGFloat { dx * dx + dy * dy }
Expand Down Expand Up @@ -69,15 +51,6 @@ public extension CGPoint {
@inlinable
static func - (lhs: CGPoint, rhs: CGVector) -> CGPoint { .init(x: lhs.x - rhs.dx, y: lhs.y - rhs.dy) }

/**
Subtract the components of a CGPoint and a CGSize
- parameter lhs: the CGPoint to subtract
- parameter rhs: the CGSize to subtract
- returns: new CGPoint representing the difference
*/
@inlinable
static func - (lhs: CGPoint, rhs: CGSize) -> CGPoint { .init(x: lhs.x - rhs.width, y: lhs.y - rhs.height) }

/**
Subtract the components of two CGPoint values
- parameter lhs: the CGPoint to subtract
Expand All @@ -87,60 +60,3 @@ public extension CGPoint {
@inlinable
static func - (lhs: CGPoint, rhs: CGPoint) -> CGVector { .init(dx: lhs.x - rhs.x, dy: lhs.y - rhs.y) }
}

/// Convenience functions for CGSize.
public extension CGSize {

/**
Add two CGSize values
- parameter lhs: the CGSize to add
- parameter rhs: the CGSize to add
- returns: new CGSize representing the sum
*/
@inlinable
static func + (lhs: CGSize, rhs: CGSize) -> CGSize {
.init(width: lhs.width + rhs.width, height: lhs.height + rhs.height)
}

/**
Multiply the components of a CGSize value by a scalar
- parameter lhs: the CGSize to multiply
- parameter rhs: the scalar to multiply
- returns: new CGSize representing the result
*/
@inlinable
static func * (lhs: CGSize, rhs: CGFloat) -> CGSize {
.init(width: lhs.width * rhs, height: lhs.height * rhs)
}

/**
Multiply the components of a CGSize value by a scalar
- parameter lhs: the scalar to multiply
- parameter rhs: the CGSize to multiply
- returns: new CGSize representing the result
*/
@inlinable
static func * (lhs: CGFloat, rhs: CGSize) -> CGSize { rhs * lhs }

/**
Divide the components of a CGSize value by a scalar
- parameter lhs: the CGSize to divide
- parameter rhs: the scalar to divide
- returns: new CGSize representing the result
*/
@inlinable
static func / (lhs: CGSize, rhs: CGFloat) -> CGSize {
.init(width: lhs.width / rhs, height: lhs.height / rhs)
}

/**
Divide the components of two CGSize values
- parameter lhs: the CGSize to divide
- parameter rhs: the CGSize to divide
- returns: new CGSize representing the result
*/
@inlinable
static func / (lhs: CGSize, rhs: CGSize) -> CGSize {
.init(width: lhs.width / rhs.width, height: lhs.height / rhs.height)
}
}
10 changes: 3 additions & 7 deletions Sources/JoyStickView/JoyStickView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ import CoreGraphics
/// use `CGRect(x: 50, y: 0, width: 1, height: 100)`
public var handleConstraint: CGRect? {
didSet {
handleCenterClamper = { $0 }
if case .some(let hc) = handleConstraint {
print("clamper: \(hc)")
handleCenterClamper = { pos in
let clamped = CGPoint(x: min(max(pos.x, hc.minX), hc.maxX), y: min(max(pos.y, hc.minY), hc.maxY))
print("\(hc) clamping: \(pos) -> \(clamped)")
return clamped
}
handleCenterClamper = { .init(x: min(max($0.x, hc.minX), hc.maxX), y: min(max($0.y, hc.minY), hc.maxY)) }
} else {
handleCenterClamper = { $0 }
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/JoyStickViewTests/Bundle+AdditionsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright © 2023 Brad Howes. All rights reserved.

import XCTest
import JoyStickView

class BundleAdditionsTests: XCTestCase {

func testPodResource() {
let main = Bundle.main
for bundle in Bundle.allBundles {
_ = main.podResource(name: bundle.description)
}
}
}
46 changes: 46 additions & 0 deletions Tests/JoyStickViewTests/CoreGraphics+AdditionsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright © 2023 Brad Howes. All rights reserved.

import XCTest
import JoyStickView

class CoreGraphicsAdditionsTests: XCTestCase {

func testCGRectMid() {
let rect = CGRect(x: 0, y: 0, width: 100, height: 220)
XCTAssertEqual(rect.mid, CGPoint(x: 50, y: 110))
}

func testCGVectorMagnitude() {
let v1 = CGVector(dx: 1.23, dy: 4.5)
XCTAssertEqual(v1.magnitude, sqrt(v1.dx * v1.dx + v1.dy * v1.dy))
}

func testCGVectorMagnitudeSquared() {
let v1 = CGVector(dx: 1.23, dy: 4.5)
XCTAssertEqual(v1.magnitude2, v1.dx * v1.dx + v1.dy * v1.dy)
}

func testCGPointPlusCGVector() {
let p1 = CGPoint(x: 1.2, y: 3.4)
let v1 = CGVector(dx: 5.6, dy: 7.8)
XCTAssertEqual(p1 + v1, CGPoint(x: p1.x + v1.dx, y: p1.y + v1.dy))
}

func testCGPointPlusCGSize() {
let p1 = CGPoint(x: 1.2, y: 3.4)
let s1 = CGSize(width: 5.6, height: 7.8)
XCTAssertEqual(p1 + s1, CGPoint(x: p1.x + s1.width, y: p1.y + s1.height))
}

func testCGPointMinusCGVector() {
let p1 = CGPoint(x: 1.2, y: 3.4)
let v1 = CGVector(dx: 5.6, dy: 7.8)
XCTAssertEqual(p1 - v1, CGPoint(x: p1.x - v1.dx, y: p1.y - v1.dy))
}

func testCGPointMinusCGPoint() {
let p1 = CGPoint(x: 1.2, y: 3.4)
let p2 = CGPoint(x: 5.6, y: 7.8)
XCTAssertEqual(p1 - p2, CGVector(dx: p1.x - p2.x, dy: p1.y - p2.y))
}
}

0 comments on commit 9174be7

Please sign in to comment.