initial commit
This commit is contained in:
4
exercises/07_threads/02_static/Cargo.toml
Normal file
4
exercises/07_threads/02_static/Cargo.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[package]
|
||||
name = "static"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
43
exercises/07_threads/02_static/src/lib.rs
Normal file
43
exercises/07_threads/02_static/src/lib.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
// TODO: Given a static slice of integers, split the slice into two halves and
|
||||
// sum each half in a separate thread.
|
||||
// Do not allocate any additional memory!
|
||||
use std::thread;
|
||||
|
||||
pub fn sum(slice: &'static [i32]) -> i32 {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
static ARRAY: [i32; 0] = [];
|
||||
assert_eq!(sum(&ARRAY), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one() {
|
||||
static ARRAY: [i32; 1] = [1];
|
||||
assert_eq!(sum(&ARRAY), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn five() {
|
||||
static ARRAY: [i32; 5] = [1, 2, 3, 4, 5];
|
||||
assert_eq!(sum(&ARRAY), 15);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nine() {
|
||||
static ARRAY: [i32; 9] = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
assert_eq!(sum(&ARRAY), 45);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ten() {
|
||||
static ARRAY: [i32; 10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
assert_eq!(sum(&ARRAY), 55);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user