mirror of
https://gitee.com/6tail/lunar-csharp.git
synced 2025-12-06 10:19:07 +08:00
v1.1.0.21 修复星座错误;新增数九、三伏。
This commit is contained in:
70
lunar/Fu.cs
Normal file
70
lunar/Fu.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
namespace com.nlf.calendar
|
||||
{
|
||||
/// <summary>
|
||||
/// 三伏
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// <p>从夏至后第3个庚日算起,初伏为10天,中伏为10天或20天,末伏为10天。当夏至与立秋之间出现4个庚日时中伏为10天,出现5个庚日则为20天。</p>
|
||||
/// </summary>
|
||||
public class Fu
|
||||
{
|
||||
/// <summary>
|
||||
/// 名称:初伏、中伏、末伏
|
||||
/// </summary>
|
||||
private string name;
|
||||
|
||||
/// <summary>
|
||||
/// 当前入伏第几天,1-20
|
||||
/// </summary>
|
||||
private int index;
|
||||
|
||||
public Fu()
|
||||
{
|
||||
}
|
||||
|
||||
public Fu(string name, int index)
|
||||
{
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
|
||||
}
|
||||
|
||||
public string getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(string name)
|
||||
{
|
||||
this.name = name;
|
||||
|
||||
}
|
||||
|
||||
public int getIndex()
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index)
|
||||
{
|
||||
this.index = index;
|
||||
|
||||
}
|
||||
|
||||
public string toString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public string toFullString()
|
||||
{
|
||||
return name + "第" + index + "天";
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
122
lunar/Lunar.cs
122
lunar/Lunar.cs
@@ -566,7 +566,7 @@ namespace com.nlf.calendar
|
||||
}
|
||||
|
||||
//追加上一农历年末的大雪
|
||||
double q = calcJieQi(w-15.2184);
|
||||
double q = calcJieQi(w - 15.2184);
|
||||
jieQi.Add(JIE_QI_PREPEND, Solar.fromJulianDay(qiAccurate2(q) + Solar.J2000));
|
||||
|
||||
int size = JIE_QI.Length;
|
||||
@@ -2562,6 +2562,46 @@ namespace com.nlf.calendar
|
||||
return timeZhiIndex;
|
||||
}
|
||||
|
||||
public int getDayGanIndex()
|
||||
{
|
||||
return dayGanIndex;
|
||||
}
|
||||
|
||||
public int getDayZhiIndex()
|
||||
{
|
||||
return dayZhiIndex;
|
||||
}
|
||||
|
||||
public int getMonthGanIndex()
|
||||
{
|
||||
return monthGanIndex;
|
||||
}
|
||||
|
||||
public int getMonthZhiIndex()
|
||||
{
|
||||
return monthZhiIndex;
|
||||
}
|
||||
|
||||
public int getYearGanIndex()
|
||||
{
|
||||
return yearGanIndex;
|
||||
}
|
||||
|
||||
public int getYearZhiIndex()
|
||||
{
|
||||
return yearZhiIndex;
|
||||
}
|
||||
|
||||
public int getYearGanIndexByLiChun()
|
||||
{
|
||||
return yearGanIndexByLiChun;
|
||||
}
|
||||
|
||||
public int getYearZhiIndexByLiChun()
|
||||
{
|
||||
return yearZhiIndexByLiChun;
|
||||
}
|
||||
|
||||
public int getDayGanIndexExact()
|
||||
{
|
||||
return dayGanIndexExact;
|
||||
@@ -2845,5 +2885,85 @@ namespace com.nlf.calendar
|
||||
{
|
||||
return LunarUtil.getXunKong(getTimeInGanZhi());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数九
|
||||
/// </summary>
|
||||
/// <returns>数九,如果不是数九天,返回null</returns>
|
||||
public ShuJiu getShuJiu()
|
||||
{
|
||||
DateTime currentCalendar = new DateTime(solar.getYear(), solar.getMonth(), solar.getDay(), 0, 0, 0, 0);
|
||||
Solar start = jieQi[JIE_QI_APPEND];
|
||||
DateTime startCalendar = new DateTime(start.getYear(), start.getMonth(), start.getDay(), 0, 0, 0, 0);
|
||||
if (currentCalendar.CompareTo(startCalendar) < 0)
|
||||
{
|
||||
start = jieQi[JIE_QI_FIRST];
|
||||
startCalendar = new DateTime(start.getYear(), start.getMonth(), start.getDay(), 0, 0, 0, 0);
|
||||
}
|
||||
DateTime endCalendar = startCalendar.AddDays(81);
|
||||
if (currentCalendar.CompareTo(startCalendar) < 0 || currentCalendar.CompareTo(endCalendar) >= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int days = currentCalendar.Subtract(startCalendar).Days;
|
||||
return new ShuJiu(LunarUtil.NUMBER[days / 9 + 1] + "九", days % 9 + 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取三伏
|
||||
/// </summary>
|
||||
/// <returns>三伏,如果不是伏天,返回null</returns>
|
||||
public Fu getFu()
|
||||
{
|
||||
DateTime currentCalendar = new DateTime(solar.getYear(), solar.getMonth(), solar.getDay(), 0, 0, 0, 0);
|
||||
Solar xiaZhi = jieQi["夏至"];
|
||||
Solar liQiu = jieQi["立秋"];
|
||||
DateTime startCalendar = new DateTime(xiaZhi.getYear(), xiaZhi.getMonth(), xiaZhi.getDay(), 0, 0, 0, 0);
|
||||
int add = 6 - xiaZhi.getLunar().getDayGanIndex();
|
||||
if (add < 0)
|
||||
{
|
||||
add += 10;
|
||||
}
|
||||
add += 20;
|
||||
startCalendar = startCalendar.AddDays(add);
|
||||
if (currentCalendar.CompareTo(startCalendar) < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int days = currentCalendar.Subtract(startCalendar).Days;
|
||||
if (days < 10)
|
||||
{
|
||||
return new Fu("初伏", days + 1);
|
||||
}
|
||||
startCalendar = startCalendar.AddDays(10);
|
||||
days = currentCalendar.Subtract(startCalendar).Days;
|
||||
if (days < 10)
|
||||
{
|
||||
return new Fu("中伏", days + 1);
|
||||
}
|
||||
startCalendar = startCalendar.AddDays(10);
|
||||
DateTime liQiuCalendar = new DateTime(liQiu.getYear(), liQiu.getMonth(), liQiu.getDay(), 0, 0, 0, 0);
|
||||
days = currentCalendar.Subtract(startCalendar).Days;
|
||||
if (liQiuCalendar.CompareTo(startCalendar) <= 0)
|
||||
{
|
||||
if (days < 10)
|
||||
{
|
||||
return new Fu("末伏", days + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (days < 10)
|
||||
{
|
||||
return new Fu("中伏", days + 11);
|
||||
}
|
||||
startCalendar = startCalendar.AddDays(10);
|
||||
days = currentCalendar.Subtract(startCalendar).Days;
|
||||
if (days < 10)
|
||||
{
|
||||
return new Fu("末伏", days + 1);
|
||||
}
|
||||
} return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
[assembly: AssemblyVersion("1.1.0.20")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.20")]
|
||||
[assembly: AssemblyVersion("1.1.0.21")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.21")]
|
||||
|
||||
67
lunar/ShuJiu.cs
Normal file
67
lunar/ShuJiu.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
namespace com.nlf.calendar
|
||||
{
|
||||
/// <summary>
|
||||
/// 数九
|
||||
/// </summary>
|
||||
public class ShuJiu
|
||||
{
|
||||
/// <summary>
|
||||
/// 名称,如一九、二九
|
||||
/// </summary>
|
||||
private string name;
|
||||
|
||||
/// <summary>
|
||||
/// 当前数九第几天,1-9
|
||||
/// </summary>
|
||||
private int index;
|
||||
|
||||
public ShuJiu()
|
||||
{
|
||||
}
|
||||
|
||||
public ShuJiu(string name, int index)
|
||||
{
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
|
||||
}
|
||||
|
||||
public string getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(string name)
|
||||
{
|
||||
this.name = name;
|
||||
|
||||
}
|
||||
|
||||
public int getIndex()
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index)
|
||||
{
|
||||
this.index = index;
|
||||
|
||||
}
|
||||
|
||||
public string toString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public string toFullString()
|
||||
{
|
||||
return name + "第" + index + "天";
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -348,8 +348,8 @@ namespace com.nlf.calendar
|
||||
/// <returns>星座</returns>
|
||||
public string getXingZuo()
|
||||
{
|
||||
int index = 11, m = month, d = day;
|
||||
int y = m * 100 + d;
|
||||
int index = 11;
|
||||
int y = month * 100 + day;
|
||||
if (y >= 321 && y <= 419)
|
||||
{
|
||||
index = 0;
|
||||
@@ -358,11 +358,11 @@ namespace com.nlf.calendar
|
||||
{
|
||||
index = 1;
|
||||
}
|
||||
else if (y >= 521 && y <= 620)
|
||||
else if (y >= 521 && y <= 621)
|
||||
{
|
||||
index = 2;
|
||||
}
|
||||
else if (y >= 621 && y <= 722)
|
||||
else if (y >= 622 && y <= 722)
|
||||
{
|
||||
index = 3;
|
||||
}
|
||||
@@ -374,15 +374,15 @@ namespace com.nlf.calendar
|
||||
{
|
||||
index = 5;
|
||||
}
|
||||
else if (y >= 923 && y <= 1022)
|
||||
else if (y >= 923 && y <= 1023)
|
||||
{
|
||||
index = 6;
|
||||
}
|
||||
else if (y >= 1023 && y <= 1121)
|
||||
else if (y >= 1024 && y <= 1122)
|
||||
{
|
||||
index = 7;
|
||||
}
|
||||
else if (y >= 1122 && y <= 1221)
|
||||
else if (y >= 1123 && y <= 1221)
|
||||
{
|
||||
index = 8;
|
||||
}
|
||||
|
||||
@@ -40,9 +40,11 @@
|
||||
<Compile Include="eightchar\LiuYue.cs" />
|
||||
<Compile Include="eightchar\XiaoYun.cs" />
|
||||
<Compile Include="eightchar\Yun.cs" />
|
||||
<Compile Include="Fu.cs" />
|
||||
<Compile Include="Holiday.cs" />
|
||||
<Compile Include="JieQi.cs" />
|
||||
<Compile Include="Lunar.cs" />
|
||||
<Compile Include="ShuJiu.cs" />
|
||||
<Compile Include="Solar.cs" />
|
||||
<Compile Include="SolarHalfYear.cs" />
|
||||
<Compile Include="SolarMonth.cs" />
|
||||
|
||||
208
test/FuTest.cs
Normal file
208
test/FuTest.cs
Normal file
@@ -0,0 +1,208 @@
|
||||
// 以下代码由 Microsoft Visual Studio 2005 生成。
|
||||
// 测试所有者应该检查每个测试的有效性。
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using com.nlf.calendar;
|
||||
namespace test
|
||||
{
|
||||
/// <summary>
|
||||
/// 三伏测试
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class FuTest
|
||||
{
|
||||
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///获取或设置测试上下文,上下文提供
|
||||
///有关当前测试运行及其功能的信息。
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
#region 附加测试属性
|
||||
//
|
||||
//编写测试时,可使用以下附加属性:
|
||||
//
|
||||
//使用 ClassInitialize 在运行类中的第一个测试前先运行代码
|
||||
//
|
||||
//[ClassInitialize()]
|
||||
//public static void MyClassInitialize(TestContext testContext)
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//使用 ClassCleanup 在运行完类中的所有测试后再运行代码
|
||||
//
|
||||
//[ClassCleanup()]
|
||||
//public static void MyClassCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//使用 TestInitialize 在运行每个测试前先运行代码
|
||||
//
|
||||
//[TestInitialize()]
|
||||
//public void MyTestInitialize()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//使用 TestCleanup 在运行完每个测试后运行代码
|
||||
//
|
||||
//[TestCleanup()]
|
||||
//public void MyTestCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
#endregion
|
||||
|
||||
[TestMethod()]
|
||||
public void test1()
|
||||
{
|
||||
Solar solar = new Solar(2011, 7, 14);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.AreEqual("初伏", fu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("初伏第1天", fu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test2()
|
||||
{
|
||||
Solar solar = new Solar(2011, 7, 23);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.AreEqual("初伏", fu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("初伏第10天", fu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test3()
|
||||
{
|
||||
Solar solar = new Solar(2011, 7, 24);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.AreEqual("中伏", fu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("中伏第1天", fu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test4()
|
||||
{
|
||||
Solar solar = new Solar(2011, 8, 12);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.AreEqual("中伏", fu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("中伏第20天", fu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test5()
|
||||
{
|
||||
Solar solar = new Solar(2011, 8, 13);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.AreEqual("末伏", fu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("末伏第1天", fu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test6()
|
||||
{
|
||||
Solar solar = new Solar(2011, 8, 22);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.AreEqual("末伏", fu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("末伏第10天", fu.toFullString(), solar.toYmd());
|
||||
}
|
||||
[TestMethod()]
|
||||
public void test7()
|
||||
{
|
||||
Solar solar = new Solar(2011, 7, 13);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.IsNull(fu);
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test8()
|
||||
{
|
||||
Solar solar = new Solar(2011, 8, 23);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.IsNull(fu);
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test9()
|
||||
{
|
||||
Solar solar = new Solar(2012, 7, 18);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.AreEqual("初伏", fu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("初伏第1天", fu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test10()
|
||||
{
|
||||
Solar solar = new Solar(2012, 8, 5);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.AreEqual("中伏", fu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("中伏第9天", fu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test11()
|
||||
{
|
||||
Solar solar = new Solar(2012, 8, 8);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.AreEqual("末伏", fu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("末伏第2天", fu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test12()
|
||||
{
|
||||
Solar solar = new Solar(2020, 7, 17);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.AreEqual("初伏", fu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("初伏第2天", fu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test13()
|
||||
{
|
||||
Solar solar = new Solar(2020, 7, 26);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.AreEqual("中伏", fu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("中伏第1天", fu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test14()
|
||||
{
|
||||
Solar solar = new Solar(2020, 8, 24);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.AreEqual("末伏", fu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("末伏第10天", fu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
140
test/ShuJiuTest.cs
Normal file
140
test/ShuJiuTest.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
// 以下代码由 Microsoft Visual Studio 2005 生成。
|
||||
// 测试所有者应该检查每个测试的有效性。
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using com.nlf.calendar;
|
||||
namespace test
|
||||
{
|
||||
/// <summary>
|
||||
/// 数九测试
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class ShuJiuTest
|
||||
{
|
||||
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///获取或设置测试上下文,上下文提供
|
||||
///有关当前测试运行及其功能的信息。
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
#region 附加测试属性
|
||||
//
|
||||
//编写测试时,可使用以下附加属性:
|
||||
//
|
||||
//使用 ClassInitialize 在运行类中的第一个测试前先运行代码
|
||||
//
|
||||
//[ClassInitialize()]
|
||||
//public static void MyClassInitialize(TestContext testContext)
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//使用 ClassCleanup 在运行完类中的所有测试后再运行代码
|
||||
//
|
||||
//[ClassCleanup()]
|
||||
//public static void MyClassCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//使用 TestInitialize 在运行每个测试前先运行代码
|
||||
//
|
||||
//[TestInitialize()]
|
||||
//public void MyTestInitialize()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//使用 TestCleanup 在运行完每个测试后运行代码
|
||||
//
|
||||
//[TestCleanup()]
|
||||
//public void MyTestCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
#endregion
|
||||
|
||||
[TestMethod()]
|
||||
public void test1()
|
||||
{
|
||||
Solar solar = new Solar(2020, 12, 21);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.AreEqual("一九", shuJiu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("一九第1天", shuJiu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test2()
|
||||
{
|
||||
Solar solar = new Solar(2020, 12, 22);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.AreEqual("一九", shuJiu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("一九第2天", shuJiu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test3()
|
||||
{
|
||||
Solar solar = new Solar(2020, 1, 7);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.AreEqual("二九", shuJiu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("二九第8天", shuJiu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test4()
|
||||
{
|
||||
Solar solar = new Solar(2021, 1, 6);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.AreEqual("二九", shuJiu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("二九第8天", shuJiu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test5()
|
||||
{
|
||||
Solar solar = new Solar(2021, 1, 8);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.AreEqual("三九", shuJiu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("三九第1天", shuJiu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test6()
|
||||
{
|
||||
Solar solar = new Solar(2021, 3, 5);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.AreEqual("九九", shuJiu.toString(), solar.toYmd());
|
||||
Assert.AreEqual("九九第3天", shuJiu.toFullString(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test7()
|
||||
{
|
||||
Solar solar = new Solar(2021, 7, 5);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.IsNull(shuJiu);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
182
test/XingZuoTest.cs
Normal file
182
test/XingZuoTest.cs
Normal file
@@ -0,0 +1,182 @@
|
||||
// 以下代码由 Microsoft Visual Studio 2005 生成。
|
||||
// 测试所有者应该检查每个测试的有效性。
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using com.nlf.calendar;
|
||||
using com.nlf.calendar.util;
|
||||
namespace test
|
||||
{
|
||||
/// <summary>
|
||||
/// 星座测试
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class XingZuoTest
|
||||
{
|
||||
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///获取或设置测试上下文,上下文提供
|
||||
///有关当前测试运行及其功能的信息。
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
#region 附加测试属性
|
||||
//
|
||||
//编写测试时,可使用以下附加属性:
|
||||
//
|
||||
//使用 ClassInitialize 在运行类中的第一个测试前先运行代码
|
||||
//
|
||||
//[ClassInitialize()]
|
||||
//public static void MyClassInitialize(TestContext testContext)
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//使用 ClassCleanup 在运行完类中的所有测试后再运行代码
|
||||
//
|
||||
//[ClassCleanup()]
|
||||
//public static void MyClassCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//使用 TestInitialize 在运行每个测试前先运行代码
|
||||
//
|
||||
//[TestInitialize()]
|
||||
//public void MyTestInitialize()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//使用 TestCleanup 在运行完每个测试后运行代码
|
||||
//
|
||||
//[TestCleanup()]
|
||||
//public void MyTestCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
#endregion
|
||||
|
||||
|
||||
[TestMethod()]
|
||||
public void test1()
|
||||
{
|
||||
Solar solar = new Solar(2020, 3, 21);
|
||||
Assert.AreEqual("白羊", solar.getXingZuo(), solar.toYmd());
|
||||
solar = new Solar(2020, 4, 19);
|
||||
Assert.AreEqual("白羊", solar.getXingZuo(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test2()
|
||||
{
|
||||
Solar solar = new Solar(2020, 4, 20);
|
||||
Assert.AreEqual("金牛", solar.getXingZuo(), solar.toYmd());
|
||||
solar = new Solar(2020, 5, 20);
|
||||
Assert.AreEqual("金牛", solar.getXingZuo(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test3()
|
||||
{
|
||||
Solar solar = new Solar(2020, 5, 21);
|
||||
Assert.AreEqual("双子", solar.getXingZuo(), solar.toYmd());
|
||||
solar = new Solar(2020, 6, 21);
|
||||
Assert.AreEqual("双子", solar.getXingZuo(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test4()
|
||||
{
|
||||
Solar solar = new Solar(2020, 6, 22);
|
||||
Assert.AreEqual("巨蟹", solar.getXingZuo(), solar.toYmd());
|
||||
solar = new Solar(2020, 7, 22);
|
||||
Assert.AreEqual("巨蟹", solar.getXingZuo(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test5()
|
||||
{
|
||||
Solar solar = new Solar(2020, 7, 23);
|
||||
Assert.AreEqual("狮子", solar.getXingZuo(), solar.toYmd());
|
||||
solar = new Solar(2020, 8, 22);
|
||||
Assert.AreEqual("狮子", solar.getXingZuo(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test6()
|
||||
{
|
||||
Solar solar = new Solar(2020, 8, 23);
|
||||
Assert.AreEqual("处女", solar.getXingZuo(), solar.toYmd());
|
||||
solar = new Solar(2020, 9, 22);
|
||||
Assert.AreEqual("处女", solar.getXingZuo(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test7()
|
||||
{
|
||||
Solar solar = new Solar(2020, 9, 23);
|
||||
Assert.AreEqual("天秤", solar.getXingZuo(), solar.toYmd());
|
||||
solar = new Solar(2020, 10, 23);
|
||||
Assert.AreEqual("天秤", solar.getXingZuo(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test8()
|
||||
{
|
||||
Solar solar = new Solar(2020, 10, 24);
|
||||
Assert.AreEqual("天蝎", solar.getXingZuo(), solar.toYmd());
|
||||
solar = new Solar(2020, 11, 22);
|
||||
Assert.AreEqual("天蝎", solar.getXingZuo(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test9()
|
||||
{
|
||||
Solar solar = new Solar(2020, 11, 23);
|
||||
Assert.AreEqual("射手", solar.getXingZuo(), solar.toYmd());
|
||||
solar = new Solar(2020, 12, 21);
|
||||
Assert.AreEqual("射手", solar.getXingZuo(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test10()
|
||||
{
|
||||
Solar solar = new Solar(2020, 12, 22);
|
||||
Assert.AreEqual("摩羯", solar.getXingZuo(), solar.toYmd());
|
||||
solar = new Solar(2021, 1, 19);
|
||||
Assert.AreEqual("摩羯", solar.getXingZuo(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test11()
|
||||
{
|
||||
Solar solar = new Solar(2021, 1, 20);
|
||||
Assert.AreEqual("水瓶", solar.getXingZuo(), solar.toYmd());
|
||||
solar = new Solar(2021, 2, 18);
|
||||
Assert.AreEqual("水瓶", solar.getXingZuo(), solar.toYmd());
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void test12()
|
||||
{
|
||||
Solar solar = new Solar(2021, 2, 19);
|
||||
Assert.AreEqual("双鱼", solar.getXingZuo(), solar.toYmd());
|
||||
solar = new Solar(2021, 3, 20);
|
||||
Assert.AreEqual("双鱼", solar.getXingZuo(), solar.toYmd());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -45,6 +45,9 @@
|
||||
<Compile Include="SolarTest.cs" />
|
||||
<Compile Include="FestivalTest.cs" />
|
||||
<Compile Include="XunTest.cs" />
|
||||
<Compile Include="XingZuoTest.cs" />
|
||||
<Compile Include="ShuJiuTest.cs" />
|
||||
<Compile Include="FuTest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="AuthoringTests.txt" />
|
||||
|
||||
Reference in New Issue
Block a user