10203040506070809010011012013014015016017018019882002188228823024025882688270280290300318832033883403503603703863904064164264364404504664764804965065105205305405565605765805906006106286306486586686786806907087187207307407507687707887908008108210283458408508610287628808909040914092093409409540961497149809926100261010102010340104401050106401070 module fluentasserts.core.operations.greaterThan; 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 greaterThanDescription = "Asserts that the tested value is greater than the tested value. However, it's often best to assert that the target is equal to its expected value."; /// IResult[] greaterThan(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 greaterThanResults(result, evaluation.expectedValue.strValue, evaluation.currentValue.strValue, evaluation); } /// IResult[] greaterThanDuration(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 greaterThanResults(result, niceExpectedValue, niceCurrentValue, evaluation); } /// IResult[] greaterThanSysTime(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 greaterThanResults(result, evaluation.expectedValue.strValue, evaluation.currentValue.strValue, evaluation); } private IResult[] greaterThanResults(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 greater than "); results ~= new ExpectedActualResult("less than or equal to " ~ niceExpectedValue, niceCurrentValue); } else { evaluation.message.addText(" is less than or equal to "); results ~= new ExpectedActualResult("greater than " ~ niceExpectedValue, niceCurrentValue); } evaluation.message.addValue(niceExpectedValue); evaluation.message.addText("."); return results; }
module fluentasserts.core.operations.greaterThan; 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 greaterThanDescription = "Asserts that the tested value is greater than the tested value. However, it's often best to assert that the target is equal to its expected value."; /// IResult[] greaterThan(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 greaterThanResults(result, evaluation.expectedValue.strValue, evaluation.currentValue.strValue, evaluation); } /// IResult[] greaterThanDuration(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 greaterThanResults(result, niceExpectedValue, niceCurrentValue, evaluation); } /// IResult[] greaterThanSysTime(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 greaterThanResults(result, evaluation.expectedValue.strValue, evaluation.currentValue.strValue, evaluation); } private IResult[] greaterThanResults(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 greater than "); results ~= new ExpectedActualResult("less than or equal to " ~ niceExpectedValue, niceCurrentValue); } else { evaluation.message.addText(" is less than or equal to "); results ~= new ExpectedActualResult("greater than " ~ niceExpectedValue, niceCurrentValue); } evaluation.message.addValue(niceExpectedValue); evaluation.message.addText("."); return results; }