z011_IntObjHash_tst.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. public class z011_IntObjHash_tst {
  15. @Before public void setup() {
  16. hash = new IntObjHash_base();
  17. } IntObjHash_base hash;
  18. @Test public void Empty() {
  19. tst_Count(0);
  20. tst_Fetch(1, null);
  21. }
  22. @Test public void Add() {
  23. hash.Add(1, "1");
  24. tst_Count(1);
  25. tst_Fetch(1, "1");
  26. tst_Fetch(2, null);
  27. }
  28. @Test public void Del() {
  29. hash.Add(1, "1");
  30. hash.Del(1);
  31. tst_Count(0);
  32. tst_Fetch(1, null);
  33. }
  34. @Test public void Clear() {
  35. hash.Add(1, "1");
  36. hash.Add(32, "32");
  37. tst_Fetch(1, "1");
  38. tst_Fetch(32, "32");
  39. tst_Count(2);
  40. hash.Clear();
  41. tst_Count(0);
  42. tst_Fetch(2, null);
  43. tst_Fetch(32, null);
  44. }
  45. @Test public void Add_bug() { // fails after expanding ary, and fetching at key=n*16
  46. hash.Add(1, "1");
  47. tst_Count(1);
  48. tst_Fetch(1, "1");
  49. tst_Fetch(15, null); // works
  50. tst_Fetch(17, null); // works
  51. tst_Fetch(16, null); // used to fail
  52. }
  53. void tst_Fetch(int key, Object expd) {Tfds.Eq(expd, hash.Get_by(key));}
  54. void tst_Count(int expd) {Tfds.Eq(expd, hash.Count());}
  55. }