Skip to content

Commit 6cb3908

Browse files
authored
Merge pull request #901 from sys27/bugfix/fact-formatting
#895 - Incorrect formatting of factorial.
2 parents 6519bda + 907a419 commit 6cb3908

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

xFunc.Maths/Analyzers/Formatters/CommonFormatter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ public virtual string Analyze(Exp exp)
103103

104104
/// <inheritdoc />
105105
public virtual string Analyze(Fact exp)
106-
=> ToString(exp, "{0}!");
106+
{
107+
if (exp.Argument is BinaryExpression)
108+
return ToString(exp, "({0})!");
109+
110+
return ToString(exp, "{0}!");
111+
}
107112

108113
/// <inheritdoc />
109114
public virtual string Analyze(Floor exp)

xFunc.Tests/Analyzers/Formatters/CommonFormatterTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ public void FactToStringTest()
124124
Assert.That(exp.ToString(), Is.EqualTo("5!"));
125125
}
126126

127+
[Test]
128+
public void FactWithBinaryToStringTest()
129+
{
130+
var exp = new Fact(new Add(Number.One, Number.Two));
131+
132+
Assert.That(exp.ToString(), Is.EqualTo("(1 + 2)!"));
133+
}
134+
127135
[Test]
128136
public void FloorToStringTest()
129137
{

0 commit comments

Comments
 (0)