public class Elevator {
	public int MAX_HEIGHT;
	public int MIN_HEIGHT;
	public int floor;
	public Elevator(int max_height, int min_height, int basic_height) {
		// TODO Auto-generated constructor stub
		MAX_HEIGHT = max_height;
		MIN_HEIGHT = min_height;
		floor = basic_height;
	}


	public int getFloor() {
		// TODO Auto-generated method stub
		return floor;
	}

	public void goTo(int i) {
		// TODO Auto-generated method stub
		if(i <= MAX_HEIGHT && i >= MIN_HEIGHT)
		floor = i;
	}

	public String callElevator(int i) {
		// TODO Auto-generated method stub
		if(floor < i){
			goTo(i);
			return "올라갑니다";
		}else{
			goTo(i);
			return "내려갑니다";
		}
	}

	public int getMaxHeight() {
		// TODO Auto-generated method stub
		return MAX_HEIGHT;
		
	}

	public int getMinHeight() {
		// TODO Auto-generated method stub
		return MIN_HEIGHT;
		
	}
}

public class ElevatorTest {
	
	@Test
	public void createTest(){
		Elevator el = new Elevator(20, -5, 1);//최고 높이, 최저 높이, 초기높이를 받는 생성자
		assertNotNull(el);
	}
	
	@Test
	public void goToTest(){
		Elevator el = new Elevator(20, -5, 1);
		el.goTo(20);
		assertEquals(20,el.getFloor()) ;
		
		
		int temp = el.getFloor();
		el.goTo(50);
		assertEquals(temp, el.getFloor());
	}
	
	@Test
	public void printTest(){
		Elevator el = new Elevator(20, -5, 1);
		assertEquals(1, el.getFloor());
	}
	
	@Test
	public void callTest(){
		Elevator el = new Elevator(20, -5, 1);
		el.goTo(10);
		
		assertEquals(el.callElevator(3),"내려갑니다");
		assertEquals(el.getFloor(), 3);
		
		assertEquals(el.callElevator(5),"올라갑니다");
		assertEquals(el.getFloor(),5);
		
	}
	
	@Test
	public void getMaxHeightTest(){
		Elevator el = new Elevator(20, -5, 1);
		assertEquals(el.getMaxHeight(), 20);
	}
	@Test
	public void getMinHeightTest(){
		Elevator el = new Elevator(20, -5, 1);
		assertEquals(el.getMinHeight(), -5);
	}

}
Retrieved from http://wiki.zeropage.org/wiki.php/데블스캠프2011/다섯째날/HowToWriteCodeWell/김준석,서영주
last modified 2021-02-07 05:29:11