-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrounding_measure_func_test.go
99 lines (68 loc) · 2.79 KB
/
rounding_measure_func_test.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package flex
import "testing"
func _measureFloor(node *Node, width float32, widthMode MeasureMode, height float32, heightMode MeasureMode) Size {
return Size{
Width: 10.2, Height: 10.2,
}
}
func _measureCeil(node *Node, width float32, widthMode MeasureMode, height float32, heightMode MeasureMode) Size {
return Size{
Width: 10.5, Height: 10.5,
}
}
func _measureFractial(node *Node, width float32, widthMode MeasureMode, height float32, heightMode MeasureMode) Size {
return Size{
Width: 0.5, Height: 0.5,
}
}
func TestRounding_feature_with_custom_measure_func_floor(t *testing.T) {
config := NewConfig()
root := NewNodeWithConfig(config)
rootChild0 := NewNodeWithConfig(config)
rootChild0.SetMeasureFunc(_measureFloor)
root.InsertChild(rootChild0, 0)
config.SetPointScaleFactor(0)
CalculateLayout(root, Undefined, Undefined, DirectionRTL)
assertFloatEqual(t, 10.2, rootChild0.LayoutGetWidth())
assertFloatEqual(t, 10.2, rootChild0.LayoutGetHeight())
config.SetPointScaleFactor(1)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
assertFloatEqual(t, 11, rootChild0.LayoutGetWidth())
assertFloatEqual(t, 11, rootChild0.LayoutGetHeight())
config.SetPointScaleFactor(2)
CalculateLayout(root, Undefined, Undefined, DirectionRTL)
assertFloatEqual(t, 10.5, rootChild0.LayoutGetWidth())
assertFloatEqual(t, 10.5, rootChild0.LayoutGetHeight())
config.SetPointScaleFactor(4)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
assertFloatEqual(t, 10.25, rootChild0.LayoutGetWidth())
assertFloatEqual(t, 10.25, rootChild0.LayoutGetHeight())
config.SetPointScaleFactor(float32(1) / float32(3))
CalculateLayout(root, Undefined, Undefined, DirectionRTL)
assertFloatEqual(t, 12.0, rootChild0.LayoutGetWidth())
assertFloatEqual(t, 12.0, rootChild0.LayoutGetHeight())
}
func TestRounding_feature_with_custom_measure_func_ceil(t *testing.T) {
config := NewConfig()
root := NewNodeWithConfig(config)
rootChild0 := NewNodeWithConfig(config)
rootChild0.SetMeasureFunc(_measureCeil)
root.InsertChild(rootChild0, 0)
config.SetPointScaleFactor(1)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
assertFloatEqual(t, 11, rootChild0.LayoutGetWidth())
assertFloatEqual(t, 11, rootChild0.LayoutGetHeight())
}
func TestRounding_feature_with_custom_measure_and_fractial_matching_scale(t *testing.T) {
config := NewConfig()
root := NewNodeWithConfig(config)
rootChild0 := NewNodeWithConfig(config)
rootChild0.StyleSetPosition(EdgeLeft, 73.625)
rootChild0.SetMeasureFunc(_measureFractial)
root.InsertChild(rootChild0, 0)
config.SetPointScaleFactor(2)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
assertFloatEqual(t, 0.5, rootChild0.LayoutGetWidth())
assertFloatEqual(t, 0.5, rootChild0.LayoutGetHeight())
assertFloatEqual(t, 73.5, rootChild0.LayoutGetLeft())
}