Решение на упр.07 задача 1 от Георги Георгиев

Обратно към всички решения

Към профила на Георги Георгиев

Резултати

  • 3 точки от тестове
  • 0 бонус точки
  • 3 точки общо
  • 0 успешни тест(а)
  • 0 неуспешни тест(а)

Код

#[test]
fn expected_behaviour_confirmed() {
let mut cinema = Cinema::new(3);
assert_eq!(cinema.total_seats(), 3);
assert_eq!(cinema.available_seats(), 3);
for seat in 0..3 {
assert_eq!(cinema.is_available(seat), Ok(true));
}
assert_eq!(cinema.reserve(1), Ok(()));
assert_eq!(cinema.available_seats(), 2);
assert_eq!(cinema.is_available(1), Ok(false));
assert_eq!(cinema.cancel(1), Ok(()));
assert_eq!(cinema.available_seats(), 3);
assert_eq!(cinema.is_available(1), Ok(true));
assert_eq!(cinema.reserve_group(0,2), Ok(()));
assert_eq!(cinema.available_seats(), 1);
assert_eq!(cinema.is_available(0), Ok(false));
assert_eq!(cinema.is_available(1), Ok(false));
}
#[test]
fn empty_cinema_correct_errmsg() {
let mut cinema = Cinema::new(0);
assert_eq!(cinema.total_seats(), 0);
assert_eq!(cinema.available_seats(), 0);
assert_eq!(cinema.reserve(0), Err(BookingError::InvalidSeat));
assert_eq!(cinema.cancel(0), Err(BookingError::InvalidSeat));
assert_eq!(cinema.reserve_group(0, 1), Err(BookingError::InvalidSeat));
}
#[test]
fn indexation_panic_is_avaliable() {
let mut cinema = Cinema::new(3);
assert_eq!(cinema.is_available(2), Ok(true));
assert_eq!(cinema.is_available(3), Err(BookingError::InvalidSeat));
assert_eq!(cinema.is_available(4), Err(BookingError::InvalidSeat));
}
#[test]
fn cancel_returns_correct_msg() {
let mut cinema = Cinema::new(3);
assert_eq!(cinema.is_available(1), Ok(true));
assert_eq!(cinema.cancel(1), Err(BookingError::NotReserved));
}
#[test]
fn reserve_full_group() {
let mut cinema = Cinema::new(3);
assert_eq!(cinema.reserve_group(0, 3), Ok(()));
assert_eq!(cinema.available_seats(), 0);
}
#[test]
fn is_grouping_atomic(){
let mut cinema = Cinema::new(5);
cinema.reserve(1).unwrap();
assert_eq!(cinema.reserve_group(0,3), Err(BookingError::AlreadyReserved));
assert_eq!(cinema.available_seats(), 4);
}

Лог от изпълнението

Compiling solution v0.1.0 (/tmp/d20261126-2321049-uwodlm/solution)
error[E0433]: failed to resolve: use of undeclared type `Cinema`
 --> src/lib.rs:3:26
  |
3 |         let mut cinema = Cinema::new(3);
  |                          ^^^^^^ use of undeclared type `Cinema`

error[E0433]: failed to resolve: use of undeclared type `Cinema`
  --> src/lib.rs:26:26
   |
26 |         let mut cinema = Cinema::new(0);
   |                          ^^^^^^ use of undeclared type `Cinema`

error[E0433]: failed to resolve: use of undeclared type `BookingError`
  --> src/lib.rs:29:43
   |
29 |         assert_eq!(cinema.reserve(0), Err(BookingError::InvalidSeat));
   |                                           ^^^^^^^^^^^^ use of undeclared type `BookingError`

error[E0433]: failed to resolve: use of undeclared type `BookingError`
  --> src/lib.rs:30:42
   |
30 |         assert_eq!(cinema.cancel(0), Err(BookingError::InvalidSeat));
   |                                          ^^^^^^^^^^^^ use of undeclared type `BookingError`

error[E0433]: failed to resolve: use of undeclared type `BookingError`
  --> src/lib.rs:31:52
   |
31 |         assert_eq!(cinema.reserve_group(0, 1), Err(BookingError::InvalidSeat));
   |                                                    ^^^^^^^^^^^^ use of undeclared type `BookingError`

error[E0433]: failed to resolve: use of undeclared type `Cinema`
  --> src/lib.rs:36:26
   |
36 |         let mut cinema = Cinema::new(3);
   |                          ^^^^^^ use of undeclared type `Cinema`

error[E0433]: failed to resolve: use of undeclared type `BookingError`
  --> src/lib.rs:38:48
   |
38 |         assert_eq!(cinema.is_available(3), Err(BookingError::InvalidSeat));
   |                                                ^^^^^^^^^^^^ use of undeclared type `BookingError`

error[E0433]: failed to resolve: use of undeclared type `BookingError`
  --> src/lib.rs:39:48
   |
39 |         assert_eq!(cinema.is_available(4), Err(BookingError::InvalidSeat));
   |                                                ^^^^^^^^^^^^ use of undeclared type `BookingError`

error[E0433]: failed to resolve: use of undeclared type `Cinema`
  --> src/lib.rs:44:26
   |
44 |         let mut cinema = Cinema::new(3);
   |                          ^^^^^^ use of undeclared type `Cinema`

error[E0433]: failed to resolve: use of undeclared type `BookingError`
  --> src/lib.rs:46:42
   |
46 |         assert_eq!(cinema.cancel(1), Err(BookingError::NotReserved));
   |                                          ^^^^^^^^^^^^ use of undeclared type `BookingError`

error[E0433]: failed to resolve: use of undeclared type `Cinema`
  --> src/lib.rs:51:26
   |
51 |         let mut cinema = Cinema::new(3);
   |                          ^^^^^^ use of undeclared type `Cinema`

error[E0433]: failed to resolve: use of undeclared type `Cinema`
  --> src/lib.rs:58:26
   |
58 |         let mut cinema = Cinema::new(5);
   |                          ^^^^^^ use of undeclared type `Cinema`

error[E0433]: failed to resolve: use of undeclared type `BookingError`
  --> src/lib.rs:61:51
   |
61 |         assert_eq!(cinema.reserve_group(0,3), Err(BookingError::AlreadyReserved));
   |                                                   ^^^^^^^^^^^^ use of undeclared type `BookingError`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `solution` (lib test) due to 13 previous errors

История (1 версия и 1 коментар)