package jdk.operator;

import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * 
 * @since 2017-07-27
 * @author fixalot
 */
public class OperatorTest {
	private static final Logger logger = LoggerFactory.getLogger(OperatorTest.class);

	@Test
	public void negativeSign() {
		Assert.assertTrue(-3 < 0);
		final int three = 3;
		Assert.assertEquals(-3, -(three));
		Assert.assertEquals(-3, -three);
		Assert.assertEquals(3, -(-three));
		Assert.assertEquals(-3, -(-(-three)));
	}
	
	@Test
	public void ternaryOperator() {
		String first = "1";
		String second = "2";
		String third = "3";
		String fourth = "";

		String result = (!fourth.isEmpty()) ? fourth : (!third.isEmpty()) ? third : (!second.isEmpty()) ? second : first;
		Assert.assertEquals("3", result);
	}

	@Test
	public void unaryOperator() {
		int a = 0;
		Assert.assertEquals(1, ++a); // 변수 반환 이전에 연산. 따라서 +1의 결과인 1
		Assert.assertEquals(1, a);
		Assert.assertEquals(1, a++); // 변수 반환 이후에 연산. 따라서 +1 하기 전의 결과인 1
		Assert.assertEquals(2, a);

		// 반복문에서 증감연산자는 피연산자의 어느쪽에 있어도 상관 없다.
		for (int i = 0; i < 2; ++i) {
			logger.debug(String.valueOf(i));
		}
		for (int i = 0; i < 2; i++) {
			logger.debug(String.valueOf(i));
		}
	}
	
	@Test
	public void binaryOperator() {
		Assert.assertEquals(2, 1 + 1);
	}
	
	@Test
	public void modulusOperator() {
		Assert.assertEquals(0, 0 % 3);
		Assert.assertEquals(1, 1 % 3);
		Assert.assertEquals(2, 2 % 3);
		Assert.assertEquals(0, 3 % 3);
		Assert.assertEquals(1, 4 % 3);
		Assert.assertEquals(2, 5 % 3);
		Assert.assertEquals(0, 6 % 3);
	}
	
}

@@ -290,16 +290,687 @@
 lass);%0A%0A
+%09/**%0A%09 * %ED%95%A0%EB%8B%B9 %EC%97%B0%EC%82%B0%EC%9E%90%3Csup%3Eassignment operator%3C/sup%3E %ED%85%8C%EC%8A%A4%ED%8A%B8%0A%09 * %0A%09 * @author noritersand%0A%09 */%0A%09@Test%0A%09public void assignmentOperator() %7B%0A%09%09// %ED%95%A0%EB%8B%B9%0A%09%09int n = 1;%0A%09%09Assert.assertEquals(1, n);%0A%09%09%0A%09%09// %EC%82%B0%EC%88%A0 %EC%97%B0%EC%82%B0 %ED%9B%84 %ED%95%A0%EB%8B%B9%0A%09%09n += 2;%0A%09%09Assert.assertEquals(3, n);%0A%09%09n -= 1;%0A%09%09Assert.assertEquals(2, n);%0A%09%09n *= 5;%0A%09%09Assert.assertEquals(10, n);%0A%09%09n /= 2;%0A%09%09Assert.assertEquals(5, n);%0A%09%09%0A%09%09// %EB%B3%80%EC%88%98 %ED%95%98%EB%82%98 %EC%9D%B4%EC%83%81%EC%9D%84 %ED%95%9C %EB%B2%88%EC%97%90 %EC%B4%88%EA%B8%B0%ED%99%94%0A%09%09int num = n = 9 + 1;%0A%09%09Assert.assertEquals(10, num);%0A%09%09Assert.assertEquals(%2220%22, String.valueOf(num = 20));%0A%09%09%0A%09%09// %EC%A2%80 %EB%8D%94 %EB%A7%8E%EC%9D%B4 %ED%95%B4%EB%B3%BC%EA%B9%8C?%0A%09%09int a, b, c, d, e;%0A%09%09a = b = c = d = e = 100; // %EB%8B%A4%EC%84%AF%EA%B0%9C%EB%A5%BC %ED%95%9C %EB%B2%88%EC%97%90 %EC%A1%B0%EB%A1%9C%EB%A1%9D%0A%09%09Assert.assertTrue(a == b && b == c && c == d && d == e && e == 100); // %EB%8B%B9%EC%97%B0%ED%9E%88 %EB%8B%A4%EC%84%AF %EB%B3%80%EC%88%98%EC%9D%98 %EA%B0%92%EC%9D%80 %EA%B0%99%EC%9D%8C%0A%09%7D%0A%09%0A
 %09@Test%0A%09

add assignment operator test case