mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare/test] Updated tests on units
Change-Id: I7c146174bcedcccc3ed31a298c9720aa2a5ba3a9
This commit is contained in:
committed by
Émilie Feral
parent
1f3c4b66a0
commit
e48e826536
@@ -294,9 +294,11 @@ QUIZ_CASE(poincare_parsing_units) {
|
||||
Expression unit = parse_expression(buffer, nullptr, false);
|
||||
quiz_assert_print_if_failure(unit.type() == ExpressionNode::Type::Unit, "Should be parsed as a Unit");
|
||||
if (rep->isPrefixable()) {
|
||||
size_t numberOfPrefixes = sizeof(Unit::AllPrefixes)/sizeof(Unit::Prefix *);
|
||||
/* ton is only prefixable by positive prefixes */
|
||||
bool isTon = strcmp("t", rep->rootSymbol()) == 0;
|
||||
size_t numberOfPrefixes = ((isTon) ? sizeof(Unit::PositiveLongScalePrefixes) : sizeof(Unit::AllPrefixes))/sizeof(Unit::Prefix *);
|
||||
for (size_t i = 0; i < numberOfPrefixes; i++) {
|
||||
const Unit::Prefix * pre = Unit::AllPrefixes[i];
|
||||
const Unit::Prefix * pre = (isTon) ? Unit::PositiveLongScalePrefixes[i] : Unit::AllPrefixes[i];
|
||||
Unit::Builder(dim, rep, pre).serialize(buffer, bufferSize, Preferences::PrintFloatMode::Decimal, Preferences::VeryShortNumberOfSignificantDigits);
|
||||
Expression unit = parse_expression(buffer, nullptr, false);
|
||||
quiz_assert_print_if_failure(unit.type() == ExpressionNode::Type::Unit, "Should be parsed as a Unit");
|
||||
|
||||
@@ -271,13 +271,13 @@ QUIZ_CASE(poincare_simplification_units) {
|
||||
* t, Hz, S, ha, L. These exceptions are tested below. */
|
||||
for (const Unit::Dimension * dim = Unit::DimensionTable; dim < Unit::DimensionTableUpperBound; dim++) {
|
||||
for (const Unit::Representative * rep = dim->stdRepresentative(); rep < dim->representativesUpperBound(); rep++) {
|
||||
if (strcmp(rep->rootSymbol(), "Hz") == 0 || strcmp(rep->rootSymbol(), "S") == 0 || strcmp(rep->rootSymbol(), "ha") == 0 || strcmp(rep->rootSymbol(), "L") == 0) {
|
||||
if (strcmp(rep->rootSymbol(), "Hz") == 0 || strcmp(rep->rootSymbol(), "S") == 0 || strcmp(rep->rootSymbol(), "ha") == 0 || strcmp(rep->rootSymbol(), "L") == 0 || strcmp(rep->rootSymbol(), "yd") || strcmp(rep->rootSymbol(), "tsp") || strcmp(rep->rootSymbol(), "Tbsp") || strcmp(rep->rootSymbol(), "pt") || strcmp(rep->rootSymbol(), "qt") || strcmp(rep->rootSymbol(), "lgtn")) {
|
||||
continue;
|
||||
}
|
||||
static constexpr size_t bufferSize = 12;
|
||||
char buffer[bufferSize] = "1×";
|
||||
Unit::Builder(dim, rep, &Unit::EmptyPrefix).serialize(buffer+strlen("1×"), bufferSize-strlen("1×"), Preferences::PrintFloatMode::Decimal, Preferences::VeryShortNumberOfSignificantDigits);
|
||||
assert_parsed_expression_simplify_to(buffer, buffer);
|
||||
assert_parsed_expression_simplify_to(buffer, buffer, User, Radian, (rep->canOutputInSystem(Metric) ? Metric : Imperial));
|
||||
if (rep->isPrefixable()) {
|
||||
for (size_t i = 0; i < rep->outputPrefixesLength(); i++) {
|
||||
const Unit::Prefix * pre = rep->outputPrefixes()[i];
|
||||
|
||||
Reference in New Issue
Block a user