package org.jerrymouse.chineseCalendar.model.birthday;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jerrymouse.chineseCalendar.test.TestInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { TestInfo.ApplicationContentPath })
public class LunarCacluatorTest {
	Log logger = LogFactory.getLog(LunarCacluatorTest.class);

	@Autowired
	LunarCacluator lunarCacluator;

	private SimpleCalendar randomDate() {
		Random random = new Random();
		int year = random.nextInt(90) + 1 + 1955;
		int month = random.nextInt(12) + 1;
		int day = random.nextInt(25) + 1;
		return new SimpleCalendar(year, month, day);
	}

	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testMap() throws Exception {
		Map<SimpleCalendar, SimpleCalendar> map = lunarCacluator.getMap();
		Set<SimpleCalendar> keys = map.keySet();
		List<SimpleCalendar> list = new ArrayList<SimpleCalendar>(keys);
		Collections.sort(list);
	}

	@Test
	public void testToLunar() {
		logger.debug(lunarCacluator.toLunar(new SimpleCalendar()));
		for (int i = 0; i < 5; i++) {
			SimpleCalendar calendar = randomDate();
			logger.debug(calendar + "," + lunarCacluator.toLunar(calendar));
		}

	}

	@Test
	public void testToNormal() {
		logger.debug(lunarCacluator.toNormal(new SimpleCalendar("1989-5-27")));
		logger.debug(lunarCacluator.toNormal(new SimpleCalendar("1988-6-2")));
		logger.debug(lunarCacluator.toNormal(new SimpleCalendar("1990-6-5")));

		logger.debug(lunarCacluator.toNormal(new SimpleCalendar("2009-1-27")));
	}

}
