| 1 | interface WalkerTalker { |
| 2 | // Abc |
| 3 | Walker // adsas |
| 4 | // zxczxc |
| 5 | Talker // xyzdef |
| 6 | // asdasdas |
| 7 | nspeeches int |
| 8 | } |
| 9 | |
| 10 | interface Talker { |
| 11 | nspeeches int |
| 12 | mut: |
| 13 | talk(msg string) |
| 14 | } |
| 15 | |
| 16 | interface Walker { |
| 17 | nsteps int |
| 18 | mut: |
| 19 | walk(newx int, newy int) |
| 20 | } |
| 21 | |
| 22 | struct Abc { |
| 23 | mut: |
| 24 | x int |
| 25 | y int |
| 26 | phrases []string |
| 27 | nsteps int = 1000 |
| 28 | nspeeches int = 1000 |
| 29 | } |
| 30 | |
| 31 | fn (mut s Abc) talk(msg string) { |
| 32 | s.phrases << msg |
| 33 | s.nspeeches++ |
| 34 | } |
| 35 | |
| 36 | fn (mut s Abc) walk(x int, y int) { |
| 37 | s.x = x |
| 38 | s.y = y |
| 39 | s.nsteps++ |
| 40 | } |
| 41 | |
| 42 | fn test_walker_talker() { |
| 43 | mut wt := WalkerTalker(Abc{ |
| 44 | x: 1 |
| 45 | y: 1 |
| 46 | phrases: ['hi'] |
| 47 | }) |
| 48 | wt.talk('my name is Wally') |
| 49 | wt.walk(100, 100) |
| 50 | if mut wt is Abc { |
| 51 | dump(wt) |
| 52 | assert wt.x == 100 |
| 53 | assert wt.y == 100 |
| 54 | assert wt.phrases.last().ends_with('Wally') |
| 55 | assert wt.nspeeches == 1001 |
| 56 | assert wt.nsteps == 1001 |
| 57 | } |
| 58 | } |
| 59 | |