v2 / vlib / v / tests / generics / generics_struct_inst_method_call_test.v
27 lines · 22 sloc · 478 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1fn test_generics_struct_inst_method_call() {
2 v1 := V2d[f32]{100}
3 r1 := v1.in_bounds(tp_lft, bt_rigt)
4 println(r1)
5 assert r1
6}
7
8const tp_lft = V2d[f32]{20}
9const bt_rigt = V2d[f32]{650}
10
11struct V2d[T] {
12mut:
13 x T
14}
15
16pub fn (v1 V2d[T]) unpack() T {
17 return v1.x
18}
19
20pub fn (v1 V2d[T]) less_than(v2 V2d[T]) V2d[bool] {
21 return V2d[bool]{v1.x < v2.x}
22}
23
24pub fn (v1 V2d[T]) in_bounds(top_left V2d[T], bottom_right V2d[T]) bool {
25 v1.less_than(bottom_right).unpack()
26 return true
27}
28