| 1 | type Tuple = []f64 |
| 2 | |
| 3 | fn new_tuple(x f64, y f64, z f64, w f64) Tuple { |
| 4 | return Tuple([x, y, z, w]) |
| 5 | } |
| 6 | |
| 7 | fn (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 | |
| 15 | fn 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 |