v2 / vlib / v / tests / aliases / alias_array_operator_overloading_test.v
19 lines · 16 sloc · 369 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1type Tuple = []f64
2
3fn new_tuple(x f64, y f64, z f64, w f64) Tuple {
4 return Tuple([x, y, z, w])
5}
6
7fn (a Tuple) + (b Tuple) Tuple {
8 mut res := []f64{len: a.len}
9 for i := 0; i < a.len; i++ {
10 res[i] = a[i] + b[i]
11 }
12 return Tuple(res)
13}
14
15fn test_tuple_arithmetic() {
16 a := new_tuple(3, -2, 5, 1)
17 b := new_tuple(-2, 3, 1, 0)
18 assert a + b == new_tuple(1, 1, 6, 1)
19}
20