mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare/test] Layout serialization tests
This commit is contained in:
@@ -159,7 +159,7 @@ int IntegralLayoutNode::serialize(char * buffer, int bufferSize, Preferences::Pr
|
||||
return bufferSize-1;
|
||||
}
|
||||
|
||||
/* Add an system parenthesis to avoid serializing:
|
||||
/* Add system parentheses to avoid serializing:
|
||||
* 2)+(1
|
||||
* ∫ (5)dx
|
||||
* 1
|
||||
@@ -169,7 +169,12 @@ int IntegralLayoutNode::serialize(char * buffer, int bufferSize, Preferences::Pr
|
||||
return bufferSize-1;
|
||||
}
|
||||
|
||||
LayoutNode * argLayouts[] = {const_cast<IntegralLayoutNode *>(this)->integrandLayout(), const_cast<IntegralLayoutNode *>(this)->differentialLayout(), const_cast<IntegralLayoutNode *>(this)->lowerBoundLayout(), const_cast<IntegralLayoutNode *>(this)->upperBoundLayout()};
|
||||
LayoutNode * argLayouts[] = {
|
||||
const_cast<IntegralLayoutNode *>(this)->integrandLayout(),
|
||||
const_cast<IntegralLayoutNode *>(this)->differentialLayout(),
|
||||
const_cast<IntegralLayoutNode *>(this)->lowerBoundLayout(),
|
||||
const_cast<IntegralLayoutNode *>(this)->upperBoundLayout()};
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(argLayouts)/sizeof(argLayouts[0]); i++) {
|
||||
if (i != 0) {
|
||||
// Write the comma
|
||||
|
||||
@@ -6,29 +6,141 @@
|
||||
|
||||
using namespace Poincare;
|
||||
|
||||
// TODO: add tests about layout serialization (especially all serialization that add system parentheses)
|
||||
|
||||
QUIZ_CASE(poincare_layout_serialization) {
|
||||
// Binomial coefficient layout
|
||||
assert_layout_serialize_to(BinomialCoefficientLayout::Builder(CodePointLayout::Builder('7'), CodePointLayout::Builder('6')), "binomial\u00127,6\u0013");
|
||||
assert(UCodePointLeftSystemParenthesis == 0x12);
|
||||
assert(UCodePointRightSystemParenthesis == 0x13);
|
||||
|
||||
// AbsoluteValueLayout
|
||||
assert_layout_serialize_to(
|
||||
AbsoluteValueLayout::Builder(CodePointLayout::Builder('8')),
|
||||
"abs\u00128\u0013");
|
||||
|
||||
// BinomialCoefficientLayout
|
||||
assert_layout_serialize_to(
|
||||
BinomialCoefficientLayout::Builder(CodePointLayout::Builder('7'), CodePointLayout::Builder('6')),
|
||||
"binomial\u00127,6\u0013");
|
||||
|
||||
// Bracket and BracketPairLayout -> Tested by other layouts
|
||||
|
||||
// CeilingLayout
|
||||
assert_layout_serialize_to(
|
||||
CeilingLayout::Builder(CodePointLayout::Builder('8')),
|
||||
"ceil\u00128\u0013");
|
||||
|
||||
// CodePointLayout -> Tested by most other layouts
|
||||
|
||||
// CondensedSumLayout -> No serialization
|
||||
|
||||
// ConjugateLayout
|
||||
assert_layout_serialize_to(
|
||||
ConjugateLayout::Builder(CodePointLayout::Builder('1')),
|
||||
"conj\u00121\u0013");
|
||||
|
||||
// EmptyLayout
|
||||
assert_layout_serialize_to(
|
||||
EmptyLayout::Builder(),
|
||||
"");
|
||||
|
||||
// FloorLayout
|
||||
assert_layout_serialize_to(
|
||||
FloorLayout::Builder(CodePointLayout::Builder('8')),
|
||||
"floor\u00128\u0013");
|
||||
|
||||
// Fraction layout: 1/(2+3)
|
||||
assert_layout_serialize_to(
|
||||
FractionLayout::Builder(
|
||||
CodePointLayout::Builder('1'),
|
||||
LayoutHelper::String("2+3", 3)),
|
||||
"\u0012\u00121\u0013/\u00122+3\u0013\u0013");
|
||||
|
||||
// GridPairLayout -> Tested by MatrixLayout
|
||||
|
||||
// HorizontalLayout
|
||||
assert_layout_serialize_to(
|
||||
HorizontalLayout::Builder(
|
||||
CodePointLayout::Builder('a'),
|
||||
CodePointLayout::Builder('b'),
|
||||
CodePointLayout::Builder('c'),
|
||||
CodePointLayout::Builder('d')),
|
||||
"abcd");
|
||||
|
||||
// IntegralLayout
|
||||
assert_layout_serialize_to(
|
||||
IntegralLayout::Builder(
|
||||
CodePointLayout::Builder('1'),
|
||||
CodePointLayout::Builder('x'),
|
||||
CodePointLayout::Builder('2'),
|
||||
CodePointLayout::Builder('3')),
|
||||
"int\u0012\u00121\u0013,\u0012x\u0013,\u00122\u0013,\u00123\u0013\u0013");
|
||||
|
||||
// LeftParenthesisLayout
|
||||
assert_layout_serialize_to(
|
||||
LeftParenthesisLayout::Builder(),
|
||||
"(");
|
||||
|
||||
// LeftSquareBracketLayout
|
||||
assert_layout_serialize_to(
|
||||
LeftSquareBracketLayout::Builder(),
|
||||
"[");
|
||||
|
||||
// MatrixLayout
|
||||
assert_layout_serialize_to(
|
||||
MatrixLayout::Builder(
|
||||
CodePointLayout::Builder('a'),
|
||||
CodePointLayout::Builder('b'),
|
||||
CodePointLayout::Builder('c'),
|
||||
CodePointLayout::Builder('d')),
|
||||
"[[a,b][c,d]]");
|
||||
|
||||
// Fraction layout
|
||||
Layout layout = FractionLayout::Builder(
|
||||
CodePointLayout::Builder('1'),
|
||||
LayoutHelper::String("2+3", 3)
|
||||
);
|
||||
assert_layout_serialize_to(layout, "\u0012\u00121\u0013/\u00122+3\u0013\u0013"); // 1/(2+3)
|
||||
|
||||
// Nth root layout
|
||||
assert_layout_serialize_to(NthRootLayout::Builder(CodePointLayout::Builder('7'), CodePointLayout::Builder('6')), "root\u00127,6\u0013");
|
||||
assert_layout_serialize_to(
|
||||
NthRootLayout::Builder(
|
||||
CodePointLayout::Builder('7'),
|
||||
CodePointLayout::Builder('6')),
|
||||
"root\u00127,6\u0013");
|
||||
|
||||
// ParenthesisLayout -> Tested by Left/RightParenthesisLayout
|
||||
|
||||
// ProductLayout
|
||||
assert_layout_serialize_to(
|
||||
ProductLayout::Builder(
|
||||
CodePointLayout::Builder('1'),
|
||||
CodePointLayout::Builder('x'),
|
||||
CodePointLayout::Builder('2'),
|
||||
CodePointLayout::Builder('3')),
|
||||
"prod\u0012\u00121\u0013,\u0012x\u0013,\u00122\u0013,\u00123\u0013\u0013");
|
||||
|
||||
// RightParenthesisLayout
|
||||
assert_layout_serialize_to(
|
||||
RightParenthesisLayout::Builder(),
|
||||
")");
|
||||
|
||||
// RightSquareBracketLayout
|
||||
assert_layout_serialize_to(
|
||||
RightSquareBracketLayout::Builder(),
|
||||
"]");
|
||||
|
||||
// SequenceLayout -> Tested by SumLayout and ProductLayout
|
||||
|
||||
// SquareBracketLayout -> Tested by Left/RightSquareBracketLayout
|
||||
|
||||
// SumLayout
|
||||
assert_layout_serialize_to(
|
||||
SumLayout::Builder(
|
||||
LayoutHelper::String("1+1", 3),
|
||||
CodePointLayout::Builder('x'),
|
||||
CodePointLayout::Builder('2'),
|
||||
CodePointLayout::Builder('3')),
|
||||
"sum\u0012\u00121+1\u0013,\u0012x\u0013,\u00122\u0013,\u00123\u0013\u0013");
|
||||
|
||||
|
||||
// Vertical offset layout
|
||||
layout = HorizontalLayout::Builder(
|
||||
CodePointLayout::Builder('2'),
|
||||
VerticalOffsetLayout::Builder(
|
||||
LayoutHelper::String("x+5", 3),
|
||||
VerticalOffsetLayoutNode::Position::Superscript
|
||||
)
|
||||
);
|
||||
assert_layout_serialize_to(layout, "2^\x12x+5\x13");
|
||||
assert_layout_serialize_to(
|
||||
HorizontalLayout::Builder(
|
||||
CodePointLayout::Builder('2'),
|
||||
VerticalOffsetLayout::Builder(
|
||||
LayoutHelper::String("x+5", 3),
|
||||
VerticalOffsetLayoutNode::Position::Superscript)),
|
||||
"2^\x12x+5\x13");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user