Fix BaseDecimalType scales 09/100109/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 13 Mar 2022 21:38:55 +0000 (22:38 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 13 Mar 2022 21:48:08 +0000 (22:48 +0100)
We fail to generate range contraint for fraction-digits=18, fix that.

JIRA: YANGTOOLS-1406
Change-Id: Ieafd48ba6b63c160f01b163e7b6786f4a5833fb5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
model/yang-model-ri/src/main/java/org/opendaylight/yangtools/yang/model/ri/type/BaseDecimalType.java
model/yang-model-ri/src/test/java/org/opendaylight/yangtools/yang/model/ri/type/BaseDecimalTest.java [new file with mode: 0644]

index e9c630c7d87e0a7cbeb0ed9232a1634dbd5da1c8..374ef46f1481e696b13d140bfa6b1fdb4b41709f 100644 (file)
@@ -50,7 +50,7 @@ final class BaseDecimalType extends AbstractRangeRestrictedBaseType<DecimalTypeD
 
     static {
         final var builder = ImmutableList.<RangeConstraint<Decimal64>>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 (file)
index 0000000..e76e3cb
--- /dev/null
@@ -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()));
+    }
+}