mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Updated/added test cases.
This commit is contained in:
parent
bd7835effa
commit
d647c163fd
5
src/test/run-pass/arith-0.rs
Normal file
5
src/test/run-pass/arith-0.rs
Normal file
@ -0,0 +1,5 @@
|
||||
fn main() -> () {
|
||||
let int a = 10;
|
||||
log a;
|
||||
check (a * (a - 1) == 90);
|
||||
}
|
22
src/test/run-pass/arith-1.rs
Normal file
22
src/test/run-pass/arith-1.rs
Normal file
@ -0,0 +1,22 @@
|
||||
fn main() -> () {
|
||||
let int i32_a = 10;
|
||||
check(i32_a == 10);
|
||||
check(i32_a - 10 == 0);
|
||||
check(i32_a / 10 == 1);
|
||||
check(i32_a - 20 == -10);
|
||||
check(i32_a << 10 == 10240);
|
||||
check(i32_a << 16 == 655360);
|
||||
check(i32_a * 16 == 160);
|
||||
check(i32_a * i32_a * i32_a == 1000);
|
||||
check(i32_a * i32_a * i32_a * i32_a == 10000);
|
||||
check(((i32_a * i32_a) / i32_a) * i32_a == 100);
|
||||
check(i32_a * (i32_a - 1) << 2 + i32_a == 368640);
|
||||
|
||||
let int i32_b = 0x10101010;
|
||||
check(i32_b + 1 - 1 == i32_b);
|
||||
check(i32_b << 1 == i32_b << 1);
|
||||
check(i32_b >> 1 == i32_b >> 1);
|
||||
check((i32_b & (i32_b << 1)) == 0);
|
||||
log ((i32_b | (i32_b << 1)));
|
||||
check((i32_b | (i32_b << 1)) == 0x30303030);
|
||||
}
|
5
src/test/run-pass/arith-2.rs
Normal file
5
src/test/run-pass/arith-2.rs
Normal file
@ -0,0 +1,5 @@
|
||||
fn main() -> () {
|
||||
let int i32_c = 0x10101010;
|
||||
check (i32_c + i32_c * 2 / 3 * 2 + (i32_c - 7 % 3) ==
|
||||
i32_c + (((i32_c * 2) / 3) * 2) + (i32_c - (7 % 3)));
|
||||
}
|
25
src/test/run-pass/basic-1.rs
Normal file
25
src/test/run-pass/basic-1.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// -*- rust -*-
|
||||
|
||||
io fn a(chan[int] c) {
|
||||
c <| 10;
|
||||
}
|
||||
|
||||
io fn main() {
|
||||
let port[int] p = port();
|
||||
spawn a(chan(p));
|
||||
spawn b(chan(p));
|
||||
let int n = 0;
|
||||
n <- p;
|
||||
n <- p;
|
||||
// log "Finished.";
|
||||
}
|
||||
|
||||
io fn b(chan[int] c) {
|
||||
// log "task b0";
|
||||
// log "task b1";
|
||||
// log "task b2";
|
||||
// log "task b3";
|
||||
// log "task b4";
|
||||
// log "task b5";
|
||||
c <| 10;
|
||||
}
|
26
src/test/run-pass/basic-2.rs
Normal file
26
src/test/run-pass/basic-2.rs
Normal file
@ -0,0 +1,26 @@
|
||||
// -*- rust -*-
|
||||
|
||||
io fn a(chan[int] c) {
|
||||
log "task a0";
|
||||
log "task a1";
|
||||
c <| 10;
|
||||
}
|
||||
|
||||
io fn main() {
|
||||
let port[int] p = port();
|
||||
spawn a(chan(p));
|
||||
spawn b(chan(p));
|
||||
let int n = 0;
|
||||
n <- p;
|
||||
n <- p;
|
||||
log "Finished.";
|
||||
}
|
||||
|
||||
io fn b(chan[int] c) {
|
||||
log "task b0";
|
||||
log "task b1";
|
||||
log "task b2";
|
||||
log "task b2";
|
||||
log "task b3";
|
||||
c <| 10;
|
||||
}
|
@ -15,5 +15,5 @@ io fn test05() {
|
||||
let int value <- po;
|
||||
value <- po;
|
||||
value <- po;
|
||||
log value;
|
||||
check(value == 30);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
fn main() -> () {
|
||||
log "===== THREADS =====";
|
||||
log "===== SPAWNING and JOINING TASKS =====";
|
||||
test00(false);
|
||||
log "===== SPAWNING and JOINING THREAD TASKS =====";
|
||||
test00(true);
|
||||
log "====== TASKS ======";
|
||||
// test00(false);
|
||||
}
|
||||
|
||||
fn start(int task_number) {
|
||||
@ -15,7 +15,7 @@ fn start(int task_number) {
|
||||
}
|
||||
|
||||
fn test00(bool create_threads) {
|
||||
let int number_of_tasks = 0;
|
||||
let int number_of_tasks = 8;
|
||||
|
||||
let int i = 0;
|
||||
let vec[task] tasks = vec();
|
||||
|
@ -1,6 +1,8 @@
|
||||
io fn main() -> () {
|
||||
log "===== THREADS =====";
|
||||
log "===== WITHOUT THREADS =====";
|
||||
test00(false);
|
||||
log "====== WITH THREADS ======";
|
||||
test00(true);
|
||||
}
|
||||
|
||||
io fn test00_start(chan[int] ch, int message, int count) {
|
||||
@ -15,8 +17,9 @@ io fn test00_start(chan[int] ch, int message, int count) {
|
||||
}
|
||||
|
||||
io fn test00(bool is_multithreaded) {
|
||||
let int number_of_tasks = 1;
|
||||
let int number_of_messages = 0;
|
||||
let int number_of_tasks = 16;
|
||||
let int number_of_messages = 4;
|
||||
|
||||
log "Creating tasks";
|
||||
|
||||
let port[int] po = port();
|
||||
@ -27,13 +30,13 @@ io fn test00(bool is_multithreaded) {
|
||||
// Create and spawn tasks...
|
||||
let vec[task] tasks = vec();
|
||||
while (i < number_of_tasks) {
|
||||
i = i + 1;
|
||||
if (is_multithreaded) {
|
||||
tasks += vec(
|
||||
spawn thread test00_start(ch, i, number_of_messages));
|
||||
} else {
|
||||
tasks += vec(spawn test00_start(ch, i, number_of_messages));
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
// Read from spawned tasks...
|
||||
@ -53,7 +56,7 @@ io fn test00(bool is_multithreaded) {
|
||||
}
|
||||
|
||||
log "Completed: Final number is: ";
|
||||
check (sum + 1 == number_of_messages *
|
||||
(number_of_tasks * number_of_tasks + number_of_tasks) / 2);
|
||||
log sum;
|
||||
// check (sum == (((number_of_tasks * (number_of_tasks - 1)) / 2) *
|
||||
// number_of_messages));
|
||||
check (sum == 480);
|
||||
}
|
@ -32,5 +32,7 @@ io fn test00() {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
check (sum == 4 * ((number_of_messages * (number_of_messages - 1)) / 2));
|
||||
check (sum == 1998000);
|
||||
// check (sum == 4 * ((number_of_messages *
|
||||
// (number_of_messages - 1)) / 2));
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
|
||||
fn main() -> () {
|
||||
// test00(true);
|
||||
io fn main() -> () {
|
||||
test00(true);
|
||||
// test01();
|
||||
// test02();
|
||||
// test03();
|
||||
// test04();
|
||||
// test05();
|
||||
test02();
|
||||
test03();
|
||||
test04();
|
||||
test05();
|
||||
test06();
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ io fn test00_start(chan[int] ch, int message, int count) {
|
||||
|
||||
io fn test00(bool is_multithreaded) {
|
||||
let int number_of_tasks = 1;
|
||||
let int number_of_messages = 64;
|
||||
let int number_of_messages = 4;
|
||||
log "Creating tasks";
|
||||
|
||||
let port[int] po = port();
|
||||
@ -103,7 +103,7 @@ fn test04_start() {
|
||||
|
||||
fn test04() {
|
||||
log "Spawning lots of tasks.";
|
||||
let int i = 64;
|
||||
let int i = 4;
|
||||
while (i > 0) {
|
||||
i = i - 1;
|
||||
spawn thread test04_start();
|
||||
@ -139,7 +139,7 @@ fn test06_start(int task_number) {
|
||||
}
|
||||
|
||||
fn test06() {
|
||||
let int number_of_tasks = 32;
|
||||
let int number_of_tasks = 4;
|
||||
log "Creating tasks";
|
||||
|
||||
let int i = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user