This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_test.v
136 lines (127 loc) · 2.97 KB
/
map_test.v
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
module viter
fn test_map_string_int() ? {
data := ['1', '2', '3', '4', '5']
mut iter := iter_string(data).map_int(fn (i string) int {
return i.int() + 1
})
assert iter.next() ? == 2
assert iter.next() ? == 3
assert iter.next() ? == 4
assert iter.next() ? == 5
assert iter.next() ? == 6
if _ := iter.next() {
assert false
}
}
fn test_map_string_string() ? {
data := ['1', '2', '3', '4', '5']
mut iter := iter_string(data).map_string(fn (i string) string {
return '$i!'
})
assert iter.next() ? == '1!'
assert iter.next() ? == '2!'
assert iter.next() ? == '3!'
assert iter.next() ? == '4!'
assert iter.next() ? == '5!'
if _ := iter.next() {
assert false
}
}
fn test_map_string_bool() ? {
data := ['1', '2', '3', '4', '5']
mut iter := iter_string(data).map_bool(fn (i string) bool {
return i.int() >= 3
})
assert iter.next() ? == false
assert iter.next() ? == false
assert iter.next() ? == true
assert iter.next() ? == true
assert iter.next() ? == true
if _ := iter.next() {
assert false
}
}
fn test_map_int_string() ? {
data := [1, 2, 3, 4, 5]
mut iter := iter_int(data).map_string(fn (i int) string {
return '$i!'
})
assert iter.next() ? == '1!'
assert iter.next() ? == '2!'
assert iter.next() ? == '3!'
assert iter.next() ? == '4!'
assert iter.next() ? == '5!'
if _ := iter.next() {
assert false
}
}
fn test_map_int_int() ? {
data := [1, 2, 3, 4, 5]
mut iter := iter_int(data).map_int(fn (i int) int {
return i + 1
})
assert iter.next() ? == 2
assert iter.next() ? == 3
assert iter.next() ? == 4
assert iter.next() ? == 5
assert iter.next() ? == 6
if _ := iter.next() {
assert false
}
}
fn test_map_int_bool() ? {
data := [1, 2, 3, 4, 5]
mut iter := iter_int(data).map_bool(fn (i int) bool {
return i >= 3
})
assert iter.next() ? == false
assert iter.next() ? == false
assert iter.next() ? == true
assert iter.next() ? == true
assert iter.next() ? == true
if _ := iter.next() {
assert false
}
}
fn test_map_bool_string() ? {
data := [true, false, true, true, false]
mut iter := iter_bool(data).map_string(fn (i bool) string {
return if i { 'yay' } else { 'boo' }
})
assert iter.next() ? == 'yay'
assert iter.next() ? == 'boo'
assert iter.next() ? == 'yay'
assert iter.next() ? == 'yay'
assert iter.next() ? == 'boo'
if _ := iter.next() {
assert false
}
}
fn test_map_bool_int() ? {
data := [true, false, true, true, false]
mut iter := iter_bool(data).map_int(fn (i bool) int {
return if i { 1 } else { 0 }
})
assert iter.next() ? == 1
assert iter.next() ? == 0
assert iter.next() ? == 1
assert iter.next() ? == 1
assert iter.next() ? == 0
if _ := iter.next() {
assert false
}
}
fn test_map_bool_bool() ? {
data := [true, false, true, true, false]
mut iter := iter_bool(data).map_bool(fn (i bool) bool {
return !i
})
assert iter.next() ? == false
assert iter.next() ? == true
assert iter.next() ? == false
assert iter.next() ? == false
assert iter.next() ? == true
if _ := iter.next() {
assert false
}
}