Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package ua.nure.rozdaybeda.Practice6.part3;
- ////
- //////import static org.junit.jupiter.api.Assertions.*;
- ////////
- //////////import java.util.Arrays;
- ////////////
- //////////////import org.junit.jupiter.api.Test;
- ////////////////
- //////////////////public class ParkingTest {
- //////////////////// @Test
- ////////////////////// public void ParkingConstructorTest(){
- //////////////////////// new Parking(1);
- ////////////////////////// new Parking(0);
- //////////////////////////// assertThrows(java.lang.NegativeArraySizeException.class, () -> new Parking(-1));
- ////////////////////////////// }
- //////////////////////////////// @Test
- ////////////////////////////////// public void totalParkingTest1(){
- //////////////////////////////////// Parking p = new Parking(1);
- ////////////////////////////////////// assertEquals("[0]", p.toString());
- //////////////////////////////////////// }
- //////////////////////////////////////////
- //////////////////////////////////////////// public synchronized int park(int place) {
- ////////////////////////////////////////////// if(place < 1 || place > parking.length)
- //////////////////////////////////////////////// throw new IndexOutOfBoundsException("There is no such place");
- //////////////////////////////////////////////////
- //////////////////////////////////////////////////// for(int parkPlace = place - 1; parkPlace < parking.length; parkPlace++)
- ////////////////////////////////////////////////////// if(parking[parkPlace] == 0) {
- //////////////////////////////////////////////////////// parking[parkPlace] = 1;
- ////////////////////////////////////////////////////////// return parkPlace + 1;
- //////////////////////////////////////////////////////////// }
- ////////////////////////////////////////////////////////////// return -1;
- //////////////////////////////////////////////////////////////// }
- //////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////// /**
- ////////////////////////////////////////////////////////////////////// * leaves the car from the parking
- //////////////////////////////////////////////////////////////////////// * @param place leave the car at this place
- ////////////////////////////////////////////////////////////////////////// * @return true if there was car or false if there wasnt car
- //////////////////////////////////////////////////////////////////////////// */
- ////////////////////////////////////////////////////////////////////////////// public boolean leave(int place) {
- //////////////////////////////////////////////////////////////////////////////// if(place < 1 || place > parking.length)
- ////////////////////////////////////////////////////////////////////////////////// throw new IndexOutOfBoundsException("There is no such place");
- //////////////////////////////////////////////////////////////////////////////////// if(parking[place] == 0)
- ////////////////////////////////////////////////////////////////////////////////////// return false;
- //////////////////////////////////////////////////////////////////////////////////////// parking[place] = 0;
- ////////////////////////////////////////////////////////////////////////////////////////// return true;
- //////////////////////////////////////////////////////////////////////////////////////////// }
- //////////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////// @Override
- ////////////////////////////////////////////////////////////////////////////////////////////////// public String toString() {
- //////////////////////////////////////////////////////////////////////////////////////////////////// return Arrays.toString(parking);
- ////////////////////////////////////////////////////////////////////////////////////////////////////// }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement