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

Refactor: Pull more classes into baselib

This commit is contained in:
gnosygnu
2021-12-19 16:19:19 -05:00
parent 48559edffe
commit 0e80d7ef6d
7999 changed files with 1375876 additions and 1365947 deletions

View File

@@ -14,8 +14,9 @@ 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 gplx.types.commons.lists.CompareAbleUtl;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BoolUtl;
import org.junit.*;
public class BoolUtlTest {
private final BoolUtlTstr fxt = new BoolUtlTstr();
@@ -27,5 +28,5 @@ public class BoolUtlTest {
}
}
class BoolUtlTstr {
public void TestCompare(boolean lhs, boolean rhs, int expd) {GfoTstr.EqInt(expd, BoolUtl.Compare(lhs, rhs));}
public void TestCompare(boolean lhs, boolean rhs, int expd) {GfoTstr.Eq(expd, BoolUtl.Compare(lhs, rhs));}
}

View File

@@ -0,0 +1,35 @@
/*
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.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.ByteUtl;
import org.junit.Test;
public class ByteUtlTest {
@Test public void int_() {
tst_int_( 0, 0);
tst_int_( 127, 127);
tst_int_( 128, 128); // NOTE: JAVA defines byte as -128 -> 127
tst_int_( 255, 255);
tst_int_( 256, 0); // NOTE: 256 will cast to 1; (byte)256 works same in both JAVA/.NET
} void tst_int_(int v, int expd) {GfoTstr.Eq((byte)expd, ByteUtl.ByInt(v));} // WORKAROUND/JAVA: expd is of type int b/c java promotes numbers to ints
@Test public void To_int() {
tst_XtoInt( 0, 0);
tst_XtoInt( 127, 127);
tst_XtoInt( 128, 128);
tst_XtoInt( 255, 255);
tst_XtoInt( 256, 0);
} void tst_XtoInt(int v, int expd) {GfoTstr.Eq(expd, ByteUtl.ToInt((byte)v));} // WORKAROUND/JAVA: v is of type int b/c java promotes numbers to ints
}

View File

@@ -14,7 +14,8 @@ 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 gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.DoubleUtl;
import org.junit.Test;
public class DoubleUtlTest {
private final DoubleUtlTstr tstr = new DoubleUtlTstr();
@@ -38,12 +39,13 @@ public class DoubleUtlTest {
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
}
@Test public void Xto_str_loose() {
tstr.TestXtoStrLoose(2449.6000000d , "2449.6");
tstr.TestXtoStrLoose(623.700d , "623.7");
}
}
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));
}
public void TestToStrByPrintF(double v, String expd) {GfoTstr.Eq(expd, DoubleUtl.ToStrByPrintF(v));}
public void TestTrimZeroes(String val, String expd) {GfoTstr.Eq(expd, DoubleUtl.TrimZeroes(val));}
public void TestXtoStrLoose(double v, String expd) {GfoTstr.Eq(expd, DoubleUtl.ToStrLoose(v));}
}

View File

@@ -14,78 +14,99 @@ 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 gplx.types.basics.utls.BryUtl;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.IntUtl;
import org.junit.Test;
public class IntUtlTest {
private final IntUtlTstr fxt = new IntUtlTstr();
private final IntUtlTstr tstr = new IntUtlTstr();
@Test public void ParseOr() {
fxt.TestParseOr("123", 123); // basic
fxt.TestParseOrMinValue(null); // null
fxt.TestParseOrMinValue(""); // empty
fxt.TestParseOrMinValue("1a"); // invalid number
tstr.TestParseOr("123", 123); // basic
tstr.TestParseOrMinValue(null); // null
tstr.TestParseOrMinValue(""); // empty
tstr.TestParseOrMinValue("1a"); // invalid number
fxt.TestParseOr("-123", -123); // negative
fxt.TestParseOrMinValue("1-23"); // negative at invalid position
tstr.TestParseOr("-123", -123); // negative
tstr.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
tstr.TestBetween(1, 0, 2, true); // simple true
tstr.TestBetween(3, 0, 2, false); // simple false
tstr.TestBetween(0, 0, 2, true); // bgn true
tstr.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);
tstr.TestCountDigits( 0, 1);
tstr.TestCountDigits( 9, 1);
tstr.TestCountDigits( 100, 3);
tstr.TestCountDigits( -1, 2);
tstr.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);
tstr.TestLog10( 0, 0);
tstr.TestLog10( 1, 0);
tstr.TestLog10( 2, 0);
tstr.TestLog10( 10, 1);
tstr.TestLog10( 12, 1);
tstr.TestLog10( 100, 2);
tstr.TestLog10( 123, 2);
tstr.TestLog10( 1000, 3);
tstr.TestLog10( 1234, 3);
tstr.TestLog10( 10000, 4);
tstr.TestLog10( 12345, 4);
tstr.TestLog10( 100000, 5);
tstr.TestLog10( 123456, 5);
tstr.TestLog10( 1000000, 6);
tstr.TestLog10( 1234567, 6);
tstr.TestLog10( 10000000, 7);
tstr.TestLog10( 12345678, 7);
tstr.TestLog10( 100000000, 8);
tstr.TestLog10( 123456789, 8);
tstr.TestLog10( 1000000000, 9);
tstr.TestLog10( 1234567890, 9);
tstr.TestLog10(IntUtl.MaxValue, 9);
tstr.TestLog10( -1, 0);
tstr.TestLog10( -10, -1);
tstr.TestLog10( -100, -2);
tstr.TestLog10( -1000000, -6);
tstr.TestLog10( -1000000000, -9);
tstr.TestLog10(IntUtl.MinValue, -9);
tstr.TestLog10(IntUtl.MinValue + 1, -9);
}
@Test public void ToStrPadBgnZeroes() {
tstr.TestToStrPadBgnZeroes(1 , 3, "001"); // pad
tstr.TestToStrPadBgnZeroes(123 , 3, "123"); // no pad
tstr.TestToStrPadBgnZeroes(1234 , 3, "1234"); // val exceeds pad; confirm noop
tstr.TestToStrPadBgnZeroes(-1 , 3, "-01"); // negative
tstr.TestToStrPadBgnZeroes(-12 , 3, "-12"); // negative
tstr.TestToStrPadBgnZeroes(-123 , 3, "-123"); // negative
tstr.TestToStrPadBgnZeroes(-1234 , 3, "-1234"); // negative
}
@Test public void ToStrFmt() {
tstr.TestToStrFmt(1, "1");
tstr.TestToStrFmt(1000, "1,000");
}
@Test public void ByHexBry() {
tstr.TestByHexBry("007C", 124);
}
}
class IntUtlTstr {
public void TestParseOr(String raw, int expd) {
GfoTstr.EqInt(expd, IntUtl.ParseOr(raw, -1));
GfoTstr.Eq(expd, IntUtl.ParseOr(raw, -1));
}
public void TestParseOrMinValue(String raw) {
GfoTstr.EqInt(IntUtl.MinValue, IntUtl.ParseOr(raw, IntUtl.MinValue));
GfoTstr.Eq(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));
GfoTstr.Eq(expd, IntUtl.Between(val, lhs, rhs));
}
public void TestCountDigits(int val, int expd) {
GfoTstr.EqInt(expd, IntUtl.CountDigits(val), IntUtl.ToStr(val));
GfoTstr.Eq(expd, IntUtl.CountDigits(val), IntUtl.ToStr(val));
}
public void TestLog10(int val, int expd) {
GfoTstr.EqInt(expd, IntUtl.Log10(val));
GfoTstr.Eq(expd, IntUtl.Log10(val));
}
public void TestToStrPadBgnZeroes(int val, int zeros, String expd) {GfoTstr.Eq(expd, IntUtl.ToStrPadBgnZero(val, zeros));}
public void TestToStrFmt(int v, String expd) {GfoTstr.Eq(expd, IntUtl.ToStrFmt(v, "#,###"));}
public void TestByHexBry(String raw, int expd) {GfoTstr.Eq(expd, IntUtl.ByHexBry(BryUtl.NewA7(raw)));}
}

View File

@@ -0,0 +1,53 @@
/*
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.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.LongUtl;
import org.junit.Test;
public class LongUtlTest {
private LongUtlTstr tstr = new LongUtlTstr();
@Test public void DigitCount() {
tstr.TestDigitCount(0, 1);
tstr.TestDigitCount(1, 1);
tstr.TestDigitCount(9, 1);
tstr.TestDigitCount(10, 2);
tstr.TestDigitCount(100, 3);
tstr.TestDigitCount(10000, 5);
tstr.TestDigitCount(100000, 6);
tstr.TestDigitCount(1000000, 7);
tstr.TestDigitCount(1000000000, 10);
tstr.TestDigitCount(10000000000L, 11);
tstr.TestDigitCount(100000000000L, 12);
tstr.TestDigitCount(10000000000000000L, 17);
tstr.TestDigitCount(-1, 2);
}
@Test public void Int_merge() {
tstr.TestInt_merge(123, 456, 528280977864L);
tstr.TestInt_merge(123, 457, 528280977865L);
}
@Test public void parse_or() {
tstr.parse_or_tst("10000000000", 10000000000L);
}
}
class LongUtlTstr {
public void TestDigitCount(long val, int expd) {GfoTstr.EqLong(expd, LongUtl.DigitCount(val));}
public void TestInt_merge(int hi, int lo, long expd) {
GfoTstr.EqLong(expd, LongUtl.IntMerge(hi, lo));
GfoTstr.EqLong(hi, LongUtl.IntSplitHi(expd));
GfoTstr.EqLong(lo, LongUtl.IntSplitLo(expd));
}
public void parse_or_tst(String raw, long expd) {GfoTstr.EqLong(expd, LongUtl.ParseOr(raw, -1));}
}