test.operations.greaterThan 0/0(100%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
630
640
650
660
670
680
690
700
710
720
730
740
750
760
770
780
790
800
810
820
830
840
850
860
870
880
890
900
910
920
930
940
950
960
970
980
990
1000
1010
1020
1030
1040
1050
1060
1070
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1190
1200
1210
1220
1230
1240
1250
1260
1270
1280
1290
1300
1310
1320
1330
1340
1350
1360
1370
1380
1390
1400
1410
1420
1430
1440
1450
1460
1470
module test.operations.greaterThan; import fluentasserts.core.expect; import fluent.asserts; import trial.discovery.spec; import std.string; import std.conv; import std.meta; import std.datetime; alias s = Spec!({ alias NumericTypes = AliasSeq!(byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real); static foreach(Type; NumericTypes) { describe("using " ~ Type.stringof ~ " values", { Type smallValue; Type largeValue; before({ smallValue = cast(Type) 40; largeValue = cast(Type) 50; }); it("should be able to compare two values", { expect(largeValue).to.be.greaterThan(smallValue); expect(largeValue).to.be.above(smallValue); }); it("should be able to compare two values using negation", { expect(smallValue).not.to.be.greaterThan(largeValue); expect(smallValue).not.to.be.above(largeValue); }); it("should throw a detailed error when the number is compared with itself", { auto msg = ({ expect(smallValue).to.be.greaterThan(smallValue); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(smallValue.to!string ~ " should be greater than " ~ smallValue.to!string ~ ". " ~ smallValue.to!string ~ " is less than or equal to " ~ smallValue.to!string ~ "."); msg.split("\n")[2].strip.should.equal("Expected:greater than " ~ smallValue.to!string); msg.split("\n")[3].strip.should.equal("Actual:" ~ smallValue.to!string); }); it("should throw a detailed error when the comparison fails", { auto msg = ({ expect(smallValue).to.be.greaterThan(largeValue); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(smallValue.to!string ~ " should be greater than " ~ largeValue.to!string ~ ". " ~ smallValue.to!string ~ " is less than or equal to " ~ largeValue.to!string ~ "."); msg.split("\n")[2].strip.should.equal("Expected:greater than " ~ largeValue.to!string); msg.split("\n")[3].strip.should.equal("Actual:" ~ smallValue.to!string); }); it("should throw a detailed error when the negated coparison fails", { auto msg = ({ expect(largeValue).not.to.be.greaterThan(smallValue); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(largeValue.to!string ~ " should not be greater than " ~ smallValue.to!string ~ ". " ~ largeValue.to!string ~ " is greater than " ~ smallValue.to!string ~ "."); msg.split("\n")[2].strip.should.equal("Expected:less than or equal to " ~ smallValue.to!string); msg.split("\n")[3].strip.should.equal("Actual:" ~ largeValue.to!string); }); }); } describe("using Duration values", { Duration smallValue; Duration largeValue; before({ smallValue = 40.seconds; largeValue = 41.seconds; }); it("should be able to compare two values", { expect(largeValue).to.be.greaterThan(smallValue); expect(largeValue).to.be.above(smallValue); }); it("should be able to compare two values using negation", { expect(smallValue).not.to.be.greaterThan(largeValue); expect(smallValue).not.to.be.above(largeValue); }); it("should throw a detailed error when the number is compared with itself", { auto msg = ({ expect(smallValue).to.be.greaterThan(smallValue); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(smallValue.to!string ~ " should be greater than " ~ smallValue.to!string ~ ". " ~ smallValue.to!string ~ " is less than or equal to " ~ smallValue.to!string ~ "."); msg.split("\n")[2].strip.should.equal("Expected:greater than " ~ smallValue.to!string); msg.split("\n")[3].strip.should.equal("Actual:" ~ smallValue.to!string); }); it("should throw a detailed error when the negated comparison fails", { auto msg = ({ expect(largeValue).not.to.be.greaterThan(smallValue); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(largeValue.to!string ~ " should not be greater than " ~ smallValue.to!string ~ ". " ~ largeValue.to!string ~ " is greater than " ~ smallValue.to!string ~ "."); msg.split("\n")[2].strip.should.equal("Expected:less than or equal to " ~ smallValue.to!string); msg.split("\n")[3].strip.should.equal("Actual:" ~ largeValue.to!string); }); }); describe("using SysTime values", { SysTime smallValue; SysTime largeValue; before({ smallValue = Clock.currTime; largeValue = smallValue + 4.seconds; }); it("should be able to compare two values", { expect(largeValue).to.be.greaterThan(smallValue); expect(largeValue).to.be.above(smallValue); }); it("should be able to compare two values using negation", { expect(smallValue).not.to.be.greaterThan(largeValue); expect(smallValue).not.to.be.above(largeValue); }); it("should throw a detailed error when the number is compared with itself", { auto msg = ({ expect(smallValue).to.be.greaterThan(smallValue); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(smallValue.toISOExtString ~ " should be greater than " ~ smallValue.toISOExtString ~ ". " ~ smallValue.toISOExtString ~ " is less than or equal to " ~ smallValue.toISOExtString ~ "."); msg.split("\n")[2].strip.should.equal("Expected:greater than " ~ smallValue.toISOExtString); msg.split("\n")[3].strip.should.equal("Actual:" ~ smallValue.toISOExtString); }); it("should throw a detailed error when the negated comparison fails", { auto msg = ({ expect(largeValue).not.to.be.greaterThan(smallValue); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(largeValue.toISOExtString ~ " should not be greater than " ~ smallValue.toISOExtString ~ ". " ~ largeValue.toISOExtString ~ " is greater than " ~ smallValue.toISOExtString ~ "."); msg.split("\n")[2].strip.should.equal("Expected:less than or equal to " ~ smallValue.toISOExtString); msg.split("\n")[3].strip.should.equal("Actual:" ~ largeValue.toISOExtString); }); }); });