fluentasserts.core.operations.lessThan 42/45(93%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
1977
200
2177
2277
230
240
2577
2677
270
280
290
300
3177
320
3377
340
350
360
370
388
390
408
418
428
438
440
450
468
478
480
498
508
510
520
530
540
558
560
578
580
590
600
610
626
630
646
656
666
676
680
690
706
716
720
730
740
750
766
770
786
790
800
810
8291
8344
840
850
8691
8762
880
890
9029
9129
920
9329
940
9529
9614
9714
980
9915
10015
1010
1020
10329
10429
1050
10629
1070
module fluentasserts.core.operations.lessThan; 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 lessThanDescription = "Asserts that the tested value is less than the tested value. However, it's often best to assert that the target is equal to its expected value."; /// IResult[] lessThan(T)(ref Evaluation evaluation) @safe nothrow { evaluation.message.addText("."); T expectedValue; T currentValue; try { expectedValue = evaluation.expectedValue.strValue.to!T; currentValue = evaluation.currentValue.strValue.to!T; } catch(Exception e) { return [ new MessageResult("Can't convert the values to " ~ T.stringof) ]; } auto result = currentValue < expectedValue; return lessThanResults(result, evaluation.expectedValue.strValue, evaluation.currentValue.strValue, evaluation); } /// IResult[] lessThanDuration(ref Evaluation evaluation) @safe nothrow { evaluation.message.addText("."); Duration expectedValue; Duration currentValue; string niceExpectedValue; string niceCurrentValue; try { expectedValue = dur!"nsecs"(evaluation.expectedValue.strValue.to!size_t); currentValue = dur!"nsecs"(evaluation.currentValue.strValue.to!size_t); niceExpectedValue = expectedValue.to!string; niceCurrentValue = currentValue.to!string; } catch(Exception e) { return [ new MessageResult("Can't convert the values to Duration") ]; } auto result = currentValue < expectedValue; return lessThanResults(result, niceExpectedValue, niceCurrentValue, evaluation); } /// IResult[] lessThanSysTime(ref Evaluation evaluation) @safe nothrow { evaluation.message.addText("."); SysTime expectedValue; SysTime currentValue; string niceExpectedValue; string niceCurrentValue; try { expectedValue = SysTime.fromISOExtString(evaluation.expectedValue.strValue); currentValue = SysTime.fromISOExtString(evaluation.currentValue.strValue); } catch(Exception e) { return [ new MessageResult("Can't convert the values to SysTime") ]; } auto result = currentValue < expectedValue; return lessThanResults(result, evaluation.expectedValue.strValue, evaluation.currentValue.strValue, evaluation); } private IResult[] lessThanResults(bool result, string niceExpectedValue, string niceCurrentValue, ref Evaluation evaluation) @safe nothrow { if(evaluation.isNegated) { result = !result; } if(result) { return []; } evaluation.message.addText(" "); evaluation.message.addValue(evaluation.currentValue.niceValue); IResult[] results = []; if(evaluation.isNegated) { evaluation.message.addText(" is less than "); results ~= new ExpectedActualResult("greater than or equal to " ~ niceExpectedValue, niceCurrentValue); } else { evaluation.message.addText(" is greater than or equal to "); results ~= new ExpectedActualResult("less than " ~ niceExpectedValue, niceCurrentValue); } evaluation.message.addValue(niceExpectedValue); evaluation.message.addText("."); return results; }