Int_ary__tst.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. XOWA: the XOWA Offline Wiki Application
  3. Copyright (C) 2012-2017 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;
  13. import org.junit.*; import gplx.core.tests.*;
  14. public class Int_ary__tst {
  15. private Int_ary__fxt fxt = new Int_ary__fxt();
  16. @Test public void Parse() {
  17. fxt.Test__Parse("1,2,3" , 3, Int_ary_.Empty, 1, 2, 3);
  18. fxt.Test__Parse("123,321,213" , 3, Int_ary_.Empty, 123, 321, 213);
  19. fxt.Test__Parse(" 1, 2,3" , 3, Int_ary_.Empty, 1, 2, 3);
  20. fxt.Test__Parse("-1,+2,-3" , 3, Int_ary_.Empty, -1, 2, -3);
  21. fxt.Test__Parse(Int_.To_str(Int_.Min_value) , 1, Int_ary_.Empty, Int_.Min_value);
  22. fxt.Test__Parse(Int_.To_str(Int_.Max_value) , 1, Int_ary_.Empty, Int_.Max_value);
  23. fxt.Test__Parse("1,2" , 1, Int_ary_.Empty);
  24. fxt.Test__Parse("1" , 2, Int_ary_.Empty);
  25. fxt.Test__Parse("a" , 1, Int_ary_.Empty);
  26. fxt.Test__Parse("1-2," , 1, Int_ary_.Empty);
  27. }
  28. @Test public void Parse_list_or_() {
  29. fxt.Test__Parse_or("1", 1);
  30. fxt.Test__Parse_or("123", 123);
  31. fxt.Test__Parse_or("1,2,123", 1, 2, 123);
  32. fxt.Test__Parse_or("1,2,12,123", 1, 2, 12, 123);
  33. fxt.Test__Parse_or("1-5", 1, 2, 3, 4, 5);
  34. fxt.Test__Parse_or("1-1", 1);
  35. fxt.Test__Parse_or("1-3,7,11-13,21", 1, 2, 3, 7, 11, 12, 13, 21);
  36. fxt.Test__Parse_or__empty("1 2"); // NOTE: MW would gen 12; treat as invalid
  37. fxt.Test__Parse_or__empty("1,"); // eos
  38. fxt.Test__Parse_or__empty("1,,2"); // empty comma
  39. fxt.Test__Parse_or__empty("1-"); // eos
  40. fxt.Test__Parse_or__empty("3-1"); // bgn > end
  41. fxt.Test__Parse_or__empty("1,a,2");
  42. fxt.Test__Parse_or__empty("a-1,2");
  43. fxt.Test__Parse_or__empty("-1"); // no rng bgn
  44. }
  45. }
  46. class Int_ary__fxt {
  47. public void Test__Parse_or__empty(String raw) {Tfds.Eq_ary(Int_ary_.Empty, Int_ary_.Parse_or(Bry_.new_a7(raw), Int_ary_.Empty));}
  48. public void Test__Parse_or(String raw, int... expd) {Tfds.Eq_ary(expd, Int_ary_.Parse_or(Bry_.new_a7(raw), Int_ary_.Empty));}
  49. public void Test__Parse(String raw, int reqd_len, int[] or, int... expd) {Gftest.Eq__ary(expd, Int_ary_.Parse(raw, reqd_len, or), "failed to parse: {0}", raw);}
  50. }