Class NumberParserTest

java.lang.Object
org.djutils.base.NumberParserTest

public class NumberParserTest extends Object
NumberParserTest tests the NumberParser.

Copyright (c) 2023-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.

Author:
Alexander Verbraeck
  • Constructor Details

    • NumberParserTest

      public NumberParserTest()
  • Method Details

    • testNPE

      @Test public void testNPE()
      Test the NumberParser for NullPointer and empty string exceptions.
    • testConstructors

      @Test public void testConstructors()
      Test the NumberParser constructors.
    • testNumberParserFloatUS

      @Test public void testNumberParserFloatUS()
      Test with a few settings for the US locale.
    • testNumberParserFloatNL

      @Test public void testNumberParserFloatNL()
      Test with a few settings for the NL locale.
    • testNumberParserFloatFRjdk17

      public void testNumberParserFloatFRjdk17()
      Test with a few settings for the FR locale. Note that the Locale for France in jdk17 is different from jdk11. See https://stackoverflow.com/questions/70865403/why-numberformat-working-different-for-openjdk11-and-openjdk17 and https://bugs.openjdk.org/browse/JDK-8225245 for more information. The jdk17 standard can be downloaded from https://unicode.org/Public/cldr/35.1/. The jdk11 standard can be downloaded from https://unicode.org/Public/cldr/33/.
    • testNumberParserFloatFRjdk11

      public void testNumberParserFloatFRjdk11()
      Test with a few settings for the FR locale. Note that the Locale for France in jdk17 is different from jdk11. See https://stackoverflow.com/questions/70865403/why-numberformat-working-different-for-openjdk11-and-openjdk17 and https://bugs.openjdk.org/browse/JDK-8225245 for more information. The jdk17 standard can be downloaded from https://unicode.org/Public/cldr/35.1/. The jdk11 standard can be downloaded from https://unicode.org/Public/cldr/33/.
    • testNumberParserFloatFR

      @Test public void testNumberParserFloatFR()
      Test with a few settings for the FR locale. Note that the Locale for France in jdk17 is different from jdk11. See https://stackoverflow.com/questions/70865403/why-numberformat-working-different-for-openjdk11-and-openjdk17 for more information. The jdk17 standard can be downloaded from https://unicode.org/Public/cldr/35.1/. The jdk11 standard can be downloaded from https://unicode.org/Public/cldr/33/.
    • testNumberParserFloatArabicJdk17

      public void testNumberParserFloatArabicJdk17()
      Test with a few settings for the Arabic locale. Note that Arabic is written right-to-left, but the numbers in a Java String are still formatted left-to-right. Note that the Locale for Arabic in jdk17 is different from jdk11. See https://stackoverflow.com/questions/72738425/numberformating-issue-with-negative-numbers-in-rtl-locale-like-arabic for more information. The jdk17 standard can be downloaded from https://unicode.org/Public/cldr/35.1/. The jdk11 standard can be downloaded from https://unicode.org/Public/cldr/33/.
    • testNumberParserFloatArabicJdk11

      public void testNumberParserFloatArabicJdk11()
      Test with a few settings for the Arabic locale. Note that Arabic is written right-to-left, but the numbers in a Java String are still formatted left-to-right. Note that the Locale for Arabic in jdk17 is different from jdk11. See https://stackoverflow.com/questions/72738425/numberformating-issue-with-negative-numbers-in-rtl-locale-like-arabic for more information. The jdk17 standard can be downloaded from https://unicode.org/Public/cldr/35.1/. The jdk11 standard can be downloaded from https://unicode.org/Public/cldr/33/.
    • testNumberParserFloatArabic

      @Test public void testNumberParserFloatArabic()
      Test with a few settings for the Arabic locale. Note that Arabic is written right-to-left, but the numbers in a Java String are still formatted left-to-right. Note that the Locale for Arabic in jdk17 is different from jdk11. See https://stackoverflow.com/questions/72738425/numberformating-issue-with-negative-numbers-in-rtl-locale-like-arabic for more information. The jdk17 standard can be downloaded from https://unicode.org/Public/cldr/35.1/. The jdk11 standard can be downloaded from https://unicode.org/Public/cldr/33/.
    • arabicStringToHex

      public void arabicStringToHex()
      Helper method to print the internal formatting of an Arab number in unicode.
    • testDouble

      public void testDouble(String text, double expectedAnswer, String expectedTrailing, boolean strict, Locale locale)
      Test a parsing testcase for Double values.
      Parameters:
      text - String; the text to parse
      expectedAnswer - double; the expected numerical answer
      expectedTrailing - String the expected trailing info
      strict - boolean; whether the text String is strict or not
      locale - Locale; the locale to test for
    • testFloat

      public void testFloat(String text, float expectedAnswer, String expectedTrailing, boolean strict, Locale locale)
      Test a parsing testcase for Float values.
      Parameters:
      text - String; the text to parse
      expectedAnswer - float; the expected numerical answer
      expectedTrailing - String the expected trailing info
      strict - boolean; whether the text String is strict or not
      locale - Locale; the locale to test for
    • testDoubleFail

      public void testDoubleFail(String text, boolean strict, boolean trailing, Locale locale)
      Test whether parsing of double fails as expected.
      Parameters:
      text - String; the text to parse
      strict - boolean; whether to apply strict parsing or not
      trailing - boolean; whether to allow trailing or not
      locale - Locale; the locale to use
    • testFloatFail

      public void testFloatFail(String text, boolean strict, boolean trailing, Locale locale)
      Test whether parsing of float fails as expected.
      Parameters:
      text - String; the text to parse
      strict - boolean; whether to apply strict parsing or not
      trailing - boolean; whether to allow trailing or not
      locale - Locale; the locale to use
    • makeNumberParserChaining

      NumberParser makeNumberParserChaining(boolean lenient, boolean trailing, Locale locale)
      Make a NumberParser through chaining with all possible combinations.
      Parameters:
      lenient - boolean; lenient or strict
      trailing - boolean; trailing info on or off
      locale - Locale; when null, no locale is set (using Locale.getDefault())
      Returns:
      NumberParser made through chaining