set_test.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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('contains element', function () {
  31. var result = lunr.Set.complete.union(this.set)
  32. assert.isOk(result.contains('foo'))
  33. })
  34. })
  35. suite('empty set', function () {
  36. test('contains element', function () {
  37. var result = lunr.Set.empty.union(this.set)
  38. assert.isOk(result.contains('foo'))
  39. })
  40. })
  41. suite('populated set', function () {
  42. suite('with other populated set', function () {
  43. test('contains both elements', function () {
  44. var target = new lunr.Set (['bar'])
  45. var result = target.union(this.set)
  46. assert.isOk(result.contains('foo'))
  47. assert.isOk(result.contains('bar'))
  48. assert.isNotOk(result.contains('baz'))
  49. })
  50. })
  51. suite('with empty set', function () {
  52. test('contains all elements', function () {
  53. var target = new lunr.Set (['bar'])
  54. var result = target.union(lunr.Set.empty)
  55. assert.isOk(result.contains('bar'))
  56. assert.isNotOk(result.contains('baz'))
  57. })
  58. })
  59. suite('with complete set', function () {
  60. test('contains all elements', function () {
  61. var target = new lunr.Set (['bar'])
  62. var result = target.union(lunr.Set.complete)
  63. assert.isOk(result.contains('foo'))
  64. assert.isOk(result.contains('bar'))
  65. assert.isOk(result.contains('baz'))
  66. })
  67. })
  68. })
  69. })
  70. suite('#intersect', function () {
  71. setup(function () {
  72. this.set = new lunr.Set(['foo'])
  73. })
  74. suite('complete set', function () {
  75. test('contains element', function () {
  76. var result = lunr.Set.complete.intersect(this.set)
  77. assert.isOk(result.contains('foo'))
  78. })
  79. })
  80. suite('empty set', function () {
  81. test('does not contain element', function () {
  82. var result = lunr.Set.empty.intersect(this.set)
  83. assert.isNotOk(result.contains('foo'))
  84. })
  85. })
  86. suite('populated set', function () {
  87. suite('no intersection', function () {
  88. test('does not contain intersection elements', function () {
  89. var target = new lunr.Set (['bar'])
  90. var result = target.intersect(this.set)
  91. assert.isNotOk(result.contains('foo'))
  92. assert.isNotOk(result.contains('bar'))
  93. })
  94. })
  95. suite('intersection', function () {
  96. test('contains intersection elements', function () {
  97. var target = new lunr.Set (['foo', 'bar'])
  98. var result = target.intersect(this.set)
  99. assert.isOk(result.contains('foo'))
  100. assert.isNotOk(result.contains('bar'))
  101. })
  102. })
  103. suite('with empty set', function () {
  104. test('returns empty set', function () {
  105. var target = new lunr.Set(['foo']),
  106. result = target.intersect(lunr.Set.empty)
  107. assert.isNotOk(result.contains('foo'))
  108. })
  109. })
  110. suite('with complete set', function () {
  111. test('returns populated set', function () {
  112. var target = new lunr.Set(['foo']),
  113. result = target.intersect(lunr.Set.complete)
  114. assert.isOk(result.contains('foo'))
  115. })
  116. })
  117. })
  118. })
  119. })