initial commit

This commit is contained in:
2025-02-19 10:34:15 +05:30
commit b9cb4c290a
355 changed files with 18626 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
[package]
name = "static"
version = "0.1.0"
edition = "2021"

View 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);
}
}