mirror of
https://github.com/kmc7468/cs220.git
synced 2025-12-15 22:48:45 +00:00
Initial commit
This commit is contained in:
19
src/assignments/assignment01.rs
Normal file
19
src/assignments/assignment01.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
//! Assignment 1: Preparing for Rust Development Environment.
|
||||
//!
|
||||
//! The primary goal of this assignment is bringing up SSH, VSCode, and all the other necessary tools to develop Rust programs.
|
||||
//! Please make sure you're comfortable with developing Rust programs before moving on to the next assignments.
|
||||
//!
|
||||
//! You should fill out `add()` and `sub()` function bodies in such a way that `/scripts/grade-01.sh` works fine.
|
||||
//! See `assignment01_grade.rs` and `/scripts/grade-01.sh` for the test script.
|
||||
//!
|
||||
//! Hint: https://doc.rust-lang.org/std/primitive.usize.html
|
||||
|
||||
/// Adds two unsigned words. If overflow happens, just wrap around.
|
||||
pub(crate) fn add(lhs: usize, rhs: usize) -> usize {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Adds two unsigned words. If underflow happens, just wrap around.
|
||||
pub(crate) fn sub(lhs: usize, rhs: usize) -> usize {
|
||||
todo!()
|
||||
}
|
||||
24
src/assignments/assignment01_grade.rs
Normal file
24
src/assignments/assignment01_grade.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::super::assignment01::*;
|
||||
|
||||
#[test]
|
||||
fn add_7_3() {
|
||||
assert_eq!(add(7, 3), 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_overflow() {
|
||||
assert_eq!(add(usize::MAX, 1), usize::MIN);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sub_7_3() {
|
||||
assert_eq!(sub(7, 3), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sub_underflow() {
|
||||
assert_eq!(sub(usize::MIN, 1), usize::MAX);
|
||||
}
|
||||
}
|
||||
5
src/assignments/mod.rs
Normal file
5
src/assignments/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
mod assignment01;
|
||||
mod assignment01_grade;
|
||||
Reference in New Issue
Block a user