/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* * Most of the formula commands in this file came from: * http://wiki.openoffice.org/wiki/Template:Math_commands_reference * which was licensed with a * Creative Common Attribution 3.0 license and written by: * Jeanweber, Weegreenblobbie, Jdpipe, TJFrazier, Ysangkok, B michaelsen, Spellbreaker
*/
void Test::SimpleUnaryOp()
{
parseandparseagain("+1", "Positive (plus)");
parseandparseagain("-2", "Negative (minus)");
parseandparseagain("+-3", "Plus/minus");
parseandparseagain("-+4", "Minus/plus");
parseandparseagain("neg a", "Boolean 'not'");
parseandparseagain("fact a", "Factorial");
parseandparseagain("- { 1 over 2 }", "BinVer in Unary 1");
ParseAndCheck("- { 1 over 2 }", "- { 1 over 2 }", "BinVer in Unary 1");
parseandparseagain("{- { 1 over 2 } }", "BinVer in Unary 2");
parseandparseagain("- 1 over 2", "Unary in BinVer as numerator 1");
parseandparseagain("{ - 1 } over 2", "Unary in BinVer as numerator 2");
parseandparseagain("1 over - 2", "Unary in BinVer as denominator 1");
parseandparseagain("1 over { - 2 }", "Unary in BinVer as denominator 2");
parseandparseagain("2 { - 1 over 2 }", "Mixed number with Unary in denominator 1");
parseandparseagain("2 { - 1 } over 2", "Mixed number with Unary in denominator 2");
parseandparseagain("- 1 + 2", "Unary in BinHor");
}
void Test::SimpleBinaryOp()
{
parseandparseagain("a + b", "Addition");
parseandparseagain("a cdot b", "Dot product");
parseandparseagain("a times b", "Cross product");
parseandparseagain("a * b", "Multiplication (asterisk)");
parseandparseagain("a and b", "Boolean 'and'");
parseandparseagain("a - b", "Subtraction");
parseandparseagain("a over b", "Division (as a fraction)");
parseandparseagain("a div b", "Division (as an operator)");
parseandparseagain("a / b", "Division (with a slash)");
parseandparseagain("a or b", "Boolean 'or'");
parseandparseagain("a circ b", "Concatenation");
}
void Test::SimpleRelationalOp()
{
parseandparseagain("a = b", "Is equal");
parseandparseagain("a <> b", "Is not equal");
parseandparseagain("a approx 2", "Approximately");
parseandparseagain("a divides b", "Divides");
parseandparseagain("a ndivides b", "Does not divide");
parseandparseagain("a < 2", "Less than");
parseandparseagain("a > 2", "Greater than");
parseandparseagain("a simeq b", "Similar to or equal");
parseandparseagain("a parallel b", "Parallel");
parseandparseagain("a ortho b", "Orthogonal to");
parseandparseagain("a leslant b", "Less than or equal to");
parseandparseagain("a geslant b", "Greater than or equal to");
parseandparseagain("a sim b", "Similar to");
parseandparseagain("a equiv b", "Congruent");
parseandparseagain("a <= b", "Less than or equal to");
parseandparseagain("a >= b", "Greater than or equal to");
parseandparseagain("a prop b", "Proportional");
parseandparseagain("a toward b", "Toward");
parseandparseagain("a dlarrow b", "Arrow left");
parseandparseagain("a dlrarrow b", "Double arrow left and right");
parseandparseagain("drarrow b", "Arrow right");
}
void Test::SimpleSetOp()
{
parseandparseagain("a in B", "Is in");
parseandparseagain("a notin B", "Is not in");
parseandparseagain("A owns b", "Owns");
parseandparseagain("emptyset", "Empty set");
parseandparseagain("A intersection B", "Intersection");
parseandparseagain("A union B", "Union");
parseandparseagain("A setminus B", "Difference");
parseandparseagain("A slash B", "Quotient");
parseandparseagain("aleph", "Aleph");
parseandparseagain("A subset B", "Subset");
parseandparseagain("A subseteq B", "Subset or equal to");
parseandparseagain("A supset B", "Superset");
parseandparseagain("A supseteq B", "Superset or equal to");
parseandparseagain("A nsubset B", "Not subset");
parseandparseagain("A nsubseteq B", "Not subset or equal");
parseandparseagain("A nsupset B", "Not superset");
parseandparseagain("A nsupseteq B", "Not superset or equal");
parseandparseagain("setN", "Set of natural numbers");
parseandparseagain("setZ", "Set of integers");
parseandparseagain("setQ", "Set of rational numbers");
parseandparseagain("setR", "Set of real numbers");
parseandparseagain("setC", "Set of complex numbers");
}
void Test::SimpleBrackets()
{
parseandparseagain("(a)", "Round Brackets");
parseandparseagain("[b]", "Square Brackets");
parseandparseagain("ldbracket c rdbracket", "Double Square Brackets");
parseandparseagain("lline a rline", "Single line or absolute");
parseandparseagain("abs a", "Single line or absolute 2");
parseandparseagain("ldline a rdline", "Double line");
parseandparseagain("lbrace w rbrace", "Braces");
parseandparseagain("left lbrace stack{0, n <> 0 # 1, n = 1} right none", "Single left brace");
parseandparseagain("langle d rangle", "Angle Brackets");
parseandparseagain("langle a mline b rangle", "Operator Brackets");
parseandparseagain("{a}", "Group brackets (used for program control)");
parseandparseagain("left ( stack{a # b # z} right )", "Round brackets scalable");
parseandparseagain("left [ stack{x # y} right ]", "Square brackets scalable");
parseandparseagain("left ldbracket c right rdbracket", "Double square brackets scalable");
parseandparseagain("left lline a right rline", "Line scalable");
parseandparseagain("left ldline d right rdline", "Double line scalable");
parseandparseagain("left lbrace e right rbrace", "Brace scalable");
parseandparseagain("left langle f right rangle", "Angle bracket scalable");
parseandparseagain("left langle g mline h right rangle", "Operator brackets scalable");
parseandparseagain("{a} overbrace b", "Over brace scalable");
parseandparseagain("{b} underbrace a", "Under brace scalable");
}
void Test::SimpleFormats()
{
parseandparseagain("a lsup{b}", "Left superscript");
parseandparseagain("a csup{b}", "Center superscript");
parseandparseagain("a^{b}", "Right superscript");
parseandparseagain("a lsub{b}", "Left subscript");
parseandparseagain("a csub{b}", "Center subscript");
parseandparseagain("a_{b}", "Right subscript");
parseandparseagain("stack { Hello world # alignl (a) }", "Align character to left");
parseandparseagain("stack{Hello world # alignc(a)}", "Align character to center");
parseandparseagain("stack { Hello world # alignr(a)}", "Align character to right");
parseandparseagain("binom{a}{b}", "Vertical stack of 2");
parseandparseagain("stack{a # b # z}", "Vertical stack, more than 2");
parseandparseagain("matrix{a # b ## c # d}", "Matrix");
parseandparseagain("matrix{a # \"=\" # alignl{b} ## {} # \"=\" # alignl{c+1}}", "Equations aligned at '=' (using 'matrix') ");
parseandparseagain("stack{alignl{a} = b # alignl{phantom{a} = c+1}}", "Equations aligned at '=' (using 'phantom') ");
parseandparseagain("asldkfjo newline sadkfj", "New line");
parseandparseagain("stuff `stuff", "Small gap (grave)");
parseandparseagain("stuff~stuff", "Large gap (tilde)");
}
/* This test takes a formula command, parses it, converts the node to text, * parses it again, converts it to text again, and compares the values. * Doing this doesn't prove that it is correct, but it should prove that the * meaning of the original command is not being changed.
*/ void Test::parseandparseagain(constchar* formula, constchar* test_name)
{
OUString output1, output2;
// auxiliary test for Accept()
std::unique_ptr<MockVisitor> mv(new MockVisitor);
pNode->Accept(mv.get());
}
// Parse two formula commands and verify that they give the same output void Test::ParseAndCompare(constchar* formula1, constchar* formula2, constchar* test_name)
{
OUString sOutput1, sOutput2;
// set up a binom (table) node
sInput += "binom a b + c"; auto pTree = SmParser5().Parse(sInput);
pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
// set up a unary operator with operand
sInput += "- 1"; auto pTree = SmParser5().Parse(sInput);
pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
// move forward (more than) enough places to be at the end int i; for (i = 0; i < 3; ++i)
aCursor.Move(pOutputDevice, MoveRight);
// select the operand
aCursor.Move(pOutputDevice, MoveLeft, false); // set up a fraction
aCursor.InsertFraction();
aCursor.Move(pOutputDevice, MoveDown);
aCursor.InsertText(u"2"_ustr);
sExpected += "- { 1 over 2 }";
CPPUNIT_ASSERT_EQUAL_MESSAGE("Binary Vertical in Unary Operator", sExpected,
xDocShRef->GetText());
}
void Test::testBinHorInSubSup()
{ // set up a blank formula auto pTree = SmParser5().Parse(OUString());
pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
// Insert an RSup expression with a BinHor for the exponent
aCursor.InsertText(u"a"_ustr);
aCursor.InsertSubSup(RSUP);
aCursor.InsertText(u"b"_ustr);
aCursor.InsertElement(PlusElement);
aCursor.InsertText(u"c"_ustr);
// Move to the end and add d to the expression
aCursor.Move(pOutputDevice, MoveRight);
aCursor.InsertElement(PlusElement);
aCursor.InsertText(u"d"_ustr);
CPPUNIT_ASSERT_EQUAL_MESSAGE("BinHor in SubSup", u"{ a ^ { b + c } + d }"_ustr,
xDocShRef->GetText());
}
void Test::testUnaryInMixedNumberAsNumerator()
{ // set up a unary operator auto pTree = SmParser5().Parse(u"- 1"_ustr);
pTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
// Set up a fraction
aCursor.InsertFraction();
aCursor.Move(pOutputDevice, MoveDown);
aCursor.InsertText(u"2"_ustr);
// Move left and turn this into a mixed number // (bad form, but this could happen right?)
aCursor.Move(pOutputDevice, MoveLeft);
aCursor.Move(pOutputDevice, MoveLeft);
aCursor.InsertText(u"2"_ustr);
// move forward (more than) enough places to be at the end for (size_t i = 0; i < 8; ++i)
aCursor.Move(pOutputDevice, MoveRight);
// add 4 to the end
aCursor.InsertElement(PlusElement);
aCursor.InsertText(u"4"_ustr);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unary in mixed number as Numerator",
u"{ 2 { { - 1 over 2 } + 4 } }"_ustr, xDocShRef->GetText());
}
void Test::testMiscEquivalent()
{ // fdo#55853
ParseAndCompare("2x", "2 x", "Number times variable");
ParseAndCompare("3x^2", "3 x^2", "Number times power");
// i#11752 and fdo#55853
ParseAndCompare("x_2n", "x_{2 n}", "Number times variable in subscript");
ParseAndCompare("x^2n", "x^{2 n}", "Number times variable in supscript");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.