Skip to content

Commit

Permalink
Merge pull request #173 from freshOS/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
s4cha authored Sep 24, 2024
2 parents c065867 + f834109 commit 1c2eaef
Show file tree
Hide file tree
Showing 17 changed files with 1,334 additions and 1,381 deletions.
15 changes: 15 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"originHash" : "0d1e08a917a619df6510ae568b5ab623f1fc22dffa644b8c590c04c4a5b086bc",
"pins" : [
{
"identity" : "swift-numerics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-numerics",
"state" : {
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
"version" : "1.0.2"
}
}
],
"version" : 3
}
8 changes: 7 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ let package = Package(
.tvOS(.v12)
],
products: [.library(name: "Stevia", targets: ["Stevia"])],
dependencies: [
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"),
],
targets: [
.target(name: "Stevia", path: "Sources", resources: [.copy("PrivacyInfo.xcprivacy")]),
.testTarget(name: "SteviaTests", dependencies: ["Stevia"]),
.testTarget(name: "SteviaTests", dependencies: [
"Stevia",
.product(name: "Numerics", package: "swift-numerics"),
]),
]
)
7 changes: 0 additions & 7 deletions Tests/LinuxMain.swift

This file was deleted.

33 changes: 15 additions & 18 deletions Tests/SteviaTests/BaselineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,40 @@
// Copyright © 2018 Sacha Durand Saint Omer. All rights reserved.
//

import XCTest
import UIKit
import Stevia
import Testing

@MainActor class BaselineTests: XCTestCase {
@Suite
@MainActor struct BaselineTests {

var win: UIWindow!
var ctrler: UIViewController!
var label1 = UILabel()
var label2 = UILabel()
let win = UIWindow(frame: UIScreen.main.bounds)
let ctrler = UIViewController()
let label1 = UILabel()
let label2 = UILabel()

override func setUp() async throws {
win = UIWindow(frame: UIScreen.main.bounds)
ctrler = UIViewController()
init() {
win.rootViewController = ctrler
label1 = UILabel()
label2 = UILabel()

ctrler.view.subviews {
label1
label2
}
}



func testAlignLastBaselines() {
@Test
func alignLastBaselines() {
label1.top(100)
align(lastBaselines: label1, label2)
ctrler.view.layoutIfNeeded()
XCTAssertEqual(label1.forLastBaselineLayout.frame.minY, label2.forLastBaselineLayout.frame.minY)
#expect(label1.forLastBaselineLayout.frame.minY == label2.forLastBaselineLayout.frame.minY)
}

func testAlignFirstBaselines() {
@Test
func alignFirstBaselines() {
label1.top(100)
align(firstBaselines: label1, label2)
ctrler.view.layoutIfNeeded()
XCTAssertEqual(label1.forLastBaselineLayout.frame.minY, label2.forLastBaselineLayout.frame.minY)
#expect(label1.forLastBaselineLayout.frame.minY == label2.forLastBaselineLayout.frame.minY)
}
}

172 changes: 80 additions & 92 deletions Tests/SteviaTests/CenterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,149 +6,137 @@
// Copyright © 2016 Sacha Durand Saint Omer. All rights reserved.
//

import XCTest
import Testing
import Numerics
import UIKit
import Stevia

let magicalIphoneXShift = 0.17

@MainActor class CenterTests: XCTestCase {
@Suite
@MainActor struct CenterTests {

var win: UIWindow!
var ctrler: UIViewController!
var v: UIView!
let win = UIWindow(frame: UIScreen.main.bounds)
var ctrler = UIViewController()
var v = UIView()

override func setUp() async throws {
// try await super.setUp()
win = UIWindow(frame: UIScreen.main.bounds)
ctrler = UIViewController()
init() {
win.rootViewController = ctrler
v = UIView()
ctrler.view.subviews { v! }

// verify view h as default values
XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne))

ctrler.view.subviews { v }
v.size(100)
ctrler.view.layoutIfNeeded()
XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne))
}

override func tearDown() {
super.tearDown()
}

func testCenterHorizontally() {
@Test
func centerHorizontally() {
v.centerHorizontally()
ctrler.view.setNeedsLayout()
ctrler.view.layoutIfNeeded()
XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.origin.x,
ctrler.view.frame.width/2.0 - (v.frame.width/2.0),
accuracy: CGFloat(magicalIphoneXShift))
XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne))
#expect(v.frame.origin.y == 0)
#expect(isApproximatelyEqual(v.frame.origin.x, ctrler.view.frame.width/2.0 - (v.frame.width/2.0)))
#expect(v.frame.width == 100)
#expect(v.frame.height == 100)
}

func testCenterHorizontallyWithOffsetDouble() {
@Test
func centerHorizontallyWithOffsetDouble() {
v.centerHorizontally(offset: Double(50))
ctrler.view.setNeedsLayout()
ctrler.view.layoutIfNeeded()
XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.origin.x - 50,
ctrler.view.frame.width/2.0 - (v.frame.width/2.0),
accuracy: CGFloat(magicalIphoneXShift))
XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne))
#expect(v.frame.origin.y == 0)
let val = v.frame.origin.x - 50
#expect(isApproximatelyEqual(val, ctrler.view.frame.width/2.0 - (v.frame.width/2.0)))
#expect(v.frame.width == 100)
#expect(v.frame.height == 100)
}

func testCenterHorizontallyWithOffsetCGFloat() {
@Test
func centerHorizontallyWithOffsetCGFloat() {
v.centerHorizontally(offset: CGFloat(50))
ctrler.view.setNeedsLayout()
ctrler.view.layoutIfNeeded()
XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.origin.x - 50,
ctrler.view.frame.width/2.0 - (v.frame.width/2.0),
accuracy: CGFloat(magicalIphoneXShift))
XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne))
#expect(v.frame.origin.y == 0)
let val = v.frame.origin.x - 50
#expect(isApproximatelyEqual(val, (ctrler.view.frame.width/2.0 - (v.frame.width/2.0))))
#expect(v.frame.width == 100)
#expect(v.frame.height == 100)
}

func testCenterHorizontallyWithOffsetInt() {
@Test
func centerHorizontallyWithOffsetInt() {
v.centerHorizontally(offset: Int(50))
ctrler.view.setNeedsLayout()
ctrler.view.layoutIfNeeded()
XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.origin.x - 50,
ctrler.view.frame.width/2.0 - (v.frame.width/2.0),
accuracy: CGFloat(magicalIphoneXShift))
XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne))
#expect(v.frame.origin.y == 0)
let val = v.frame.origin.x - 50
#expect(isApproximatelyEqual(val, (ctrler.view.frame.width/2.0 - (v.frame.width/2.0))))
#expect(v.frame.width == 100)
#expect(v.frame.height == 100)
}

func testCenterVertically() {
@Test
func centerVertically() {
v.centerVertically()
ctrler.view.setNeedsLayout()
ctrler.view.layoutIfNeeded()
XCTAssertEqual(v.frame.origin.y,
ctrler.view.frame.height/2.0 - (v.frame.height/2.0),
accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne))
#expect(v.frame.origin.y == ctrler.view.frame.height/2.0 - (v.frame.height/2.0))
#expect(v.frame.origin.x == 0)
#expect(v.frame.width == 100)
#expect(v.frame.height == 100)
}

func testCenterVerticallyWithOffsetDouble() {
@Test
func centerVerticallyWithOffsetDouble() {
v.centerVertically(offset: Double(50))
ctrler.view.setNeedsLayout()
ctrler.view.layoutIfNeeded()
XCTAssertEqual(v.frame.origin.y - 50,
ctrler.view.frame.height/2.0 - (v.frame.height/2.0),
accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne))
let val = v.frame.origin.y - 50
#expect(isApproximatelyEqual(val, (ctrler.view.frame.height/2.0 - (v.frame.height/2.0))))
#expect(v.frame.origin.x == 0)
#expect(v.frame.width == 100)
#expect(v.frame.height == 100)
}

func testCenterVerticallyWithOffsetCGFloat() {
@Test
func centerVerticallyWithOffsetCGFloat() {
v.centerVertically(offset: CGFloat(50))
ctrler.view.setNeedsLayout()
ctrler.view.layoutIfNeeded()
XCTAssertEqual(v.frame.origin.y - 50,
ctrler.view.frame.height/2.0 - (v.frame.height/2.0),
accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne))
let val = v.frame.origin.y - 50
#expect(isApproximatelyEqual(val, (ctrler.view.frame.height/2.0 - (v.frame.height/2.0))))
#expect(v.frame.origin.x == 0)
#expect(v.frame.width == 100)
#expect(v.frame.height == 100)
}

func testCenterVerticallyWithOffsetInt() {
@Test
func centerVerticallyWithOffsetInt() {
v.centerVertically(offset: Int(50))
ctrler.view.setNeedsLayout()
ctrler.view.layoutIfNeeded()
XCTAssertEqual(v.frame.origin.y - 50,
ctrler.view.frame.height/2.0 - (v.frame.height/2.0),
accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne))

let val = v.frame.origin.y - 50
#expect(isApproximatelyEqual(val, (ctrler.view.frame.height/2.0 - (v.frame.height/2.0))))
#expect(v.frame.origin.x == 0)
#expect(v.frame.width == 100)
#expect(v.frame.height == 100)
}

func testCenterInContainer() {
@Test
func centerInContainer() {
v.centerInContainer()
ctrler.view.setNeedsLayout()
ctrler.view.layoutIfNeeded()
XCTAssertEqual(v.frame.origin.y,
ctrler.view.frame.height/2.0 - (v.frame.height/2.0),
accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.origin.x,
ctrler.view.frame.width/2.0 - (v.frame.width/2.0),
accuracy: CGFloat(magicalIphoneXShift))
XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne))
XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne))

#expect(v.frame.origin.y == ctrler.view.frame.height/2.0 - (v.frame.height/2.0))
#expect(isApproximatelyEqual(v.frame.origin.x, ctrler.view.frame.width/2.0 - (v.frame.width/2.0)))
#expect(v.frame.width == 100)
#expect(v.frame.height == 100)
#expect(isApproximatelyEqual(v.frame.origin.y, ctrler.view.frame.height/2.0 - (v.frame.height/2.0)))
#expect(isApproximatelyEqual(v.frame.origin.x, ctrler.view.frame.width/2.0 - (v.frame.width/2.0)))
#expect(v.frame.height == 100)
}
}

func isApproximatelyEqual(_ a: Double, _ b: Double) -> Bool {
return a.isApproximatelyEqual(to: b, absoluteTolerance: 0.5)
}
Loading

0 comments on commit 1c2eaef

Please sign in to comment.