Решение на упр.07 задача 1 от Надя Йотова
Резултати
- 4 точки от тестове
- 0 бонус точки
- 4 точки общо
- 0 успешни тест(а)
- 0 неуспешни тест(а)
Код
#[cfg(test)]
mod tests {
#[test]
fn reserve_and_cancel() {
let mut cinema = super::Cinema::new(1);
assert_eq!(cinema.total_seats(), 1);
assert_eq!(cinema.available_seats(), 1);
assert_eq!(cinema.reserve(0), Ok(()));
assert_eq!(cinema.reserve(0), Err(super::BookingError::AlreadyReserved));
assert_eq!(cinema.is_available(0), Ok(false));
assert_eq!(cinema.available_seats(), 0);
assert_eq!(cinema.cancel(0), Ok(()));
assert_eq!(cinema.is_available(0), Ok(true));
assert_eq!(cinema.available_seats(), 1);
}
#[test]
fn invalid_seat_in_empty_cinema() {
let mut cinema = super::Cinema::new(0);
assert_eq!(cinema.total_seats(), 0);
assert_eq!(cinema.reserve(0), Err(super::BookingError::InvalidSeat));
assert_eq!(cinema.cancel(0), Err(super::BookingError::InvalidSeat));
assert_eq!(cinema.available_seats(), 0);
assert_eq!(cinema.is_available(0), Err(super::BookingError::InvalidSeat));
}
#[test]
fn cancel_free_seat() {
let mut cinema = super::Cinema::new(1);
let result = cinema.cancel(0);
assert_eq!(cinema.available_seats(), 1);
assert_eq!(cinema.is_available(0), Ok(true));
assert_eq!(result, Err(super::BookingError::NotReserved));
}
#[test]
fn reserve_group() {
let mut cinema = super::Cinema::new(3);
assert_eq!(cinema.reserve_group(1, 2), Ok(()));
assert_eq!(cinema.available_seats(), 1);
assert_eq!(cinema.is_available(0), Ok(true));
assert_eq!(cinema.is_available(1), Ok(false));
assert_eq!(cinema.is_available(2), Ok(false));
}
#[test]
fn invalid_groups() {
let mut cinema = super::Cinema::new(2);
assert_eq!(cinema.reserve_group(0, 0), Err(super::BookingError::EmptyGroup));
assert_eq!(cinema.available_seats(), 2);
assert_eq!(cinema.reserve_group(1, 2), Err(super::BookingError::InvalidSeat));
assert_eq!(cinema.available_seats(), 2);
}
#[test]
fn group_conflict_leaves_seats_unchanged() {
let mut cinema = super::Cinema::new(2);
assert_eq!(cinema.reserve(1), Ok(()));
assert_eq!(
cinema.reserve_group(0, 2),
Err(super::BookingError::AlreadyReserved)
);
assert_eq!(cinema.is_available(0), Ok(true));
assert_eq!(cinema.is_available(1), Ok(false));
assert_eq!(cinema.available_seats(), 1);
}
}
Лог от изпълнението
Compiling solution v0.1.0 (/tmp/d20261126-2321049-tyen3q/solution) error[E0433]: failed to resolve: could not find `Cinema` in the crate root --> src/lib.rs:5:33 | 5 | let mut cinema = super::Cinema::new(1); | ^^^^^^ could not find `Cinema` in the crate root error[E0433]: failed to resolve: could not find `BookingError` in the crate root --> src/lib.rs:10:50 | 10 | assert_eq!(cinema.reserve(0), Err(super::BookingError::AlreadyReserved)); | ^^^^^^^^^^^^ could not find `BookingError` in the crate root error[E0433]: failed to resolve: could not find `Cinema` in the crate root --> src/lib.rs:21:33 | 21 | let mut cinema = super::Cinema::new(0); | ^^^^^^ could not find `Cinema` in the crate root error[E0433]: failed to resolve: could not find `BookingError` in the crate root --> src/lib.rs:24:50 | 24 | assert_eq!(cinema.reserve(0), Err(super::BookingError::InvalidSeat)); | ^^^^^^^^^^^^ could not find `BookingError` in the crate root error[E0433]: failed to resolve: could not find `BookingError` in the crate root --> src/lib.rs:25:49 | 25 | assert_eq!(cinema.cancel(0), Err(super::BookingError::InvalidSeat)); | ^^^^^^^^^^^^ could not find `BookingError` in the crate root error[E0433]: failed to resolve: could not find `BookingError` in the crate root --> src/lib.rs:27:55 | 27 | assert_eq!(cinema.is_available(0), Err(super::BookingError::InvalidSeat)); | ^^^^^^^^^^^^ could not find `BookingError` in the crate root error[E0433]: failed to resolve: could not find `Cinema` in the crate root --> src/lib.rs:32:33 | 32 | let mut cinema = super::Cinema::new(1); | ^^^^^^ could not find `Cinema` in the crate root error[E0433]: failed to resolve: could not find `BookingError` in the crate root --> src/lib.rs:37:39 | 37 | assert_eq!(result, Err(super::BookingError::NotReserved)); | ^^^^^^^^^^^^ could not find `BookingError` in the crate root error[E0433]: failed to resolve: could not find `Cinema` in the crate root --> src/lib.rs:42:33 | 42 | let mut cinema = super::Cinema::new(3); | ^^^^^^ could not find `Cinema` in the crate root error[E0433]: failed to resolve: could not find `Cinema` in the crate root --> src/lib.rs:53:33 | 53 | let mut cinema = super::Cinema::new(2); | ^^^^^^ could not find `Cinema` in the crate root error[E0433]: failed to resolve: could not find `BookingError` in the crate root --> src/lib.rs:55:59 | 55 | assert_eq!(cinema.reserve_group(0, 0), Err(super::BookingError::EmptyGroup)); | ^^^^^^^^^^^^ could not find `BookingError` in the crate root error[E0433]: failed to resolve: could not find `BookingError` in the crate root --> src/lib.rs:57:59 | 57 | assert_eq!(cinema.reserve_group(1, 2), Err(super::BookingError::InvalidSeat)); | ^^^^^^^^^^^^ could not find `BookingError` in the crate root error[E0433]: failed to resolve: could not find `Cinema` in the crate root --> src/lib.rs:63:33 | 63 | let mut cinema = super::Cinema::new(2); | ^^^^^^ could not find `Cinema` in the crate root error[E0433]: failed to resolve: could not find `BookingError` in the crate root --> src/lib.rs:68:24 | 68 | Err(super::BookingError::AlreadyReserved) | ^^^^^^^^^^^^ could not find `BookingError` in the crate root For more information about this error, try `rustc --explain E0433`. error: could not compile `solution` (lib test) due to 14 previous errors
