test.operations.approximately 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
module test.operations.approximately; import fluentasserts.core.expect; import fluent.asserts; import trial.discovery.spec; import std.string; import std.conv; import std.meta; import std.algorithm; import std.range; alias s = Spec!({ alias IntTypes = AliasSeq!(byte, ubyte, short, ushort, int, uint, long, ulong); alias FPTypes = AliasSeq!(float, double, real); static foreach(Type; FPTypes) { describe("using " ~ Type.stringof, { Type testValue; before({ testValue = cast(Type) 0.351; }); it("should check approximately compare two numbers", { expect(testValue).to.be.approximately(0.35, 0.01); }); it("should check approximately with a delta of 0.00001", { expect(testValue).to.not.be.approximately(0.35, 0.00001); }); it("should check approximately with a delta of 0.001", { expect(testValue).to.not.be.approximately(0.35, 0.001); }); it("should show a detailed error message when two numbers should be approximatly equal but they are not", { auto msg = ({ expect(testValue).to.be.approximately(0.35, 0.0001); }).should.throwException!TestException.msg; msg.should.contain("Expected:0.35±0.0001"); msg.should.contain("Actual:0.351"); msg.should.not.contain("Missing:"); }); it("should show a detailed error message when two numbers are approximatly equal but they should not", { auto msg = ({ expect(testValue).to.not.be.approximately(testValue, 0.0001); }).should.throwException!TestException.msg; msg.should.contain("Expected:not " ~ testValue.to!string ~ "±0.0001"); }); }); describe("using " ~ Type.stringof ~ " lists", { Type[] testValues; before({ testValues = [cast(Type) 0.350, cast(Type) 0.501, cast(Type) 0.341]; }); it("should approximately compare two lists", { expect(testValues).to.be.approximately([0.35, 0.50, 0.34], 0.01); }); it("should approximately with a range of 0.00001 compare two lists that are not equal", { expect(testValues).to.not.be.approximately([0.35, 0.50, 0.34], 0.00001); }); it("should approximately with a range of 0.001 compare two lists that are not equal", { expect(testValues).to.not.be.approximately([0.35, 0.50, 0.34], 0.001); }); it("should approximately with a range of 0.001 compare two lists with different lengths", { expect(testValues).to.not.be.approximately([0.35, 0.50], 0.001); }); it("should show a detailed error message when two lists should be approximatly equal but they are not", { auto msg = ({ expect(testValues).to.be.approximately([0.35, 0.50, 0.34], 0.0001); }).should.throwException!TestException.msg; msg.should.contain("Expected:[0.35±0.0001, 0.5±0.0001, 0.34±0.0001]"); msg.should.contain("Missing:[0.501±0.0001, 0.341±0.0001]"); }); it("should show a detailed error message when two lists are approximatly equal but they should not", { auto msg = ({ expect(testValues).to.not.be.approximately(testValues, 0.0001); }).should.throwException!TestException.msg; msg.should.contain("Expected:not [0.35±0.0001, 0.501±0.0001, 0.341±0.0001]"); }); }); } });