commit
6b82b49520
|
@ -1,6 +1,6 @@
|
||||||
[ ] 未开始测试 - 25 (35.71%)
|
[ ] 未开始测试 - 25 (35.71%)
|
||||||
[-] 测试未完成 - 13 (18.57%)
|
[-] 测试未完成 - 12 (17.14%)
|
||||||
[Y] 测试完成 - 20 (28.57%)
|
[Y] 测试完成 - 21 (30.00%)
|
||||||
[x] 无需测试 - 12 (17.14%)
|
[x] 无需测试 - 12 (17.14%)
|
||||||
|
|
||||||
xyz.zhouxy.plusone.commons
|
xyz.zhouxy.plusone.commons
|
||||||
|
@ -79,7 +79,7 @@ xyz.zhouxy.plusone.commons
|
||||||
│ SQL.java [ ]
|
│ SQL.java [ ]
|
||||||
│
|
│
|
||||||
├───time
|
├───time
|
||||||
│ Quarter.java [-]
|
│ Quarter.java [Y]
|
||||||
│ YearQuarter.java [-]
|
│ YearQuarter.java [-]
|
||||||
│
|
│
|
||||||
└───util
|
└───util
|
||||||
|
|
|
@ -34,15 +34,15 @@ public interface IWithCode<T> {
|
||||||
default boolean equalsCode(T code) {
|
default boolean equalsCode(T code) {
|
||||||
return Objects.equals(getCode(), code);
|
return Objects.equals(getCode(), code);
|
||||||
}
|
}
|
||||||
default boolean equalsCode(IWithCode<?> obj) { // TODO 单元测试
|
default boolean equalsCode(IWithCode<?> obj) {
|
||||||
return obj != null && obj.getCode().equals(getCode());
|
return obj != null && obj.getCode().equals(getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean equalsCode(IWithIntCode obj) { // TODO 单元测试
|
default boolean equalsCode(IWithIntCode obj) {
|
||||||
return obj != null && getCode().equals(obj.getCode());
|
return obj != null && getCode().equals(obj.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean equalsCode(IWithLongCode obj) { // TODO 单元测试
|
default boolean equalsCode(IWithLongCode obj) {
|
||||||
return obj != null && getCode().equals(obj.getCode());
|
return obj != null && getCode().equals(obj.getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,15 +30,15 @@ public interface IWithIntCode {
|
||||||
return getCode() == code;
|
return getCode() == code;
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean equalsCode(IWithCode<?> obj) { // TODO 单元测试
|
default boolean equalsCode(IWithCode<?> obj) {
|
||||||
return obj != null && obj.getCode().equals(getCode());
|
return obj != null && obj.getCode().equals(getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean equalsCode(IWithIntCode obj) { // TODO 单元测试
|
default boolean equalsCode(IWithIntCode obj) {
|
||||||
return obj != null && getCode() == obj.getCode();
|
return obj != null && getCode() == obj.getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean equalsCode(IWithLongCode obj) { // TODO 单元测试
|
default boolean equalsCode(IWithLongCode obj) {
|
||||||
return obj != null && getCode() == obj.getCode();
|
return obj != null && getCode() == obj.getCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,15 +30,15 @@ public interface IWithLongCode {
|
||||||
return getCode() == code;
|
return getCode() == code;
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean equalsCode(IWithCode<?> obj) { // TODO 单元测试
|
default boolean equalsCode(IWithCode<?> obj) {
|
||||||
return obj != null && obj.getCode().equals(getCode());
|
return obj != null && obj.getCode().equals(getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean equalsCode(IWithIntCode obj) { // TODO 单元测试
|
default boolean equalsCode(IWithIntCode obj) {
|
||||||
return obj != null && getCode() == obj.getCode();
|
return obj != null && getCode() == obj.getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean equalsCode(IWithLongCode obj) { // TODO 单元测试
|
default boolean equalsCode(IWithLongCode obj) {
|
||||||
return obj != null && getCode() == obj.getCode();
|
return obj != null && getCode() == obj.getCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,12 +116,12 @@ public enum Quarter implements IWithIntCode {
|
||||||
|
|
||||||
// computes
|
// computes
|
||||||
|
|
||||||
public Quarter plus(long quarters) { // TODO 单元测试
|
public Quarter plus(long quarters) {
|
||||||
final int amount = (int) ((quarters % 4) + 4);
|
final int amount = (int) ((quarters % 4) + 4);
|
||||||
return ENUMS[(ordinal() + amount) % 4];
|
return ENUMS[(ordinal() + amount) % 4];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Quarter minus(long quarters) { // TODO 单元测试
|
public Quarter minus(long quarters) {
|
||||||
return plus(-(quarters % 4));
|
return plus(-(quarters % 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -240,4 +240,116 @@ class QuarterTests {
|
||||||
firstDayOfYear = Quarter.Q4.firstDayOfYear(false);
|
firstDayOfYear = Quarter.Q4.firstDayOfYear(false);
|
||||||
assertEquals(1 + (31 + 28 + 31) + (30 + 31 + 30) + (31 + 30 + 31), firstDayOfYear);
|
assertEquals(1 + (31 + 28 + 31) + (30 + 31 + 30) + (31 + 30 + 31), firstDayOfYear);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testPlusZeroAndPositiveRealNumbers() {
|
||||||
|
for (int i = 0; i < 100; i += 4) {
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q1.plus(i));
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q2.plus(i));
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q3.plus(i));
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q4.plus(i));
|
||||||
|
}
|
||||||
|
for (int i = 1; i < 100 + 1; i += 4) {
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q1.plus(i));
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q2.plus(i));
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q3.plus(i));
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q4.plus(i));
|
||||||
|
}
|
||||||
|
for (int i = 2; i < 100 + 2; i += 4) {
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q1.plus(i));
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q2.plus(i));
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q3.plus(i));
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q4.plus(i));
|
||||||
|
}
|
||||||
|
for (int i = 3; i < 100 + 3; i += 4) {
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q1.plus(i));
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q2.plus(i));
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q3.plus(i));
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q4.plus(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testPlusZeroAndNegativeNumber() {
|
||||||
|
for (int i = 0; i > -100; i -= 4) {
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q1.plus(i));
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q2.plus(i));
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q3.plus(i));
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q4.plus(i));
|
||||||
|
}
|
||||||
|
for (int i = -1; i > -(100 + 1); i -= 4) {
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q1.plus(i));
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q2.plus(i));
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q3.plus(i));
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q4.plus(i));
|
||||||
|
}
|
||||||
|
for (int i = -2; i > -(100 + 2); i -= 4) {
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q1.plus(i));
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q2.plus(i));
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q3.plus(i));
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q4.plus(i));
|
||||||
|
}
|
||||||
|
for (int i = -3; i > -(100 + 3); i -= 4) {
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q1.plus(i));
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q2.plus(i));
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q3.plus(i));
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q4.plus(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMinusZeroAndNegativeNumber() {
|
||||||
|
for (int i = 0; i < 100; i += 4) {
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q1.minus(i));
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q2.minus(i));
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q3.minus(i));
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q4.minus(i));
|
||||||
|
}
|
||||||
|
for (int i = 1; i < 100 + 1; i += 4) {
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q1.minus(i));
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q2.minus(i));
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q3.minus(i));
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q4.minus(i));
|
||||||
|
}
|
||||||
|
for (int i = 2; i < 100 + 2; i += 4) {
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q1.minus(i));
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q2.minus(i));
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q3.minus(i));
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q4.minus(i));
|
||||||
|
}
|
||||||
|
for (int i = 3; i < 100 + 3; i += 4) {
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q1.minus(i));
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q2.minus(i));
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q3.minus(i));
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q4.minus(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMinusZeroAndPositiveRealNumbers() {
|
||||||
|
for (int i = 0; i > -100; i -= 4) {
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q1.minus(i));
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q2.minus(i));
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q3.minus(i));
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q4.minus(i));
|
||||||
|
}
|
||||||
|
for (int i = -1; i > -(100 + 1); i -= 4) {
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q1.minus(i));
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q2.minus(i));
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q3.minus(i));
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q4.minus(i));
|
||||||
|
}
|
||||||
|
for (int i = -2; i > -(100 + 2); i -= 4) {
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q1.minus(i));
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q2.minus(i));
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q3.minus(i));
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q4.minus(i));
|
||||||
|
}
|
||||||
|
for (int i = -3; i > -(100 + 3); i -= 4) {
|
||||||
|
assertEquals(Quarter.Q4, Quarter.Q1.minus(i));
|
||||||
|
assertEquals(Quarter.Q1, Quarter.Q2.minus(i));
|
||||||
|
assertEquals(Quarter.Q2, Quarter.Q3.minus(i));
|
||||||
|
assertEquals(Quarter.Q3, Quarter.Q4.minus(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue