2020-08-06 15:28:19 +02:00
|
|
|
const (
|
|
|
|
num_iterations = 10000
|
|
|
|
)
|
|
|
|
|
2020-08-31 10:44:39 +02:00
|
|
|
fn do_send(ch chan int) {
|
2020-08-06 15:28:19 +02:00
|
|
|
for i in 0 .. num_iterations {
|
2020-08-31 10:44:39 +02:00
|
|
|
ch <- i
|
2020-08-06 15:28:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_channel_buffered() {
|
2020-08-31 10:44:39 +02:00
|
|
|
ch := chan int{cap: 1000}
|
|
|
|
go do_send(ch)
|
2020-08-06 15:28:19 +02:00
|
|
|
mut sum := i64(0)
|
|
|
|
for _ in 0 .. num_iterations {
|
2020-08-31 10:44:39 +02:00
|
|
|
sum += <-ch
|
2020-08-06 15:28:19 +02:00
|
|
|
}
|
2021-05-08 12:32:29 +02:00
|
|
|
assert sum == u64(num_iterations) * (num_iterations - 1) / 2
|
2020-08-06 15:28:19 +02:00
|
|
|
}
|
2021-05-20 02:14:27 +02:00
|
|
|
|
|
|
|
fn test_builtin_enum() {
|
|
|
|
x := ChanState.closed
|
|
|
|
assert x == .closed
|
|
|
|
println(x)
|
|
|
|
}
|