U E D R , A S I H C RSS

데블스캠프2011/다섯째날/How To Write Code Well/임상현,서민관

Difference between r1.6 and the current

@@ -164,7 +164,7 @@
}
}}}

== 클래스 파일 ==
== Elev.java ==
{{{

public class Elev {


testTest.java

import static org.junit.Assert.*;

import java.util.Timer;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


public class testTest {

	private Elev el1;
	private Elev el2;

	@Before
	public void setUp() throws Exception {
		el1 = new Elev(10,-2);
		el2 = new Elev(-10,20);
	}

	@After
	public void tearDown() throws Exception {
		
	}

	@Test
	public void testConstructor1() {
		Elev el3 = new Elev(10,-2);
		assertEquals("UP", el3.direction);
		assertEquals(1, el3.currentFloor);
		assertEquals(0, el3.Turn);
		assertEquals(10, el3.maxFloor);
		assertEquals(-2, el3.minFloor);
	}
	
	@Test
	public void testConstructor2() {
		Elev el3 = new Elev(-2,10);
		assertEquals("UP", el3.direction);
		assertEquals(1, el3.currentFloor);
		assertEquals(0, el3.Turn);
		assertEquals(10, el3.maxFloor);
		assertEquals(-2, el3.minFloor);		
	}
	
	@Test
	public void testConstructor3() {
		Elev el3 = new Elev(-2,-20);
		assertEquals("DOWN", el3.direction);
		assertEquals(-2, el3.currentFloor);
		assertEquals(0, el3.Turn);
		assertEquals(-2, el3.maxFloor);
		assertEquals(-20, el3.minFloor);	
		
	}
	
	@Test
	public void testConstructor4() {
		Elev el3 = new Elev(3,30);
		assertEquals("UP", el3.direction);
		assertEquals(3, el3.currentFloor);
		assertEquals(0, el3.Turn);
		assertEquals(30, el3.maxFloor);
		assertEquals(3, el3.minFloor);
		
	}
	

	@Test
	public void testgoTo1() throws Exception {
		el1.goTo(4);
		assertEquals(3, el1.Turn);
		assertEquals(4, el1.currentFloor);
	}
	
	@Test(expected = Exception.class)
	public void testgoTo2() throws Exception {
		el1.goTo(44);
		assertEquals(1, el1.currentFloor);
	}

	@Test(expected = Exception.class)
	public void testgoTo3() throws Exception {
		el1.goTo(-39);
		assertEquals(1, el1.currentFloor);
	}
	

	@Test
	public void testupTo1() throws Exception {
		el1.upTo(5);
		assertEquals(4, el1.Turn);
		assertEquals(5, el1.currentFloor);
	}

	@Test(expected = Exception.class)
	public void testupTo2() throws Exception {
		el1.upTo(30);
	}

	@Test(expected = Exception.class)
	public void testupTo3() throws Exception {
		el1.upTo(-39);
	}
	
	@Test(expected = Exception.class)
	public void testupTo4() throws Exception {
		el1.upTo(0);
	}
	
	@Test
	public void testdownTo1() throws Exception {
		el1.downTo(5);
		assertEquals(4, el1.Turn);
		assertEquals(5, el1.currentFloor);
	}

	@Test(expected = Exception.class)
	public void testdownTo2() throws Exception {
		el1.downTo(30);
	}

	@Test(expected = Exception.class)
	public void testdownTo3() throws Exception {
		el1.downTo(-39);
	}
	@Test(expected = Exception.class)
	public void testdownTo4() throws Exception {
		el1.downTo(0);
	}
	
	@Test
	public void testpush1() throws Exception {
		el1.push(5);
		assertEquals(4, el1.Turn);
		assertEquals(5, el1.currentFloor);
	}

	@Test(expected = Exception.class)
	public void testpush2() throws Exception {
		el1.push(30);
	}

	@Test(expected = Exception.class)
	public void testpush3() throws Exception {
		el1.push(-39);
	}
	@Test(expected = Exception.class)
	public void testpush4() throws Exception {
		el1.push(0);
	}
	
	@Test
	public void testcase1() {
		assertEquals(1, el1.currentFloor);
	}
	

	
}

Elev.java


public class Elev {
	public String direction;
	public int currentFloor;
	public int maxFloor;
	public int minFloor;
	public int Turn;

	public Elev(int i, int j) {
		if ( i > j ) {
			this.maxFloor = i;
			this.minFloor = j;
		}
		else {
			this.maxFloor = j;
			this.minFloor = i;
		}
		if(minFloor <= 1 && maxFloor>=1)
			currentFloor = 1;
		else
			currentFloor = minFloor;

		if(minFloor < 0 && maxFloor < 0)
			currentFloor = maxFloor;
		
		
		if(i<0 && j<0){
			direction = "DOWN";
		}
		else{
			direction = "UP";
		}
	}

	
	
	public void goTo(int i) throws Exception {
		
		if ( i >= minFloor && i <= maxFloor && i != 0 ) {
			Turn = Math.abs(this.currentFloor - i); 
			this.currentFloor = i;
		}
		else{
			throw new Exception("wow");
		}
		
	}

	public void downTo(int i) throws Exception {// 외부에서 엘리베이터가 내려오도록 함.
		direction = "DOWN";
		goTo(i);
	}

	public void push(int i) throws Exception { // 엘리베이터 내부에서 i층으로 이동.
		goTo(i);		
	}

	public void upTo(int i) throws Exception { // 외부에서 엘리베이터가 올라오도록 함.
		direction = "UP";
			goTo(i);
	}

}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:12
Processing time 0.0429 sec