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,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.lists;
import gplx.objects.arrays.ArrayUtl;
import gplx.tests.GfoTstr;
import org.junit.Test;
public class ComparerAbleSorterTest {
@Test public void Basic() {
Object[] src = new Object[] {0,8,1,7,2,6,3,5,4};
new ComparerAbleSorter().Sort(src, src.length);
GfoTstr.EqAry(src, Sequential(0, 8));
}
@Test public void Basic2() {
Object[] src = new Object[] {"0","8","1","7","2","6","3","5","4"};
new ComparerAbleSorter().Sort(src, src.length);
GfoTstr.EqAry(src, new Object[] {"0","1","2","3","4","5","6","7","8"});
}
private Object[] Sequential(int bgn, int end) {
Object[] rv = new Object[end - bgn + 1];
for (int i = 0; i < ArrayUtl.Len(rv); i++)
rv[i] = i + bgn;
return rv;
}
}

View File

@@ -1,70 +1,83 @@
/*
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.lists;
import gplx.tests.Gftest_fxt;
import gplx.tests.GfoTstr;
import org.junit.Test;
public class GfoIndexedListEntryTest {
private GfoIndexedList<String, String> list = new GfoIndexedList<>();
@Test public void Add() {
list.Add("A", "a");
list.Add("B", "b");
list.Add("C", "c");
private GfoIndexedList<String, String> list = new GfoIndexedList<>();
@Test public void Add() {
list.Add("A", "a");
list.Add("B", "b");
list.Add("C", "c");
testGetAt(0, "a");
testGetAt(1, "b");
testGetAt(2, "c");
testGetByOrFail("A", "a");
testGetByOrFail("B", "b");
testGetByOrFail("C", "c");
testIterate("a", "b", "c");
}
@Test public void DelBy() {
list.Add("A", "a");
list.Add("B", "b");
list.Add("C", "c");
testGetAt(0, "a");
testGetAt(1, "b");
testGetAt(2, "c");
testGetByOrFail("A", "a");
testGetByOrFail("B", "b");
testGetByOrFail("C", "c");
testIterate("a", "b", "c");
}
@Test public void DelBy() {
list.Add("A", "a");
list.Add("B", "b");
list.Add("C", "c");
list.DelBy("A");
list.DelBy("A");
testIterate("b", "c");
testIterate("b", "c");
list.DelBy("B");
list.DelBy("B");
testIterate("c");
testIterate("c");
list.DelBy("C");
list.DelBy("C");
testIterate();
}
@Test public void DelBy_SameVal() {
list.Add("A", "a");
list.Add("B", "b");
list.Add("C", "a");
testIterate();
}
@Test public void DelBySameVal() {
list.Add("A", "a");
list.Add("B", "b");
list.Add("C", "a");
list.DelBy("C");
list.DelBy("C");
testIterate("a", "b"); // fails if "b", "a"
}
@Test public void Set() {
list.Add("A", "a");
list.Add("B", "b");
list.Add("C", "c");
testIterate("a", "b"); // fails if "b", "a"
}
@Test public void Set() {
list.Add("A", "a");
list.Add("B", "b");
list.Add("C", "c");
list.Set("B", "bb");
testGetByOrFail("B", "bb");
testIterate("a", "bb", "c");
}
private void testGetByOrFail(String key, String expd) {
Gftest_fxt.Eq__str(expd, list.GetByOrFail(key));
}
private void testGetAt(int idx, String expd) {
Gftest_fxt.Eq__str(expd, list.GetAt(idx));
}
private void testIterate(String... expd) {
String[] actl = new String[expd.length];
int i = 0;
for (String itm : list) {
actl[i++] = itm;
}
Gftest_fxt.Eq__ary(expd, actl);
}
}
list.Set("B", "bb");
testGetByOrFail("B", "bb");
testIterate("a", "bb", "c");
}
private void testGetByOrFail(String key, String expd) {
GfoTstr.EqStr(expd, list.GetByOrFail(key));
}
private void testGetAt(int idx, String expd) {
GfoTstr.EqStr(expd, list.GetAt(idx));
}
private void testIterate(String... expd) {
String[] actl = new String[expd.length];
int i = 0;
for (String itm : list) {
actl[i++] = itm;
}
GfoTstr.EqAry(expd, actl);
}
}