From: Robert Varga Date: Sun, 13 Mar 2022 21:38:55 +0000 (+0100) Subject: Fix BaseDecimalType scales X-Git-Tag: v8.0.1~1 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=yangtools.git;a=commitdiff_plain;h=4d91e42fb4f17951d06e9286ef8cded5b10f20ba Fix BaseDecimalType scales We fail to generate range contraint for fraction-digits=18, fix that. JIRA: YANGTOOLS-1406 Change-Id: Ieafd48ba6b63c160f01b163e7b6786f4a5833fb5 Signed-off-by: Robert Varga --- diff --git a/model/yang-model-ri/src/main/java/org/opendaylight/yangtools/yang/model/ri/type/BaseDecimalType.java b/model/yang-model-ri/src/main/java/org/opendaylight/yangtools/yang/model/ri/type/BaseDecimalType.java index e9c630c7d8..374ef46f14 100644 --- a/model/yang-model-ri/src/main/java/org/opendaylight/yangtools/yang/model/ri/type/BaseDecimalType.java +++ b/model/yang-model-ri/src/main/java/org/opendaylight/yangtools/yang/model/ri/type/BaseDecimalType.java @@ -50,7 +50,7 @@ final class BaseDecimalType extends AbstractRangeRestrictedBaseType>builderWithExpectedSize(18); - for (int scale = 1; scale < 18; ++scale) { + for (int scale = 1; scale <= 18; ++scale) { builder.add(new ResolvedRangeConstraint<>(BUILTIN_CONSTRAINT, ImmutableRangeSet.of(Range.closed( Decimal64.minValueIn(scale), Decimal64.maxValueIn(scale))))); } diff --git a/model/yang-model-ri/src/test/java/org/opendaylight/yangtools/yang/model/ri/type/BaseDecimalTest.java b/model/yang-model-ri/src/test/java/org/opendaylight/yangtools/yang/model/ri/type/BaseDecimalTest.java new file mode 100644 index 0000000000..e76e3cb982 --- /dev/null +++ b/model/yang-model-ri/src/test/java/org/opendaylight/yangtools/yang/model/ri/type/BaseDecimalTest.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.yangtools.yang.model.ri.type; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Range; +import org.junit.Test; +import org.opendaylight.yangtools.yang.common.Decimal64; + +public class BaseDecimalTest { + @Test + public void testImplicitRanges() { + assertEquals( + Range.closed(Decimal64.valueOf("-922337203685477580.8"), Decimal64.valueOf("922337203685477580.7")), + Iterables.getOnlyElement(BaseDecimalType.constraintsForDigits(1).getAllowedRanges().asRanges())); + + assertEquals(Range.closed( + Decimal64.valueOf("-9.223372036854775808"), Decimal64.valueOf("9.223372036854775807")), + Iterables.getOnlyElement(BaseDecimalType.constraintsForDigits(18).getAllowedRanges().asRanges())); + } +}