ArrayUtlTest.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. XOWA: the XOWA Offline Wiki Application
  3. Copyright (C) 2012-2021 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.arrays;
  13. import gplx.frameworks.tests.GfoTstr;
  14. import gplx.types.basics.utls.ArrayUtl;
  15. import org.junit.Test;
  16. public class ArrayUtlTest {
  17. @Test public void Append() {
  18. TestAppend(AryInt(), AryInt(1), AryInt(1)); // 0 + 1 = 1
  19. TestAppend(AryInt(0), AryInt(), AryInt(0)); // 1 + 0 = 1
  20. TestAppend(AryInt(0), AryInt(1), AryInt(0, 1)); // 1 + 1 = 2
  21. }
  22. private void TestAppend(int[] source, int[] added, int[] expd) {
  23. GfoTstr.EqAry(expd, (int[])ArrayUtl.Append(source, added));
  24. }
  25. @Test public void Resize() {
  26. TestResize(AryInt(0), 0, AryInt()); // 1 -> 0
  27. TestResize(AryInt(0, 1), 1, AryInt(0)); // 2 -> 1
  28. }
  29. private void TestResize(int[] source, int length, int[] expd) {
  30. GfoTstr.EqAry(expd, (int[])ArrayUtl.Resize(source, length));
  31. }
  32. @Test public void Insert() {
  33. TestInsert(AryObj(0, 1, 4, 5), AryObj(2, 3), 2, AryObj(0, 1, 2, 3, 4, 5));
  34. }
  35. private void TestInsert(Object[] cur, Object[] add, int addPos, Object[] expd) {
  36. GfoTstr.EqAryObjAry(expd, ArrayUtl.Insert(cur, add, addPos));
  37. }
  38. private Object[] AryObj(Object... ary) {return ary;}
  39. private int[] AryInt(int... ary) {return ary;}
  40. }