1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Refactor: Refactor baselib; merge Array_ and Bool_

This commit is contained in:
gnosygnu
2021-12-05 16:25:05 -05:00
parent 197e0aa863
commit 48559edffe
1793 changed files with 177613 additions and 16991 deletions

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2021 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.objects.primitives;
import gplx.objects.lists.CompareAbleUtl;
import gplx.tests.GfoTstr;
import org.junit.*;
public class BoolUtlTest {
private final BoolUtlTstr fxt = new BoolUtlTstr();
@Test public void Compare() {
fxt.TestCompare(BoolUtl.Y, BoolUtl.Y, CompareAbleUtl.Same);
fxt.TestCompare(BoolUtl.N, BoolUtl.N, CompareAbleUtl.Same);
fxt.TestCompare(BoolUtl.N, BoolUtl.Y, CompareAbleUtl.Less);
fxt.TestCompare(BoolUtl.Y, BoolUtl.N, CompareAbleUtl.More);
}
}
class BoolUtlTstr {
public void TestCompare(boolean lhs, boolean rhs, int expd) {GfoTstr.EqInt(expd, BoolUtl.Compare(lhs, rhs));}
}

View File

@@ -0,0 +1,49 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2021 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.objects.primitives;
import gplx.tests.GfoTstr;
import org.junit.Test;
public class DoubleUtlTest {
private final DoubleUtlTstr tstr = new DoubleUtlTstr();
@Test
public void TrimZeroes() {
tstr.TestTrimZeroes("12.100" , "12.1");
tstr.TestTrimZeroes("12.000" , "12");
tstr.TestTrimZeroes("12.001" , "12.001");
tstr.TestTrimZeroes("1020.00" , "1020");
tstr.TestTrimZeroes("1020.00" , "1020");
tstr.TestTrimZeroes("1.200e5" , "1.2E5");
tstr.TestTrimZeroes("1.200e-05" , "1.2E-5");
}
@Test
public void ToStrByPrintF() {
tstr.TestToStrByPrintF(1d / 2d , "0.5"); // fails with 0.50000000000000
tstr.TestToStrByPrintF(5d / 100000000000000000d, "5E-17"); // fails with 5.0000000000000e-17
tstr.TestToStrByPrintF(7538000d / 7773352000d , "0.00096972322879499"); // fails with 0; ISSUE#:697; DATE:2020-08-11
tstr.TestToStrByPrintF(56225d / 7776747000d , "7.2298867379895E-06"); // fails with 0; ISSUE#:697; DATE:2020-08-11
tstr.TestToStrByPrintF(35746d / 7805411000d , "4.5796435319037E-06"); // fails with 0; ISSUE#:697; DATE:2020-08-11
}
}
class DoubleUtlTstr {
public void TestToStrByPrintF(double v, String expd) {
GfoTstr.EqStr(expd, DoubleUtl.ToStrByPrintF(v));
}
public void TestTrimZeroes(String val, String expd) {
GfoTstr.EqStr(expd, DoubleUtl.TrimZeroes(val));
}
}

View File

@@ -1,51 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.objects.primitives;
import gplx.tests.Gftest_fxt;
import org.junit.Test;
public class Double_Test {
private final Double_Tstr tstr = new Double_Tstr();
@Test
public void TrimZeroes() {
tstr.Test_TrimZeroes("12.100" , "12.1");
tstr.Test_TrimZeroes("12.000" , "12");
tstr.Test_TrimZeroes("12.001" , "12.001");
tstr.Test_TrimZeroes("1020.00" , "1020");
tstr.Test_TrimZeroes("1020.00" , "1020");
tstr.Test_TrimZeroes("1.200e5" , "1.2E5");
tstr.Test_TrimZeroes("1.200e-05" , "1.2E-5");
}
@Test
public void ToStrByPrintF() {
tstr.Test_ToStrByPrintF(1d / 2d , "0.5"); // fails with 0.50000000000000
tstr.Test_ToStrByPrintF(5d / 100000000000000000d, "5E-17"); // fails with 5.0000000000000e-17
tstr.Test_ToStrByPrintF(7538000d / 7773352000d , "0.00096972322879499"); // fails with 0; ISSUE#:697; DATE:2020-08-11
tstr.Test_ToStrByPrintF(56225d / 7776747000d , "7.2298867379895E-06"); // fails with 0; ISSUE#:697; DATE:2020-08-11
tstr.Test_ToStrByPrintF(35746d / 7805411000d , "4.5796435319037E-06"); // fails with 0; ISSUE#:697; DATE:2020-08-11
}
}
class Double_Tstr {
public void Test_ToStrByPrintF(double v, String expd) {
Gftest_fxt.Eq__str(expd, Double_.ToStrByPrintF(v));
}
public void Test_TrimZeroes(String val, String expd) {
Gftest_fxt.Eq__str(expd, Double_.TrimZeroes(val));
}
}

View File

@@ -0,0 +1,91 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2021 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.objects.primitives;
import gplx.tests.GfoTstr;
import org.junit.Test;
public class IntUtlTest {
private final IntUtlTstr fxt = new IntUtlTstr();
@Test public void ParseOr() {
fxt.TestParseOr("123", 123); // basic
fxt.TestParseOrMinValue(null); // null
fxt.TestParseOrMinValue(""); // empty
fxt.TestParseOrMinValue("1a"); // invalid number
fxt.TestParseOr("-123", -123); // negative
fxt.TestParseOrMinValue("1-23"); // negative at invalid position
}
@Test public void Between() {
fxt.TestBetween(1, 0, 2, true); // simple true
fxt.TestBetween(3, 0, 2, false); // simple false
fxt.TestBetween(0, 0, 2, true); // bgn true
fxt.TestBetween(2, 0, 2, true); // end true
}
@Test public void CountDigits() {
fxt.TestCountDigits( 0, 1);
fxt.TestCountDigits( 9, 1);
fxt.TestCountDigits( 100, 3);
fxt.TestCountDigits( -1, 2);
fxt.TestCountDigits(-100, 4);
}
@Test public void Log10() {
fxt.TestLog10( 0, 0);
fxt.TestLog10( 1, 0);
fxt.TestLog10( 2, 0);
fxt.TestLog10( 10, 1);
fxt.TestLog10( 12, 1);
fxt.TestLog10( 100, 2);
fxt.TestLog10( 123, 2);
fxt.TestLog10( 1000, 3);
fxt.TestLog10( 1234, 3);
fxt.TestLog10( 10000, 4);
fxt.TestLog10( 12345, 4);
fxt.TestLog10( 100000, 5);
fxt.TestLog10( 123456, 5);
fxt.TestLog10( 1000000, 6);
fxt.TestLog10( 1234567, 6);
fxt.TestLog10( 10000000, 7);
fxt.TestLog10( 12345678, 7);
fxt.TestLog10( 100000000, 8);
fxt.TestLog10( 123456789, 8);
fxt.TestLog10( 1000000000, 9);
fxt.TestLog10( 1234567890, 9);
fxt.TestLog10(IntUtl.MaxValue, 9);
fxt.TestLog10( -1, 0);
fxt.TestLog10( -10, -1);
fxt.TestLog10( -100, -2);
fxt.TestLog10( -1000000, -6);
fxt.TestLog10( -1000000000, -9);
fxt.TestLog10(IntUtl.MinValue, -9);
fxt.TestLog10(IntUtl.MinValue + 1, -9);
}
}
class IntUtlTstr {
public void TestParseOr(String raw, int expd) {
GfoTstr.EqInt(expd, IntUtl.ParseOr(raw, -1));
}
public void TestParseOrMinValue(String raw) {
GfoTstr.EqInt(IntUtl.MinValue, IntUtl.ParseOr(raw, IntUtl.MinValue));
}
public void TestBetween(int val, int lhs, int rhs, boolean expd) {
GfoTstr.EqBool(expd, IntUtl.Between(val, lhs, rhs));
}
public void TestCountDigits(int val, int expd) {
GfoTstr.EqInt(expd, IntUtl.CountDigits(val), IntUtl.ToStr(val));
}
public void TestLog10(int val, int expd) {
GfoTstr.EqInt(expd, IntUtl.Log10(val));
}
}