-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathAlignmentIDTests.swift
51 lines (47 loc) · 1.23 KB
/
AlignmentIDTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// AlignmentIDTests.swift
//
//
// Created by Kyle on 2023/12/16.
//
@testable import OpenSwiftUI
import Testing
#if canImport(Darwin)
import CoreGraphics
#else
import Foundation
#endif
struct AlignmentIDTests {
private struct TestAlignment: AlignmentID {
static func defaultValue(in _: ViewDimensions) -> CGFloat { .zero }
}
@Test
func combineExplicitLinear() throws {
var value: CGFloat?
try (0 ... 10).forEach { n in
TestAlignment._combineExplicit(
childValue: .init(n),
n,
into: &value
)
let value = try #require(value)
// TODO: use swift-numerics
// https://github.com/apple/swift-testing/issues/165
#expect(abs(value - CGFloat(n) / 2) <= 0.0001)
}
}
@Test
func combineExplicitSame() throws {
var value: CGFloat?
let child = CGFloat.random(in: 0.0 ... 100.0)
try (0 ... 10).forEach { n in
TestAlignment._combineExplicit(
childValue: child,
n,
into: &value
)
let value = try #require(value)
#expect(abs(value - child) <= 0.0001)
}
}
}