Решение на упр.07 задача 1 от Васил Петков
Резултати
- 4 точки от тестове
- 0 бонус точки
- 4 точки общо
- 0 успешни тест(а)
- 0 неуспешни тест(а)
Код
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_total_seats() {
let cin = Cinema::new(5);
assert_eq!(cin.total_seats(), 5);
let cin = Cinema::new(12);
assert_eq!(cin.total_seats(), 12);
let cin = Cinema::new(20);
assert_eq!(cin.total_seats(), 20);
let cin = Cinema::new(150);
assert_eq!(cin.total_seats(), 150);
let cin = Cinema::new(0);
assert_eq!(cin.total_seats(), 0);
}
#[test]
fn test_reserve() {
let mut cin = Cinema::new(5);
assert_eq!(cin.reserve(0), Ok(()));
assert_eq!(cin.reserve(0), Err(BookingError::AlreadyReserved));
assert!(cin.seats[0]);
assert_eq!(cin.reserve(5), Err(BookingError::InvalidSeat));
assert_eq!(cin.reserve(3), Ok(()));
assert_eq!(cin.reserve(2), Ok(()));
}
#[test]
fn test_is_available() {
let mut cin = Cinema::new(15);
assert_eq!(cin.is_available(0), Ok(true));
assert_eq!(cin.is_available(5), Ok(true));
assert_eq!(cin.is_available(14), Ok(true));
assert_eq!(cin.is_available(15), Err(BookingError::InvalidSeat));
_ = cin.reserve(0);
assert_eq!(cin.is_available(0), Ok(false));
}
#[test]
fn test_cancel() {
let mut cin = Cinema::new(20);
_ = cin.reserve(0);
_ = cin.reserve(5);
_ = cin.reserve(10);
_ = cin.reserve(15);
assert_eq!(cin.cancel(1), Err(BookingError::NotReserved));
assert_eq!(cin.cancel(0), Ok(()));
assert_eq!(cin.cancel(0), Err(BookingError::NotReserved));
assert_eq!(cin.cancel(20), Err(BookingError::InvalidSeat));
assert_eq!(cin.cancel(5), Ok(()));
assert_eq!(cin.cancel(5), Err(BookingError::NotReserved));
assert!(!cin.seats[5]);
}
#[test]
fn test_available_seats() {
let mut cin = Cinema::new(30);
assert_eq!(cin.available_seats(), 30);
for seat in 0..12 {
_ = cin.reserve(seat);
}
assert_eq!(cin.available_seats(), 18);
_ = cin.reserve(25);
_ = cin.reserve(20);
assert_eq!(cin.available_seats(), 16);
_ = cin.reserve(19);
assert_eq!(cin.available_seats(), 15);
for seat in 0..30 {
_ = cin.reserve(seat);
}
assert_eq!(cin.available_seats(), 0);
}
#[test]
fn test_reserve_group() {
let mut cin = Cinema::new(30);
assert_eq!(cin.reserve_group(0, 0), Err(BookingError::EmptyGroup));
assert_eq!(cin.reserve_group(0, 12), Ok(()));
assert_eq!(cin.cancel(11), Ok(()));
_ = cin.reserve(20);
assert_eq!(
cin.reserve_group(12, 10),
Err(BookingError::AlreadyReserved)
);
assert_eq!(cin.available_seats(), 18);
assert_eq!(cin.reserve_group(29, 1), Ok(()));
}
}
Лог от изпълнението
Compiling solution v0.1.0 (/tmp/d20261126-2321049-9b3x1g/solution) warning: unused import: `super::*` --> src/lib.rs:4:9 | 4 | use super::*; | ^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default error[E0433]: failed to resolve: use of undeclared type `Cinema` --> src/lib.rs:8:19 | 8 | let cin = Cinema::new(5); | ^^^^^^ use of undeclared type `Cinema` error[E0433]: failed to resolve: use of undeclared type `Cinema` --> src/lib.rs:10:19 | 10 | let cin = Cinema::new(12); | ^^^^^^ use of undeclared type `Cinema` error[E0433]: failed to resolve: use of undeclared type `Cinema` --> src/lib.rs:12:19 | 12 | let cin = Cinema::new(20); | ^^^^^^ use of undeclared type `Cinema` error[E0433]: failed to resolve: use of undeclared type `Cinema` --> src/lib.rs:14:19 | 14 | let cin = Cinema::new(150); | ^^^^^^ use of undeclared type `Cinema` error[E0433]: failed to resolve: use of undeclared type `Cinema` --> src/lib.rs:16:19 | 16 | let cin = Cinema::new(0); | ^^^^^^ use of undeclared type `Cinema` error[E0433]: failed to resolve: use of undeclared type `Cinema` --> src/lib.rs:22:23 | 22 | let mut cin = Cinema::new(5); | ^^^^^^ use of undeclared type `Cinema` error[E0433]: failed to resolve: use of undeclared type `BookingError` --> src/lib.rs:24:40 | 24 | assert_eq!(cin.reserve(0), Err(BookingError::AlreadyReserved)); | ^^^^^^^^^^^^ use of undeclared type `BookingError` error[E0433]: failed to resolve: use of undeclared type `BookingError` --> src/lib.rs:26:40 | 26 | assert_eq!(cin.reserve(5), Err(BookingError::InvalidSeat)); | ^^^^^^^^^^^^ use of undeclared type `BookingError` error[E0433]: failed to resolve: use of undeclared type `Cinema` --> src/lib.rs:33:23 | 33 | let mut cin = Cinema::new(15); | ^^^^^^ use of undeclared type `Cinema` error[E0433]: failed to resolve: use of undeclared type `BookingError` --> src/lib.rs:37:46 | 37 | assert_eq!(cin.is_available(15), Err(BookingError::InvalidSeat)); | ^^^^^^^^^^^^ use of undeclared type `BookingError` error[E0433]: failed to resolve: use of undeclared type `Cinema` --> src/lib.rs:45:23 | 45 | let mut cin = Cinema::new(20); | ^^^^^^ use of undeclared type `Cinema` error[E0433]: failed to resolve: use of undeclared type `BookingError` --> src/lib.rs:50:39 | 50 | assert_eq!(cin.cancel(1), Err(BookingError::NotReserved)); | ^^^^^^^^^^^^ use of undeclared type `BookingError` error[E0433]: failed to resolve: use of undeclared type `BookingError` --> src/lib.rs:52:39 | 52 | assert_eq!(cin.cancel(0), Err(BookingError::NotReserved)); | ^^^^^^^^^^^^ use of undeclared type `BookingError` error[E0433]: failed to resolve: use of undeclared type `BookingError` --> src/lib.rs:53:40 | 53 | assert_eq!(cin.cancel(20), Err(BookingError::InvalidSeat)); | ^^^^^^^^^^^^ use of undeclared type `BookingError` error[E0433]: failed to resolve: use of undeclared type `BookingError` --> src/lib.rs:55:39 | 55 | assert_eq!(cin.cancel(5), Err(BookingError::NotReserved)); | ^^^^^^^^^^^^ use of undeclared type `BookingError` error[E0433]: failed to resolve: use of undeclared type `Cinema` --> src/lib.rs:61:23 | 61 | let mut cin = Cinema::new(30); | ^^^^^^ use of undeclared type `Cinema` error[E0433]: failed to resolve: use of undeclared type `Cinema` --> src/lib.rs:81:23 | 81 | let mut cin = Cinema::new(30); | ^^^^^^ use of undeclared type `Cinema` error[E0433]: failed to resolve: use of undeclared type `BookingError` --> src/lib.rs:82:49 | 82 | assert_eq!(cin.reserve_group(0, 0), Err(BookingError::EmptyGroup)); | ^^^^^^^^^^^^ use of undeclared type `BookingError` error[E0433]: failed to resolve: use of undeclared type `BookingError` --> src/lib.rs:88:17 | 88 | Err(BookingError::AlreadyReserved) | ^^^^^^^^^^^^ use of undeclared type `BookingError` For more information about this error, try `rustc --explain E0433`. warning: `solution` (lib test) generated 1 warning error: could not compile `solution` (lib test) due to 19 previous errors; 1 warning emitted
