diff --git a/confidence-core/src/main/java/org/saynotobugs/confidence/description/NumberDescription.java b/confidence-core/src/main/java/org/saynotobugs/confidence/description/NumberDescription.java index 05c0aeb2..e4471a5d 100644 --- a/confidence-core/src/main/java/org/saynotobugs/confidence/description/NumberDescription.java +++ b/confidence-core/src/main/java/org/saynotobugs/confidence/description/NumberDescription.java @@ -28,6 +28,36 @@ public final class NumberDescription extends DescriptionComposition { public NumberDescription(Number value) { - super(new ToStringDescription(value)); + super(new ToStringDescription(new NumberToString(value))); + } + + private final static class NumberToString + { + + private final Number mNumber; + + private NumberToString(Number number) {mNumber = number;} + + @Override + public String toString() + { + if (mNumber instanceof Integer) + { + return mNumber.toString(); + } + if (mNumber instanceof Long) + { + return mNumber.toString() + "l"; + } + if (mNumber instanceof Float) + { + return mNumber.toString() + "f"; + } + if (mNumber instanceof Double) + { + return mNumber.toString() + "d"; + } + return mNumber.toString(); + } } } diff --git a/confidence-core/src/test/java/org/saynotobugs/confidence/description/NumberDescriptionTest.java b/confidence-core/src/test/java/org/saynotobugs/confidence/description/NumberDescriptionTest.java index 45b578f6..dd9615fe 100644 --- a/confidence-core/src/test/java/org/saynotobugs/confidence/description/NumberDescriptionTest.java +++ b/confidence-core/src/test/java/org/saynotobugs/confidence/description/NumberDescriptionTest.java @@ -16,16 +16,23 @@ void testInt() } + @Test + void testLong() + { + assertThat(new NumberDescription(123l), new DescribesAs("<123l>")); + } + + @Test void testFloat() { - assertThat(new NumberDescription(123.23f), new DescribesAs("<123.23>")); + assertThat(new NumberDescription(123.23f), new DescribesAs("<123.23f>")); } @Test void testDouble() { - assertThat(new NumberDescription(123.23d), new DescribesAs("<123.23>")); + assertThat(new NumberDescription(123.23d), new DescribesAs("<123.23d>")); } } \ No newline at end of file diff --git a/confidence-core/src/test/java/org/saynotobugs/confidence/quality/file/HasLengthTest.java b/confidence-core/src/test/java/org/saynotobugs/confidence/quality/file/HasLengthTest.java index af6f0890..e18c525f 100644 --- a/confidence-core/src/test/java/org/saynotobugs/confidence/quality/file/HasLengthTest.java +++ b/confidence-core/src/test/java/org/saynotobugs/confidence/quality/file/HasLengthTest.java @@ -54,9 +54,9 @@ void testWithQuality() throws IOException assertThat(new HasLength(new EqualTo<>(10L)), new AllOf<>( new Passes<>(file10Bytes), - new Fails<>(tempDir, new DescribesAs(new MatchesPattern("had length <\\d+>"))), - new Fails<>(emptyFile, "had length <0>"), - new HasDescription("has length <10>") + new Fails<>(tempDir, new DescribesAs(new MatchesPattern("had length <\\d+l>"))), + new Fails<>(emptyFile, "had length <0l>"), + new HasDescription("has length <10l>") )); } @@ -74,9 +74,9 @@ void testWithPrimitive() throws IOException assertThat(new HasLength(10), new AllOf<>( new Passes<>(file10Bytes), - new Fails<>(tempDir, new DescribesAs(new MatchesPattern("had length <\\d+>"))), - new Fails<>(emptyFile, "had length <0>"), - new HasDescription("has length <10>") + new Fails<>(tempDir, new DescribesAs(new MatchesPattern("had length <\\d+l>"))), + new Fails<>(emptyFile, "had length <0l>"), + new HasDescription("has length <10l>") )); } diff --git a/confidence-core/src/test/java/org/saynotobugs/confidence/quality/number/CloseToTest.java b/confidence-core/src/test/java/org/saynotobugs/confidence/quality/number/CloseToTest.java index b134b905..c24dd135 100644 --- a/confidence-core/src/test/java/org/saynotobugs/confidence/quality/number/CloseToTest.java +++ b/confidence-core/src/test/java/org/saynotobugs/confidence/quality/number/CloseToTest.java @@ -18,7 +18,7 @@ void testNumber() assertThat(new CloseTo(1.0, 0.01), new AllOf<>( new Passes<>(1.0, 1f, 1, 1.00999, 0.99000001), - new Fails<>(1.01001d, "<1.01001> differs from <1.0> by <0.01001>, which exceeds the ε of <0.01>"), + new Fails<>(1.01001d, "<1.01001d> differs from <1.0> by <0.01001>, which exceeds the ε of <0.01>"), new HasDescription("differs from <1.0> by less than <0.01>") )); } @@ -30,7 +30,7 @@ void testDouble1ulp() assertThat(new CloseTo(1.0), new AllOf<>( new Passes<>(1.0000000000000001, 0.9999999999999999), - new Fails<>(1.01001d, "<1.01001> differs from <1.0> by <0.01001>, which exceeds the ε of <2.220446049250313E-16>"), + new Fails<>(1.01001d, "<1.01001d> differs from <1.0> by <0.01001>, which exceeds the ε of <2.220446049250313E-16>"), new HasDescription("differs from <1.0> by less than <2.220446049250313E-16>") )); } @@ -42,7 +42,7 @@ void testDouble10ulp() assertThat(new CloseTo(1.0, 10), new AllOf<>( new Passes<>(1.000000000000001, 0.999999999999999), - new Fails<>(1.01001d, "<1.01001> differs from <1.0> by <0.01001>, which exceeds the ε of <2.220446049250313E-15>"), + new Fails<>(1.01001d, "<1.01001d> differs from <1.0> by <0.01001>, which exceeds the ε of <2.220446049250313E-15>"), new HasDescription("differs from <1.0> by less than <2.220446049250313E-15>") )); } @@ -53,7 +53,7 @@ void testFloat1ulp() assertThat(new CloseTo(1.0f), new AllOf<>( new Passes<>(1.0000001, 0.9999999), - new Fails<>(1.01001d, "<1.01001> differs from <1.0> by <0.01001>, which exceeds the ε of <1.1920929E-7>"), + new Fails<>(1.01001d, "<1.01001d> differs from <1.0> by <0.01001>, which exceeds the ε of <1.1920929E-7>"), new HasDescription("differs from <1.0> by less than <1.1920929E-7>") )); } @@ -65,7 +65,7 @@ void testFloat10ulp() assertThat(new CloseTo(1.0f, 10), new AllOf<>( new Passes<>(1.000001, 0.999999), - new Fails<>(1.01001d, "<1.01001> differs from <1.0> by <0.01001>, which exceeds the ε of <0.0000011920929>"), + new Fails<>(1.01001d, "<1.01001d> differs from <1.0> by <0.01001>, which exceeds the ε of <0.0000011920929>"), new HasDescription("differs from <1.0> by less than <0.0000011920929>") )); } diff --git a/confidence-core/src/test/java/org/saynotobugs/confidence/quality/number/HasLongValueTest.java b/confidence-core/src/test/java/org/saynotobugs/confidence/quality/number/HasLongValueTest.java index 43dd82d2..653d1c7b 100644 --- a/confidence-core/src/test/java/org/saynotobugs/confidence/quality/number/HasLongValueTest.java +++ b/confidence-core/src/test/java/org/saynotobugs/confidence/quality/number/HasLongValueTest.java @@ -35,8 +35,8 @@ void testWithPrimitive() assertThat(new HasLongValue(10L), new AllOf<>( new Passes<>(10, 10L, 10f, 10d), - new Fails<>(11, "had long value <11>"), - new HasDescription("has long value <10>") + new Fails<>(11, "had long value <11l>"), + new HasDescription("has long value <10l>") )); } @@ -46,8 +46,8 @@ void testWithQuality() assertThat(new HasLongValue(new LessThan<>(11L)), new AllOf<>( new Passes<>(10, 10L, 10f, 10d), - new Fails<>(11, "had long value <11>"), - new HasDescription("has long value less than <11>") + new Fails<>(11, "had long value <11l>"), + new HasDescription("has long value less than <11l>") )); } diff --git a/confidence-core/src/test/java/org/saynotobugs/confidence/quality/object/UnsafeInstanceOfTest.java b/confidence-core/src/test/java/org/saynotobugs/confidence/quality/object/UnsafeInstanceOfTest.java index 48f7c826..001d0247 100644 --- a/confidence-core/src/test/java/org/saynotobugs/confidence/quality/object/UnsafeInstanceOfTest.java +++ b/confidence-core/src/test/java/org/saynotobugs/confidence/quality/object/UnsafeInstanceOfTest.java @@ -53,7 +53,7 @@ void testSubClassDelegate() assertThat(new UnsafeInstanceOf<>(Iterable.class, new That<>(new Iterates<>(1, "abc", true))), new AllOf<>( new Passes<>(new Seq(1, "abc", true), new Seq(1, "abc", true)), - new Fails<>(new Seq(1.1, "abc", true), "(1) that iterated [ 0: <1.1>\n ... ]"), + new Fails<>(new Seq(1.1, "abc", true), "(1) that iterated [ 0: <1.1d>\n ... ]"), new Fails<>(2, "(0) instance of "), new Fails<>("string", "(0) instance of "), new Fails<>(new Object(), "(0) instance of "), diff --git a/confidence-json/src/test/java/org/saynotobugs/confidence/json/quality/ArrayTest.java b/confidence-json/src/test/java/org/saynotobugs/confidence/json/quality/ArrayTest.java index 600249aa..48e730ac 100644 --- a/confidence-json/src/test/java/org/saynotobugs/confidence/json/quality/ArrayTest.java +++ b/confidence-json/src/test/java/org/saynotobugs/confidence/json/quality/ArrayTest.java @@ -130,7 +130,7 @@ void testNumberArray() new Fails<>(mock("not an array", JsonElementAdapter.class, with(JsonElementAdapter::asArray, returning(new Absent<>()))), "array not an array"), - new HasDescription("array { has length <2>\n and\n { <0>: <1.2>\n and\n <1>: <5> } }") + new HasDescription("array { has length <2>\n and\n { <0>: <1.2d>\n and\n <1>: <5> } }") )); } diff --git a/confidence-json/src/test/java/org/saynotobugs/confidence/json/quality/NumberTest.java b/confidence-json/src/test/java/org/saynotobugs/confidence/json/quality/NumberTest.java index 7428a172..c1796396 100644 --- a/confidence-json/src/test/java/org/saynotobugs/confidence/json/quality/NumberTest.java +++ b/confidence-json/src/test/java/org/saynotobugs/confidence/json/quality/NumberTest.java @@ -113,11 +113,11 @@ void testWithLong() with(JsonElementAdapter::asNumber, returning(new Present<>(3L))))), new Fails<>(mock("mismatching number", JsonElementAdapter.class, with(JsonElementAdapter::asNumber, returning(new Present<>(4L)))), - "<4>"), + "<4l>"), new Fails<>(mock("no number", JsonElementAdapter.class, with(JsonElementAdapter::asNumber, returning(new Absent<>()))), "not a number"), - new HasDescription("<3>") + new HasDescription("<3l>") )); } diff --git a/confidence-rxjava3/src/main/java/org/saynotobugs/confidence/rxjava3/rxexpectation/internal/IsComplete.java b/confidence-rxjava3/src/main/java/org/saynotobugs/confidence/rxjava3/rxexpectation/internal/IsComplete.java index b46b534f..813649aa 100644 --- a/confidence-rxjava3/src/main/java/org/saynotobugs/confidence/rxjava3/rxexpectation/internal/IsComplete.java +++ b/confidence-rxjava3/src/main/java/org/saynotobugs/confidence/rxjava3/rxexpectation/internal/IsComplete.java @@ -18,9 +18,9 @@ package org.saynotobugs.confidence.rxjava3.rxexpectation.internal; -import org.saynotobugs.confidence.description.NumberDescription; import org.saynotobugs.confidence.description.Spaced; import org.saynotobugs.confidence.description.Text; +import org.saynotobugs.confidence.description.ToStringDescription; import org.saynotobugs.confidence.quality.composite.QualityComposition; import org.saynotobugs.confidence.quality.object.Satisfies; import org.saynotobugs.confidence.rxjava3.RxTestAdapter; @@ -31,7 +31,7 @@ public final class IsComplete extends QualityComposition> public IsComplete() { super(new Satisfies<>(actual -> actual.completions() == 1, - ackSubscriber -> new Spaced(new Text("completed"), new NumberDescription(ackSubscriber.completions()), new Text("times")), + ackSubscriber -> new Spaced(new Text("completed"), new ToStringDescription(ackSubscriber.completions()), new Text("times")), new Text("completes exactly once"))); } } diff --git a/confidence-rxjava3/src/test/java/org/saynotobugs/confidence/rxjava3/quality/TimedTest.java b/confidence-rxjava3/src/test/java/org/saynotobugs/confidence/rxjava3/quality/TimedTest.java index ea9e6b6f..d5ed2c83 100644 --- a/confidence-rxjava3/src/test/java/org/saynotobugs/confidence/rxjava3/quality/TimedTest.java +++ b/confidence-rxjava3/src/test/java/org/saynotobugs/confidence/rxjava3/quality/TimedTest.java @@ -41,9 +41,9 @@ void testInstantAndValueQuality() new AllOf<>( new Passes<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 123, TimeUnit.MILLISECONDS)), new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(789, 123, TimeUnit.MILLISECONDS), "{ ...\n had value <789> }"), - new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 789, TimeUnit.MILLISECONDS), "{ had time of <789> millis\n ... }"), - new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(987, 789, TimeUnit.MILLISECONDS), "{ had time of <789> millis\n and\n had value <987> }"), - new HasDescription("{ has time of <123> millis\n and\n has value <456> }")) + new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 789, TimeUnit.MILLISECONDS), "{ had time of <789l> millis\n ... }"), + new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(987, 789, TimeUnit.MILLISECONDS), "{ had time of <789l> millis\n and\n had value <987> }"), + new HasDescription("{ has time of <123l> millis\n and\n has value <456> }")) ); } @@ -55,9 +55,9 @@ void testInstantAndValue() new AllOf<>( new Passes<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 123, TimeUnit.MILLISECONDS)), new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(789, 123, TimeUnit.MILLISECONDS), "{ ...\n had value <789> }"), - new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 789, TimeUnit.MILLISECONDS), "{ had time of <789> millis\n ... }"), - new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(987, 789, TimeUnit.MILLISECONDS), "{ had time of <789> millis\n and\n had value <987> }"), - new HasDescription("{ has time of <123> millis\n and\n has value <456> }")) + new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 789, TimeUnit.MILLISECONDS), "{ had time of <789l> millis\n ... }"), + new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(987, 789, TimeUnit.MILLISECONDS), "{ had time of <789l> millis\n and\n had value <987> }"), + new HasDescription("{ has time of <123l> millis\n and\n has value <456> }")) ); } @@ -69,9 +69,9 @@ void testDurationAndValueQuality() new AllOf<>( new Passes<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 123, TimeUnit.MILLISECONDS)), new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(789, 123, TimeUnit.MILLISECONDS), "{ ...\n had value <789> }"), - new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 789, TimeUnit.MILLISECONDS), "{ had time of <789> millis\n ... }"), - new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(987, 789, TimeUnit.MILLISECONDS), "{ had time of <789> millis\n and\n had value <987> }"), - new HasDescription("{ has time of <123> millis\n and\n has value <456> }")) + new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 789, TimeUnit.MILLISECONDS), "{ had time of <789l> millis\n ... }"), + new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(987, 789, TimeUnit.MILLISECONDS), "{ had time of <789l> millis\n and\n had value <987> }"), + new HasDescription("{ has time of <123l> millis\n and\n has value <456> }")) ); } @@ -83,9 +83,9 @@ void testDurationAndValue() new AllOf<>( new Passes<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 123, TimeUnit.MILLISECONDS)), new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(789, 123, TimeUnit.MILLISECONDS), "{ ...\n had value <789> }"), - new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 789, TimeUnit.MILLISECONDS), "{ had time of <789> millis\n ... }"), - new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(987, 789, TimeUnit.MILLISECONDS), "{ had time of <789> millis\n and\n had value <987> }"), - new HasDescription("{ has time of <123> millis\n and\n has value <456> }")) + new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 789, TimeUnit.MILLISECONDS), "{ had time of <789l> millis\n ... }"), + new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(987, 789, TimeUnit.MILLISECONDS), "{ had time of <789l> millis\n and\n had value <987> }"), + new HasDescription("{ has time of <123l> millis\n and\n has value <456> }")) ); } @@ -97,9 +97,9 @@ void testLongAndValueQuality() new AllOf<>( new Passes<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 123, TimeUnit.MILLISECONDS)), new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(789, 123, TimeUnit.MILLISECONDS), "{ ...\n had value <789> }"), - new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 789, TimeUnit.MILLISECONDS), "{ had time of <789> millis\n ... }"), - new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(987, 789, TimeUnit.MILLISECONDS), "{ had time of <789> millis\n and\n had value <987> }"), - new HasDescription("{ has time of <123> millis\n and\n has value <456> }")) + new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 789, TimeUnit.MILLISECONDS), "{ had time of <789l> millis\n ... }"), + new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(987, 789, TimeUnit.MILLISECONDS), "{ had time of <789l> millis\n and\n had value <987> }"), + new HasDescription("{ has time of <123l> millis\n and\n has value <456> }")) ); } @@ -111,9 +111,9 @@ void testLongAndValue() new AllOf<>( new Passes<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 123, TimeUnit.MILLISECONDS)), new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(789, 123, TimeUnit.MILLISECONDS), "{ ...\n had value <789> }"), - new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 789, TimeUnit.MILLISECONDS), "{ had time of <789> millis\n ... }"), - new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(987, 789, TimeUnit.MILLISECONDS), "{ had time of <789> millis\n and\n had value <987> }"), - new HasDescription("{ has time of <123> millis\n and\n has value <456> }")) + new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(456, 789, TimeUnit.MILLISECONDS), "{ had time of <789l> millis\n ... }"), + new Fails<>(new io.reactivex.rxjava3.schedulers.Timed<>(987, 789, TimeUnit.MILLISECONDS), "{ had time of <789l> millis\n and\n had value <987> }"), + new HasDescription("{ has time of <123l> millis\n and\n has value <456> }")) ); } } \ No newline at end of file