fluentasserts.core.operations.between 52/56(92%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
20116
21116
22116
230
24116
25116
26116
270
280
29116
30116
31116
320
330
340
350
36116
370
380
390
400
410
429
430
449
459
469
470
480
499
509
519
520
539
540
550
560
570
589
590
609
610
620
630
640
659
660
679
689
699
700
710
729
739
749
750
769
770
780
790
800
819
820
839
840
850
860
87268
88268
890
90134
91134
92251
930
94134
950
960
97268
980
990
1000
1010
102134
1030
104134
10574
10629
1070
10829
10914
11014
1110
1120
1130
11429
11515
11615
1170
1180
1190
12029
1210
12229
1230
12460
12515
1260
1270
128134
1290
module fluentasserts.core.operations.between; import fluentasserts.core.results; import fluentasserts.core.evaluation; import fluentasserts.core.lifecycle; import std.conv; import std.datetime; version(unittest) { import fluentasserts.core.expect; } static immutable betweenDescription = "Asserts that the target is a number or a date greater than or equal to the given number or date start, " ~ "and less than or equal to the given number or date finish respectively. However, it's often best to assert that the target is equal to its expected value."; /// IResult[] between(T)(ref Evaluation evaluation) @safe nothrow { evaluation.message.addText(" and "); evaluation.message.addValue(evaluation.expectedValue.meta["1"]); evaluation.message.addText(". "); T currentValue; T limit1; T limit2; try { currentValue = evaluation.currentValue.strValue.to!T; limit1 = evaluation.expectedValue.strValue.to!T; limit2 = evaluation.expectedValue.meta["1"].to!T; } catch(Exception e) { return [ new MessageResult("Can't convert the values to " ~ T.stringof) ]; } return betweenResults(currentValue, limit1, limit2, evaluation); } /// IResult[] betweenDuration(ref Evaluation evaluation) @safe nothrow { evaluation.message.addText(" and "); Duration currentValue; Duration limit1; Duration limit2; try { currentValue = dur!"nsecs"(evaluation.currentValue.strValue.to!size_t); limit1 = dur!"nsecs"(evaluation.expectedValue.strValue.to!size_t); limit2 = dur!"nsecs"(evaluation.expectedValue.meta["1"].to!size_t); evaluation.message.addValue(limit2.to!string); } catch(Exception e) { return [ new MessageResult("Can't convert the values to Duration") ]; } evaluation.message.addText(". "); return betweenResults(currentValue, limit1, limit2, evaluation); } /// IResult[] betweenSysTime(ref Evaluation evaluation) @safe nothrow { evaluation.message.addText(" and "); SysTime currentValue; SysTime limit1; SysTime limit2; try { currentValue = SysTime.fromISOExtString(evaluation.currentValue.strValue); limit1 = SysTime.fromISOExtString(evaluation.expectedValue.strValue); limit2 = SysTime.fromISOExtString(evaluation.expectedValue.meta["1"]); evaluation.message.addValue(limit2.toISOExtString); } catch(Exception e) { return [ new MessageResult("Can't convert the values to Duration") ]; } evaluation.message.addText(". "); return betweenResults(currentValue, limit1, limit2, evaluation); } private IResult[] betweenResults(T)(T currentValue, T limit1, T limit2, ref Evaluation evaluation) { T min = limit1 < limit2 ? limit1 : limit2; T max = limit1 > limit2 ? limit1 : limit2; auto isLess = currentValue <= min; auto isGreater = currentValue >= max; auto isBetween = !isLess && !isGreater; string interval; try { interval = "a value " ~ (evaluation.isNegated ? "outside" : "inside") ~ " (" ~ min.to!string ~ ", " ~ max.to!string ~ ") interval"; } catch(Exception) { interval = "a value " ~ (evaluation.isNegated ? "outside" : "inside") ~ " the interval"; } IResult[] results = []; if(!evaluation.isNegated) { if(!isBetween) { evaluation.message.addValue(evaluation.currentValue.niceValue); if(isGreater) { evaluation.message.addText(" is greater than or equal to "); try evaluation.message.addValue(max.to!string); catch(Exception) {} } if(isLess) { evaluation.message.addText(" is less than or equal to "); try evaluation.message.addValue(min.to!string); catch(Exception) {} } evaluation.message.addText("."); results ~= new ExpectedActualResult(interval, evaluation.currentValue.niceValue); } } else if(isBetween) { results ~= new ExpectedActualResult(interval, evaluation.currentValue.niceValue); } return results; }