From 767217a143b12e5b18e90ad294177a2e6f7a44d0 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Wed, 25 Dec 2024 21:30:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=B7=B2=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E7=9A=84=20TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/xyz/zhouxy/plusone/commons/base/IWithCode.java | 6 +++--- .../java/xyz/zhouxy/plusone/commons/base/IWithIntCode.java | 6 +++--- .../java/xyz/zhouxy/plusone/commons/base/IWithLongCode.java | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/base/IWithCode.java b/src/main/java/xyz/zhouxy/plusone/commons/base/IWithCode.java index b8bc1bb..bec30b0 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/base/IWithCode.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/base/IWithCode.java @@ -34,15 +34,15 @@ public interface IWithCode { default boolean equalsCode(T code) { return Objects.equals(getCode(), code); } - default boolean equalsCode(IWithCode obj) { // TODO 单元测试 + default boolean equalsCode(IWithCode obj) { 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()); } - default boolean equalsCode(IWithLongCode obj) { // TODO 单元测试 + default boolean equalsCode(IWithLongCode obj) { return obj != null && getCode().equals(obj.getCode()); } } diff --git a/src/main/java/xyz/zhouxy/plusone/commons/base/IWithIntCode.java b/src/main/java/xyz/zhouxy/plusone/commons/base/IWithIntCode.java index 5a5f36c..3e65ca5 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/base/IWithIntCode.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/base/IWithIntCode.java @@ -30,15 +30,15 @@ public interface IWithIntCode { return getCode() == code; } - default boolean equalsCode(IWithCode obj) { // TODO 单元测试 + default boolean equalsCode(IWithCode obj) { return obj != null && obj.getCode().equals(getCode()); } - default boolean equalsCode(IWithIntCode obj) { // TODO 单元测试 + default boolean equalsCode(IWithIntCode obj) { return obj != null && getCode() == obj.getCode(); } - default boolean equalsCode(IWithLongCode obj) { // TODO 单元测试 + default boolean equalsCode(IWithLongCode obj) { return obj != null && getCode() == obj.getCode(); } } diff --git a/src/main/java/xyz/zhouxy/plusone/commons/base/IWithLongCode.java b/src/main/java/xyz/zhouxy/plusone/commons/base/IWithLongCode.java index 7550358..bef8622 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/base/IWithLongCode.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/base/IWithLongCode.java @@ -30,15 +30,15 @@ public interface IWithLongCode { return getCode() == code; } - default boolean equalsCode(IWithCode obj) { // TODO 单元测试 + default boolean equalsCode(IWithCode obj) { return obj != null && obj.getCode().equals(getCode()); } - default boolean equalsCode(IWithIntCode obj) { // TODO 单元测试 + default boolean equalsCode(IWithIntCode obj) { return obj != null && getCode() == obj.getCode(); } - default boolean equalsCode(IWithLongCode obj) { // TODO 单元测试 + default boolean equalsCode(IWithLongCode obj) { return obj != null && getCode() == obj.getCode(); } } From 979293cb7ad23682cd09615e5fe865b5597265ea Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Wed, 25 Dec 2024 21:30:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=8C=E6=88=90=20Quarter=20=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProgressOfTesting.txt | 6 +- .../zhouxy/plusone/commons/time/Quarter.java | 4 +- .../plusone/commons/time/QuarterTests.java | 112 ++++++++++++++++++ 3 files changed, 117 insertions(+), 5 deletions(-) diff --git a/ProgressOfTesting.txt b/ProgressOfTesting.txt index 9387d85..5c34b22 100644 --- a/ProgressOfTesting.txt +++ b/ProgressOfTesting.txt @@ -1,6 +1,6 @@ [ ] 未开始测试 - 25 (35.71%) -[-] 测试未完成 - 13 (18.57%) -[Y] 测试完成 - 20 (28.57%) +[-] 测试未完成 - 12 (17.14%) +[Y] 测试完成 - 21 (30.00%) [x] 无需测试 - 12 (17.14%) xyz.zhouxy.plusone.commons @@ -79,7 +79,7 @@ xyz.zhouxy.plusone.commons │ SQL.java [ ] │ ├───time - │ Quarter.java [-] + │ Quarter.java [Y] │ YearQuarter.java [-] │ └───util diff --git a/src/main/java/xyz/zhouxy/plusone/commons/time/Quarter.java b/src/main/java/xyz/zhouxy/plusone/commons/time/Quarter.java index cbc38e1..71efd48 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/time/Quarter.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/time/Quarter.java @@ -116,12 +116,12 @@ public enum Quarter implements IWithIntCode { // computes - public Quarter plus(long quarters) { // TODO 单元测试 + public Quarter plus(long quarters) { final int amount = (int) ((quarters % 4) + 4); return ENUMS[(ordinal() + amount) % 4]; } - public Quarter minus(long quarters) { // TODO 单元测试 + public Quarter minus(long quarters) { return plus(-(quarters % 4)); } diff --git a/src/test/java/xyz/zhouxy/plusone/commons/time/QuarterTests.java b/src/test/java/xyz/zhouxy/plusone/commons/time/QuarterTests.java index 69637a8..75f583f 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/time/QuarterTests.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/time/QuarterTests.java @@ -240,4 +240,116 @@ class QuarterTests { firstDayOfYear = Quarter.Q4.firstDayOfYear(false); 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)); + } + } }