1 module fluentasserts.core.operations.greaterThan; 2 3 import fluentasserts.core.results; 4 import fluentasserts.core.evaluation; 5 6 import fluentasserts.core.lifecycle; 7 8 import std.conv; 9 import std.datetime; 10 11 version(unittest) { 12 import fluentasserts.core.expect; 13 } 14 15 /// 16 IResult[] greaterThan(T)(ref Evaluation evaluation) @safe nothrow { 17 evaluation.message.addText("."); 18 19 T expectedValue; 20 T currentValue; 21 22 try { 23 expectedValue = evaluation.expectedValue.strValue.to!T; 24 currentValue = evaluation.currentValue.strValue.to!T; 25 } catch(Exception e) { 26 return [ new MessageResult("Can't convert the values to " ~ T.stringof) ]; 27 } 28 29 auto result = currentValue > expectedValue; 30 31 return greaterThanResults(result, evaluation.expectedValue.strValue, evaluation.currentValue.strValue, evaluation); 32 } 33 34 /// 35 IResult[] greaterThanDuration(ref Evaluation evaluation) @safe nothrow { 36 evaluation.message.addText("."); 37 38 Duration expectedValue; 39 Duration currentValue; 40 string niceExpectedValue; 41 string niceCurrentValue; 42 43 try { 44 expectedValue = dur!"nsecs"(evaluation.expectedValue.strValue.to!size_t); 45 currentValue = dur!"nsecs"(evaluation.currentValue.strValue.to!size_t); 46 47 niceExpectedValue = expectedValue.to!string; 48 niceCurrentValue = currentValue.to!string; 49 } catch(Exception e) { 50 return [ new MessageResult("Can't convert the values to Duration") ]; 51 } 52 53 auto result = currentValue > expectedValue; 54 55 return greaterThanResults(result, niceExpectedValue, niceCurrentValue, evaluation); 56 } 57 58 /// 59 IResult[] greaterThanSysTime(ref Evaluation evaluation) @safe nothrow { 60 evaluation.message.addText("."); 61 62 SysTime expectedValue; 63 SysTime currentValue; 64 string niceExpectedValue; 65 string niceCurrentValue; 66 67 try { 68 expectedValue = SysTime.fromISOExtString(evaluation.expectedValue.strValue); 69 currentValue = SysTime.fromISOExtString(evaluation.currentValue.strValue); 70 } catch(Exception e) { 71 return [ new MessageResult("Can't convert the values to SysTime") ]; 72 } 73 74 auto result = currentValue > expectedValue; 75 76 return greaterThanResults(result, evaluation.expectedValue.strValue, evaluation.currentValue.strValue, evaluation); 77 } 78 79 private IResult[] greaterThanResults(bool result, string niceExpectedValue, string niceCurrentValue, ref Evaluation evaluation) @safe nothrow { 80 if(evaluation.isNegated) { 81 result = !result; 82 } 83 84 if(result) { 85 return []; 86 } 87 88 evaluation.message.addText(" "); 89 evaluation.message.addValue(evaluation.currentValue.niceValue); 90 91 IResult[] results = []; 92 93 if(evaluation.isNegated) { 94 evaluation.message.addText(" is greater than "); 95 results ~= new ExpectedActualResult("less than or equal to " ~ niceExpectedValue, niceCurrentValue); 96 } else { 97 evaluation.message.addText(" is less than or equal to "); 98 results ~= new ExpectedActualResult("greater than " ~ niceExpectedValue, niceCurrentValue); 99 } 100 101 evaluation.message.addValue(niceExpectedValue); 102 evaluation.message.addText("."); 103 104 return results; 105 }