[poincare] Fix Unit::IsISEnergy

This commit is contained in:
Émilie Feral
2020-05-07 15:33:52 +02:00
parent 7bb4a2ae98
commit 88a39c335f
2 changed files with 5 additions and 3 deletions

View File

@@ -459,11 +459,11 @@ bool Unit::IsISEnergy(Expression & e) {
return e.type() == ExpressionNode::Type::Multiplication && e.numberOfChildren() == 3 &&
e.childAtIndex(0).type() == ExpressionNode::Type::Unit && e.childAtIndex(0).convert<Unit>().isKilogram() &&
e.childAtIndex(1).type() == ExpressionNode::Type::Power &&
e.childAtIndex(1).childAtIndex(0).type() == ExpressionNode::Type::Unit && e.childAtIndex(1).childAtIndex(0).convert<Unit>().isMeter();
e.childAtIndex(1).childAtIndex(0).type() == ExpressionNode::Type::Unit && e.childAtIndex(1).childAtIndex(0).convert<Unit>().isMeter() &&
e.childAtIndex(1).childAtIndex(1).type() == ExpressionNode::Type::Rational && e.childAtIndex(1).childAtIndex(1).convert<const Rational>().isTwo() &&
e.childAtIndex(2).type() == ExpressionNode::Type::Power &&
e.childAtIndex(2).childAtIndex(0).type() == ExpressionNode::Type::Unit && e.childAtIndex(1).childAtIndex(0).convert<Unit>().isSecond();
e.childAtIndex(2).childAtIndex(1).type() == ExpressionNode::Type::Rational && e.childAtIndex(1).childAtIndex(1).convert<const Rational>().isMinusTwo();
e.childAtIndex(2).childAtIndex(0).type() == ExpressionNode::Type::Unit && e.childAtIndex(2).childAtIndex(0).convert<Unit>().isSecond() &&
e.childAtIndex(2).childAtIndex(1).type() == ExpressionNode::Type::Rational && e.childAtIndex(2).childAtIndex(1).convert<const Rational>().isMinusTwo();
}
bool Unit::IsISTime(Expression & e) {

View File

@@ -428,6 +428,8 @@ QUIZ_CASE(poincare_expression_unit_helper) {
// 4. Energy
Expression kilogramMeter2PerSecond2 = extract_unit("_kg×_m^2×_s^-2");
quiz_assert(Unit::IsISEnergy(kilogramMeter2PerSecond2));
Expression kilogramMeter3PerSecond2 = extract_unit("_kg×_m^3×_s^-2");
quiz_assert(!Unit::IsISEnergy(kilogramMeter3PerSecond2));
// 5. International System
quiz_assert(Unit::IsIS(kilogramMeter2PerSecond2));