z012_GfmlTrie_tst.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.gfml; import gplx.*;
  13. import org.junit.*;
  14. import gplx.core.texts.*; /*CharStream*/
  15. public class z012_GfmlTrie_tst {
  16. @Before public void setup() {
  17. trie = GfmlTrie.new_();
  18. } GfmlTrie trie;
  19. @Test public void Null() {
  20. tst_FindMatch_first("", null);
  21. tst_FindMatch_first("{", null);
  22. }
  23. @Test public void OneChar() {
  24. trie.Add("{", "val0");
  25. tst_FindMatch_first("{", "val0");
  26. tst_FindMatch_first(":", null);
  27. }
  28. @Test public void TwoChar() {
  29. trie.Add("/*", "val0");
  30. tst_FindMatch_first("/*", "val0");
  31. tst_FindMatch_first("//", null);
  32. }
  33. @Test public void ManySym() {
  34. trie.Add(":", "val0");
  35. trie.Add("{", "val1");
  36. tst_FindMatch_first(":", "val0");
  37. tst_FindMatch_first("{", "val1");
  38. tst_FindMatch_first("-", null);
  39. }
  40. @Test public void Overlap_1_2() {
  41. trie.Add("[", "val0");
  42. trie.Add("[:", "val1");
  43. tst_FindMatch_first("[", "val0");
  44. tst_FindMatch_first("[:", "val1");
  45. tst_FindMatch_first("[-", "val0");
  46. tst_FindMatch_first(":", null);
  47. }
  48. @Test public void Overlap_2_1() {
  49. trie.Add("[:", "val0");
  50. trie.Add("[", "val1");
  51. tst_FindMatch_first("[:", "val0");
  52. tst_FindMatch_first("[", "val1");
  53. tst_FindMatch_first("[-", "val1");
  54. tst_FindMatch_first(":", null);
  55. }
  56. @Test public void Overlap_1_1() {
  57. trie.Add("[", "val0");
  58. trie.Add("[", "val1");
  59. tst_FindMatch_first("[", "val1"); // return last added
  60. tst_FindMatch_first(":", null);
  61. }
  62. void tst_FindMatch_first(String text, String expd) {
  63. CharStream stream = CharStream.pos0_(text);
  64. String actl = (String)trie.FindMatch(stream);
  65. Tfds.Eq(expd, actl);
  66. }
  67. }