diff --git a/src/parser.js b/src/parser.js index 74ce483..52cf135 100644 --- a/src/parser.js +++ b/src/parser.js @@ -165,8 +165,8 @@ function parser(options) { } else if (ascii.startsWith("binom")) { const [, , group, , after] = syntax.splitNextGroup(ascii); const [a, b] = colsplit(group); - const over = parsegroup(a.trim()); - const under = parsegroup(b.trim()); + const over = parsegroup(a.trim()) || mrow(""); + const under = parsegroup(b.trim()) || mrow(""); el = mfenced(mfrac(over + under, { linethickness: 0 }), { open: "(", diff --git a/test/groupings.js b/test/groupings.js index ed761ab..5cfa55c 100644 --- a/test/groupings.js +++ b/test/groupings.js @@ -79,6 +79,32 @@ test("Complex groupings", t => { ); }); +test("Binom function", t => { + t.is( + a2ml("binom(n, k)"), + 'nk' + ); +}); + +test("Binom function accepts expressions", t => { + t.is( + a2ml("binom(a, b + c)"), + 'ab+c' + ); +}); + +test("Missing argument in the binom function", t => { + t.is( + a2ml("binom(a,)"), + 'a' + ); + + t.is( + a2ml("binom(,b)"), + 'b' + ); +}); + test("Simplify polynomials", t => { t.is( a2ml("(x+y)(x-y) = x^2-y^2"), @@ -113,3 +139,10 @@ test("Average over time", t => { 'Vt2=limT1T-T2T2Vt2dt' ); }); + +test("The binomial coefficient", t => { + t.is( + a2ml("binom(n, k) = n! / (n-k)!k!"), + 'nk=n!n-k!k!' + ); +}); diff --git a/test/roots.js b/test/roots.js index 539c5ad..db7b39c 100644 --- a/test/roots.js +++ b/test/roots.js @@ -14,20 +14,6 @@ test("Omits brackets in roots", t => { t.is(a2ml("root(3)(2)"), "23"); }); -test("Display the binomial coefficient", t => { - t.is( - a2ml("binom(n, k)"), - 'nk' - ); -}); - -test("Displays the whole terms of the binomial coefficient", t => { - t.is( - a2ml("binom(a, b + c)"), - 'ab+c' - ); -}); - test("Allows empty roots", t => { t.is(a2ml("sqrt"), ""); t.is( @@ -73,10 +59,3 @@ test("Continued square root", t => { "1+1+1+1+1+1+1+" ); }); - -test("The binomial coefficient", t => { - t.is( - a2ml("binom(n, k) = n! / (n-k)!k!"), - 'nk=n!n-k!k!' - ); -});