-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAxisTests.swift
executable file
·67 lines (57 loc) · 1.98 KB
/
AxisTests.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// AxisTests.swift
// CoreLayout
//
// Created by Jake Marsh on 10/15/16.
// Copyright © 2016 Jake Marsh. All rights reserved.
//
import Foundation
@testable import CoreLayout
import XCTest
class AxisTests: CoreLayoutTestCase {
override func containerSize() -> CGSize {
return CGSize(width: 164, height: 164)
}
func axisLayout(primaryAxis: Axis) -> ComputedLayout {
let l = Layout(
container: ContainerBehavior(primaryAxis: primaryAxis),
padding: Edges(all: 8),
children: (1..<4).map { i in
Layout(
identifier: String(i),
size: .absolute(width: 44, height: 44),
margin: (primaryAxis == .vertical ? Edges(bottom: 8) : Edges(trailing: 8))
)
}
)
return l.compute(with: containerSize())
}
func testAxisLayout() {
let values: [Axis : ComputedLayout] = [
.vertical : ComputedLayout(
frame: CGRect(x: 0.0, y: 0.0, width: 164.0, height: 164.0),
children: [
ComputedLayout(frame: CGRect(x: 8.0, y: 8.0, width: 44.0, height: 44.0)),
ComputedLayout(frame: CGRect(x: 8.0, y: 60.0, width: 44.0, height: 44.0)),
ComputedLayout(frame: CGRect(x: 8.0, y: 112.0, width: 44.0, height: 44.0))
]
),
.horizontal : ComputedLayout(
frame: CGRect(x: 0.0, y: 0.0, width: 164.0, height: 164.0),
children: [
ComputedLayout(frame: CGRect(x: 8.0, y: 8.0, width: 44.0, height: 44.0)),
ComputedLayout(frame: CGRect(x: 60.0, y: 8.0, width: 44.0, height: 44.0)),
ComputedLayout(frame: CGRect(x: 112.0, y: 8.0, width: 44.0, height: 44.0))
]
)
]
for (value, computed) in values {
let computedTest = axisLayout(primaryAxis: value)
self.saveImageForComputedLayout(computed: computedTest, name: "primaryAxis-\(value)")
XCTAssert(computedTest == computed, "Axis layout test failed.")
}
}
func testAxisLayoutPerformance1() {
self.measure { _ = self.testAxisLayout() }
}
}