fluentasserts.core.operations.between 31/56(55%) 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
421
430
441
451
461
470
480
491
501
511
520
531
540
550
560
570
581
590
601
610
620
630
640
654
660
674
684
694
700
710
724
734
744
750
764
770
780
790
800
814
820
834
840
850
860
8710
8810
890
905
915
9210
930
945
950
960
9710
980
990
1000
1010
1025
1030
1045
1055
1060
1070
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1190
1200
1210
1220
1230
1240
1250
1260
1270
1285
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; }