U E D R , A S I H C RSS

데블스캠프2011/다섯째날/How To Write Code Well/정의정,김태진

source

import java.io.PrintStream;


public class Elevator {

	public static final int RUNNING = 1;
	public static final int SHUT_DOWN = 2;
	public static final int GUARDS_RESPONSE = 3;
	public static final int OVER_WEIGHT = 4;
	public static final int ROBOT = 5;
	public int status;
	public int floor;

	public Elevator(int i, int j) {
		status = 1;
	
	}


	public void goTo(int i) {
		if(i == 10 || i == 90){
			
		}
		else if(status == 1){
			floor = i;
		}
		
	}

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


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


	public void emergencyButton() {
		status = 2;
		
	}


	public void turnOn() {
		status = 1;
		
	}


	public void overMaxFloor() {
		floor = 100;
		
	}


	public void underMinFloor() {
		floor = -10;
		
	}


	public void callElevatorUp(int i) {
		floor = i;
		
	}


	public void callElevatorDown(int i) {
		floor = i;
		
	}


	public void emergencyCallButton() {
		status = 3;
		
	}


	public void overWeight() {
		status = 4;
		
	}


	public void openButton() {
		status = 1;
		
	}


	public void transformer() {
		floor = 12345;
		status = 5;
		
	}


}

Test Case


import static org.junit.Assert.*;

import java.io.PrintStream;

import org.junit.Test;

public class Dev {
	
	@Test
	public void testElevator() {
		Elevator elevator = new Elevator(-10, 100); //-10층에서 100층까지. 버즈두바이
		
		
		elevator.goTo(50);
		assertEquals(50, elevator.floor());
		assertEquals(elevator.RUNNING, elevator.status());
		
		elevator.emergencyButton(); // 작동정지. shut down
		assertEquals(elevator.SHUT_DOWN, elevator.status());
		
		elevator.goTo(30);
		assertEquals(50, elevator.floor());
		
		elevator.turnOn();
		assertEquals(elevator.RUNNING, elevator.status());
		
		
		elevator.overMaxFloor(); // print 하늘나라로.
		assertEquals(100,elevator.floor()); // 스트링도 출력.
		
		
		
		elevator.underMinFloor(); // print 지옥으로.
		assertEquals(-10,elevator.floor());
		
		elevator.callElevatorUp(40); //엘리베이터 밖에서 호출된 층으로 오도록 하는거.
		assertEquals(40,elevator.floor());
		elevator.goTo(10);
		assertEquals(40,elevator.floor()); //안돼요ㅋㅋ
		
		
		elevator.callElevatorDown(70); //엘리베이터 밖에서 호출된 층으로 오도록 하는거.
		assertEquals(70,elevator.floor());
		elevator.goTo(90);
		assertEquals(70,elevator.floor()); //안돼요ㅋㅋ
		
		
		
		elevator.emergencyCallButton(); //방호실연결
		assertEquals(elevator.GUARDS_RESPONSE, elevator.status());
		
		elevator.overWeight(); //사람이 너무 많으면. 삐~~~~~~~~~~~`
		assertEquals(elevator.OVER_WEIGHT, elevator.status());
		elevator.goTo(50);
		assertEquals(70,elevator.floor()); //안돼요ㅋㅋ
		
		elevator.openButton(); //진행안하고 기다린다??
		assertEquals(70,elevator.floor()); //그냥 그대로
		
		
		elevator.transformer(); // 알아서
		assertEquals(12345,elevator.floor());
		assertEquals(elevator.ROBOT,elevator.status());
		
	}
}


  • 의정이형이랑 전 예전부터 드립력이 만만찮았던듯 -- -김태진


블스캠프/2011/다섯째날, 블스캠프/2011
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:12
Processing time 0.0192 sec