1
0
mirror of synced 2025-12-26 15:27:59 +08:00

optimized codes and fix negative month bug @ Lunar.getXiu()

This commit is contained in:
6tail
2019-05-05 15:45:00 +08:00
parent c196e58ec8
commit 6db884b981
16 changed files with 366 additions and 109 deletions

View File

@@ -0,0 +1,24 @@
package test;
import com.nlf.calendar.SolarHalfYear;
import org.junit.Assert;
import org.junit.Test;
/**
* 半年测试
*
* @author 6tail
*/
public class HalfYearTest {
@Test
public void test(){
SolarHalfYear halfYear = new SolarHalfYear(2019,5);
Assert.assertEquals("2019.1",halfYear.toString());
Assert.assertEquals("2019年上半年",halfYear.toFullString());
Assert.assertEquals("2019.2",halfYear.next(1).toString());
Assert.assertEquals("2019年下半年",halfYear.next(1).toFullString());
}
}

View File

@@ -0,0 +1,23 @@
package test;
import com.nlf.calendar.Lunar;
import org.junit.Assert;
import org.junit.Test;
/**
* 农历测试
*
* @author 6tail
*/
public class LunarTest {
@Test
public void test(){
Lunar date = new Lunar(2019,3,27);
Assert.assertEquals("己亥年叁月廿七",date.toString());
Assert.assertEquals("己亥年叁月廿七 猪年 西方白虎 娄金狗",date.toFullString());
Assert.assertEquals("2019-05-01",date.getSolar().toString());
Assert.assertEquals("2019-05-01 星期三 (劳动节) 金牛座",date.getSolar().toFullString());
}
}

View File

@@ -0,0 +1,24 @@
package test;
import com.nlf.calendar.SolarMonth;
import org.junit.Assert;
import org.junit.Test;
/**
* 月份测试
*
* @author 6tail
*/
public class MonthTest {
@Test
public void test(){
SolarMonth month = new SolarMonth(2019,5);
Assert.assertEquals("2019-5",month.toString());
Assert.assertEquals("2019年5月",month.toFullString());
Assert.assertEquals("2019-6",month.next(1).toString());
Assert.assertEquals("2019年6月",month.next(1).toFullString());
}
}

View File

@@ -0,0 +1,24 @@
package test;
import com.nlf.calendar.SolarSeason;
import org.junit.Assert;
import org.junit.Test;
/**
* 季度测试
*
* @author 6tail
*/
public class SeasonTest {
@Test
public void test(){
SolarSeason season = new SolarSeason(2019,5);
Assert.assertEquals("2019.2",season.toString());
Assert.assertEquals("2019年2季度",season.toFullString());
Assert.assertEquals("2019.3",season.next(1).toString());
Assert.assertEquals("2019年3季度",season.next(1).toFullString());
}
}

View File

@@ -0,0 +1,23 @@
package test;
import com.nlf.calendar.Solar;
import org.junit.Assert;
import org.junit.Test;
/**
* 阳历测试
*
* @author 6tail
*/
public class SolarTest {
@Test
public void test(){
Solar date = new Solar(2019,5,1);
Assert.assertEquals("2019-05-01",date.toString());
Assert.assertEquals("2019-05-01 星期三 (劳动节) 金牛座",date.toFullString());
Assert.assertEquals("己亥年叁月廿七",date.getLunar().toString());
Assert.assertEquals("己亥年叁月廿七 猪年 西方白虎 娄金狗",date.getLunar().toFullString());
}
}

View File

@@ -0,0 +1,44 @@
package test;
import com.nlf.calendar.SolarWeek;
import com.nlf.calendar.util.SolarUtil;
import org.junit.Assert;
import org.junit.Test;
/**
* 周测试
*
* @author 6tail
*/
public class WeekTest {
@Test
public void testFromMonday(){
//一周的开始从星期一开始计
int start = 1;
SolarWeek week = new SolarWeek(2019,5,1,start);
Assert.assertEquals("2019.5.1",week.toString());
Assert.assertEquals("2019年5月第1周",week.toFullString());
//当月共几周
Assert.assertEquals(5,SolarUtil.getWeeksOfMonth(week.getYear(),week.getMonth(),start));
//当周第一天
Assert.assertEquals("2019-04-29",week.getFirstDay().toString());
//当周第一天(本月)
Assert.assertEquals("2019-05-01",week.getFirstDayInMonth().toString());
}
@Test
public void testFromSunday(){
//一周的开始从星期日开始计
int start = 0;
SolarWeek week = new SolarWeek(2019,5,1,start);
Assert.assertEquals("2019.5.1",week.toString());
Assert.assertEquals("2019年5月第1周",week.toFullString());
//当月共几周
Assert.assertEquals(5,SolarUtil.getWeeksOfMonth(week.getYear(),week.getMonth(),start));
//当周第一天
Assert.assertEquals("2019-04-28",week.getFirstDay().toString());
//当周第一天(本月)
Assert.assertEquals("2019-05-01",week.getFirstDayInMonth().toString());
}
}

View File

@@ -0,0 +1,24 @@
package test;
import com.nlf.calendar.SolarYear;
import org.junit.Assert;
import org.junit.Test;
/**
* 年份测试
*
* @author 6tail
*/
public class YearTest {
@Test
public void test(){
SolarYear year = new SolarYear(2019);
Assert.assertEquals("2019",year.toString());
Assert.assertEquals("2019年",year.toFullString());
Assert.assertEquals("2020",year.next(1).toString());
Assert.assertEquals("2020年",year.next(1).toFullString());
}
}