v / vlib / sync / channel_1_test.v
23 lines · 20 sloc · 395 bytes · f09826e928f9612bab9299faefff7cf34a503362
Raw
1const num_iterations = 10000
2
3fn do_send(ch chan int) {
4 for i in 0 .. num_iterations {
5 ch <- i
6 }
7}
8
9fn test_channel_buffered() {
10 ch := chan int{cap: 1000}
11 spawn do_send(ch)
12 mut sum := i64(0)
13 for _ in 0 .. num_iterations {
14 sum += <-ch
15 }
16 assert sum == u64(num_iterations) * (num_iterations - 1) / 2
17}
18
19fn test_builtin_enum() {
20 x := ChanState.closed
21 assert x == .closed
22 println(x)
23}
24