Double_Test.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. XOWA: the XOWA Offline Wiki Application
  3. Copyright (C) 2012-2020 gnosygnu@gmail.com
  4. XOWA is licensed under the terms of the General Public License (GPL) Version 3,
  5. or alternatively under the terms of the Apache License Version 2.0.
  6. You may use XOWA according to either of these licenses as is most appropriate
  7. for your project on a case-by-case basis.
  8. The terms of each license can be found in the source code repository:
  9. GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
  10. Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
  11. */
  12. package gplx.objects.primitives;
  13. import gplx.tests.Gftest_fxt;
  14. import org.junit.Test;
  15. public class Double_Test {
  16. private final Double_Tstr tstr = new Double_Tstr();
  17. @Test
  18. public void TrimZeroes() {
  19. tstr.Test_TrimZeroes("12.100" , "12.1");
  20. tstr.Test_TrimZeroes("12.000" , "12");
  21. tstr.Test_TrimZeroes("12.001" , "12.001");
  22. tstr.Test_TrimZeroes("1020.00" , "1020");
  23. tstr.Test_TrimZeroes("1020.00" , "1020");
  24. tstr.Test_TrimZeroes("1.200e5" , "1.2E5");
  25. tstr.Test_TrimZeroes("1.200e-05" , "1.2E-5");
  26. }
  27. @Test
  28. public void ToStrByPrintF() {
  29. tstr.Test_ToStrByPrintF(1d / 2d , "0.5"); // fails with 0.50000000000000
  30. tstr.Test_ToStrByPrintF(5d / 100000000000000000d, "5E-17"); // fails with 5.0000000000000e-17
  31. tstr.Test_ToStrByPrintF(7538000d / 7773352000d , "0.00096972322879499"); // fails with 0; ISSUE#:697; DATE:2020-08-11
  32. tstr.Test_ToStrByPrintF(56225d / 7776747000d , "7.2298867379895E-06"); // fails with 0; ISSUE#:697; DATE:2020-08-11
  33. tstr.Test_ToStrByPrintF(35746d / 7805411000d , "4.5796435319037E-06"); // fails with 0; ISSUE#:697; DATE:2020-08-11
  34. }
  35. }
  36. class Double_Tstr {
  37. public void Test_ToStrByPrintF(double v, String expd) {
  38. Gftest_fxt.Eq__str(expd, Double_.ToStrByPrintF(v));
  39. }
  40. public void Test_TrimZeroes(String val, String expd) {
  41. Gftest_fxt.Eq__str(expd, Double_.TrimZeroes(val));
  42. }
  43. }