mirror of
https://github.com/kmc7468/cs220.git
synced 2025-12-12 21:08:45 +00:00
Merge branch 'main' into 'main'
minor format & typo fixes See merge request kaist-cp-class/cs220-private!16
This commit is contained in:
@@ -24,7 +24,7 @@ run_linters || exit 1
|
||||
for RUNNER in "${RUNNERS[@]}"; do
|
||||
echo "Running with $RUNNER..."
|
||||
|
||||
TESTS=("--lib assignment11_grade")
|
||||
TESTS=("--lib assignment11")
|
||||
if [ $(run_tests) -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::assignments::assignment04::syntax::*;
|
||||
|
||||
use super::super::assignment04::*;
|
||||
use crate::assignments::assignment04::*;
|
||||
|
||||
#[test]
|
||||
fn test_parse() {
|
||||
@@ -16,5 +16,6 @@
|
||||
//! Run `/scripts/prepare-submissions.sh` and submit `/target/assignment04.zip` to <https://gg.kaist.ac.kr>.
|
||||
|
||||
pub mod context;
|
||||
mod grade;
|
||||
pub mod parser;
|
||||
pub mod syntax;
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
#[test]
|
||||
fn test_tv_room() {
|
||||
use crate::assignments::assignment11::tv_room::*;
|
||||
|
||||
let tv_room = TVRoom::new();
|
||||
assert!(!tv_room.is_opened());
|
||||
|
||||
// Turn on and add new guests.
|
||||
let manager = tv_room.open().unwrap();
|
||||
assert!(tv_room.is_opened());
|
||||
let guest1 = manager.new_guest();
|
||||
let guest2 = manager.new_guest();
|
||||
drop(manager);
|
||||
drop(guest1);
|
||||
assert!(tv_room.open().is_none());
|
||||
drop(guest2);
|
||||
assert!(!tv_room.is_opened());
|
||||
|
||||
// Turn on and add new guests.
|
||||
let manager = tv_room.open().unwrap();
|
||||
assert!(tv_room.is_opened());
|
||||
let guest3 = manager.new_guest();
|
||||
drop(guest3);
|
||||
assert!(tv_room.is_opened());
|
||||
drop(manager);
|
||||
assert!(!tv_room.is_opened());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mock_storage() {
|
||||
use crate::assignments::assignment11::mock_storage::*;
|
||||
|
||||
let mock_storage = MockStorage::new(100);
|
||||
|
||||
let uploader1 = FileUploader::new(&mock_storage);
|
||||
let uploader2 = FileUploader::new(&mock_storage);
|
||||
|
||||
let usage_analyzer = UsageAnalyzer::new(&mock_storage, 0.75);
|
||||
|
||||
assert!(uploader1.upload("file1.txt", 20).is_ok());
|
||||
assert!(usage_analyzer.is_usage_under_bound());
|
||||
|
||||
assert!(uploader2.upload("file2.txt", 30).is_ok());
|
||||
assert!(usage_analyzer.is_usage_under_bound());
|
||||
|
||||
assert!(uploader1.upload("file3.txt", 40).is_ok());
|
||||
assert!(!usage_analyzer.is_usage_under_bound());
|
||||
|
||||
assert_eq!(uploader2.upload("file4.txt", 50), Err(40));
|
||||
assert!(!usage_analyzer.is_usage_under_bound());
|
||||
|
||||
assert!(uploader1.upload("file3.txt", 10).is_ok());
|
||||
assert!(usage_analyzer.is_usage_under_bound());
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
struct V(usize);
|
||||
|
||||
#[test]
|
||||
fn test_linked_list() {
|
||||
use crate::assignments::assignment11::linked_list::*;
|
||||
|
||||
let mut list = SinglyLinkedList::new();
|
||||
list.push_back(V(3));
|
||||
list.push_front(V(2));
|
||||
list.push_back(V(4));
|
||||
list.push_front(V(1));
|
||||
list.push_back(V(5));
|
||||
|
||||
assert_eq!(list.pop_front(), Some(V(1)));
|
||||
assert_eq!(list.pop_back(), Some(V(5)));
|
||||
assert_eq!(list.pop_front(), Some(V(2)));
|
||||
assert_eq!(list.pop_back(), Some(V(4)));
|
||||
assert_eq!(list.pop_front(), Some(V(3)));
|
||||
assert_eq!(list.pop_back(), None);
|
||||
assert_eq!(list.pop_front(), None);
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@
|
||||
//! See `assignment12_grade.rs` and `/scripts/grade-12.sh` for the test script.
|
||||
|
||||
pub mod card;
|
||||
pub mod card_grade;
|
||||
mod card_grade;
|
||||
pub mod demux;
|
||||
pub mod demux_grade;
|
||||
mod demux_grade;
|
||||
pub mod funnel;
|
||||
pub mod funnel_grade;
|
||||
mod funnel_grade;
|
||||
pub mod small_exercises;
|
||||
pub mod small_exercises_grade;
|
||||
mod small_exercises_grade;
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::super::assignment12::*;
|
||||
use ntest::timeout;
|
||||
|
||||
use std::sync::mpsc::channel;
|
||||
use std::thread;
|
||||
|
||||
#[test]
|
||||
fn test_ping_pong() {
|
||||
let (tx1, mut rx1) = channel();
|
||||
let (mut tx2, rx2) = channel();
|
||||
|
||||
let thread_ping = thread::spawn(move || {
|
||||
for i in 0..100 {
|
||||
tx1.send(i).unwrap();
|
||||
let x = rx2.recv().unwrap();
|
||||
assert_eq!(x, i + 1);
|
||||
}
|
||||
});
|
||||
|
||||
let thread_pong = thread::spawn(move || while pong(&mut rx1, &mut tx2) {});
|
||||
|
||||
thread_ping.join().unwrap();
|
||||
thread_pong.join().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scoped_thread() {
|
||||
for i in 0..100 {
|
||||
let v = (0..i).collect::<Vec<u32>>();
|
||||
|
||||
thread::scope(|s| {
|
||||
let (r1, r2) = use_scoped_thread(
|
||||
s,
|
||||
|| v.iter().sum::<u32>(),
|
||||
|| v.windows(2).map(|x| x[0] * x[1]).sum::<u32>(),
|
||||
);
|
||||
|
||||
assert_eq!(r1, v.iter().sum());
|
||||
assert_eq!(r2, v.windows(2).map(|x| x[0] * x[1]).sum());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[timeout(5000)]
|
||||
fn test_scoped_thread_concurrent() {
|
||||
use std::sync::Mutex;
|
||||
|
||||
let m = Mutex::new(0);
|
||||
let (r1, r2) = thread::scope(|s| {
|
||||
use_scoped_thread(
|
||||
s,
|
||||
|| {
|
||||
for i in 0..100 {
|
||||
loop {
|
||||
let mut a = m.lock().unwrap();
|
||||
if *a == 2 * i {
|
||||
*a += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
thread::current().id()
|
||||
},
|
||||
|| {
|
||||
for i in 0..100 {
|
||||
loop {
|
||||
let mut a = m.lock().unwrap();
|
||||
if *a == 2 * i + 1 {
|
||||
*a += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
thread::current().id()
|
||||
},
|
||||
)
|
||||
});
|
||||
|
||||
assert!(r1 != r2);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ mod assignment02_grade;
|
||||
pub mod assignment03;
|
||||
mod assignment03_grade;
|
||||
pub mod assignment04;
|
||||
mod assignment04_grade;
|
||||
pub mod assignment06;
|
||||
pub mod assignment07;
|
||||
pub mod assignment08;
|
||||
|
||||
Reference in New Issue
Block a user