set_test.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. suite('lunr.Set', function () {
  2. suite('#contains', function () {
  3. suite('complete set', function () {
  4. test('returns true', function () {
  5. assert.isOk(lunr.Set.complete.contains('foo'))
  6. })
  7. })
  8. suite('empty set', function () {
  9. test('returns false', function () {
  10. assert.isNotOk(lunr.Set.empty.contains('foo'))
  11. })
  12. })
  13. suite('populated set', function () {
  14. setup(function () {
  15. this.set = new lunr.Set (['foo'])
  16. })
  17. test('element contained in set', function () {
  18. assert.isOk(this.set.contains('foo'))
  19. })
  20. test('element not contained in set', function () {
  21. assert.isNotOk(this.set.contains('bar'))
  22. })
  23. })
  24. })
  25. suite('#union', function () {
  26. setup(function () {
  27. this.set = new lunr.Set(['foo'])
  28. })
  29. suite('complete set', function () {
  30. test('union is complete', function () {
  31. var result = lunr.Set.complete.union(this.set)
  32. assert.isOk(result.contains('foo'))
  33. assert.isOk(result.contains('bar'))
  34. })
  35. })
  36. suite('empty set', function () {
  37. test('contains element', function () {
  38. var result = lunr.Set.empty.union(this.set)
  39. assert.isOk(result.contains('foo'))
  40. assert.isNotOk(result.contains('bar'))
  41. })
  42. })
  43. suite('populated set', function () {
  44. suite('with other populated set', function () {
  45. test('contains both elements', function () {
  46. var target = new lunr.Set (['bar'])
  47. var result = target.union(this.set)
  48. assert.isOk(result.contains('foo'))
  49. assert.isOk(result.contains('bar'))
  50. assert.isNotOk(result.contains('baz'))
  51. })
  52. })
  53. suite('with empty set', function () {
  54. test('contains all elements', function () {
  55. var target = new lunr.Set (['bar'])
  56. var result = target.union(lunr.Set.empty)
  57. assert.isOk(result.contains('bar'))
  58. assert.isNotOk(result.contains('baz'))
  59. })
  60. })
  61. suite('with complete set', function () {
  62. test('contains all elements', function () {
  63. var target = new lunr.Set (['bar'])
  64. var result = target.union(lunr.Set.complete)
  65. assert.isOk(result.contains('foo'))
  66. assert.isOk(result.contains('bar'))
  67. assert.isOk(result.contains('baz'))
  68. })
  69. })
  70. })
  71. })
  72. suite('#intersect', function () {
  73. setup(function () {
  74. this.set = new lunr.Set(['foo'])
  75. })
  76. suite('complete set', function () {
  77. test('contains element', function () {
  78. var result = lunr.Set.complete.intersect(this.set)
  79. assert.isOk(result.contains('foo'))
  80. assert.isNotOk(result.contains('bar'))
  81. })
  82. })
  83. suite('empty set', function () {
  84. test('does not contain element', function () {
  85. var result = lunr.Set.empty.intersect(this.set)
  86. assert.isNotOk(result.contains('foo'))
  87. })
  88. })
  89. suite('populated set', function () {
  90. suite('no intersection', function () {
  91. test('does not contain intersection elements', function () {
  92. var target = new lunr.Set (['bar'])
  93. var result = target.intersect(this.set)
  94. assert.isNotOk(result.contains('foo'))
  95. assert.isNotOk(result.contains('bar'))
  96. })
  97. })
  98. suite('intersection', function () {
  99. test('contains intersection elements', function () {
  100. var target = new lunr.Set (['foo', 'bar'])
  101. var result = target.intersect(this.set)
  102. assert.isOk(result.contains('foo'))
  103. assert.isNotOk(result.contains('bar'))
  104. })
  105. })
  106. suite('with empty set', function () {
  107. test('returns empty set', function () {
  108. var target = new lunr.Set(['foo']),
  109. result = target.intersect(lunr.Set.empty)
  110. assert.isNotOk(result.contains('foo'))
  111. })
  112. })
  113. suite('with complete set', function () {
  114. test('returns populated set', function () {
  115. var target = new lunr.Set(['foo']),
  116. result = target.intersect(lunr.Set.complete)
  117. assert.isOk(result.contains('foo'))
  118. assert.isNotOk(result.contains('bar'))
  119. })
  120. })
  121. })
  122. })
  123. })