2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.util;
10 import org.junit.Test;
11 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
12 import org.opendaylight.yangtools.yang.model.api.Status;
14 import java.util.Collections;
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertNotEquals;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.assertFalse;
21 public class Decimal64Test {
24 public void canCreateDecimal64() {
25 Integer fractionDig = 2;
26 Decimal64 decimal64 = Decimal64.create(SchemaPath.ROOT, fractionDig);
28 assertEquals("Status should be CURRENT", Status.CURRENT, decimal64.getStatus());
30 assertEquals("Default value should be null", null, decimal64.getDefaultValue());
32 assertEquals("Should be empty list", Collections.EMPTY_LIST, decimal64.getUnknownSchemaNodes());
34 assertEquals("Should be null", null, decimal64.getBaseType());
36 assertNotEquals("Description is not null", null, decimal64.getDescription());
38 assertNotEquals("Reference is not null", null, decimal64.getReference());
40 assertEquals("Should be empty string", "", decimal64.getUnits());
42 assertTrue("Should contain factionDigits=2", decimal64.toString().contains("fractionDigits="+fractionDig));
44 assertEquals("Should get farctionDig", fractionDig, decimal64.getFractionDigits());
46 assertEquals("Should be empty list",
47 Collections.EMPTY_LIST, decimal64.getPath().getPathFromRoot());
49 assertEquals("Should be DECIMAL64_QNAME", BaseTypes.DECIMAL64_QNAME, decimal64.getQName());
51 assertTrue("Should contain max", decimal64.getRangeConstraints().toString().contains("max=922337203685477580.7"));
52 assertTrue("Should contain min", decimal64.getRangeConstraints().toString().contains("min=-922337203685477580.8"));
54 Decimal64 decimal641 = decimal64;
55 assertTrue("Hash code of decimal64 and decimal641 should be equal",
56 decimal64.hashCode() == decimal641.hashCode());
58 assertFalse("Decimal64 shouldn't equal to null", decimal64.equals(null));
59 assertEquals("Decimal64 should equals to itself", decimal64, decimal64);
60 assertFalse("Decimal64 shouldn't equal to object of other type", decimal64.equals("str"));