Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

test cases for string bsearch

  • Loading branch information...
commit e636abbd0cd9c3da217146e7cac3a45d621cf6fb 1 parent 9b58392
Dan Stocker danstocker authored

Showing 1 changed file with 46 additions and 19 deletions. Show diff stats Hide diff stats

  1. +46 19 test/order.js
65 test/order.js
@@ -12,7 +12,9 @@ jOrder.testing = function (testing, constants, jOrder) {
12 12
13 13 // test indexes
14 14 string = jOrder.index(testing.jsonX, ['author'], {ordered: true}),
15   - number = jOrder.index(testing.jsonX, ['volumes'], {type: jOrder.number, grouped: true, ordered: true});
  15 + number = jOrder.index(testing.jsonX, ['volumes'], {type: jOrder.number, grouped: true, ordered: true}),
  16 +
  17 + json;
16 18
17 19 test("Binary search", function () {
18 20 // searching in empty order
@@ -47,18 +49,21 @@ jOrder.testing = function (testing, constants, jOrder) {
47 49 equal(number.bsearch(1.5, constants.end), 1, "In between result as end in grouped numeric index");
48 50 });
49 51
50   - test("Bsearch edge cases", function () {
51   - // heavily redundant data
52   - var json = [
53   - {val: 5},
54   - {val: 1},
55   - {val: 5},
56   - {val: 5},
57   - {val: 9},
58   - {val: 5},
59   - {val: 5}
60   - ],
61   - grouped = jOrder.index(json, ['val'], {grouped: true, ordered: true, type: jOrder.number}),
  52 + // heavily redundant data
  53 + json = [
  54 + {val: 5, str: "testx"},
  55 + {val: 1, str: "test"},
  56 + {val: 5, str: "testA"},
  57 + {val: 5, str: "test"},
  58 + {val: 9, str: "blah"},
  59 + {val: 5, str: "blahhh"},
  60 + {val: 5, str: "lab"}
  61 + ];
  62 +
  63 + test("Bsearch edge cases (numeric)", function () {
  64 + var
  65 +
  66 + index = jOrder.index(json, ['val'], {grouped: true, ordered: true, type: jOrder.number}),
62 67 random_order = [5, 4, 0, 2, 6, 3, 1],
63 68 expected = [
64 69 {key: 1, rowId: 1},
@@ -71,20 +76,42 @@ jOrder.testing = function (testing, constants, jOrder) {
71 76 ],
72 77 i;
73 78
74   - deepEqual(grouped.order(), expected, "Index is ordered by key, then rowId");
  79 + deepEqual(index.order(), expected, "Index is ordered by key, then rowId");
75 80
76 81 // locating items by key (and optionally rowId)
77   - equal(grouped.bsearch(5, constants.start), 1, "Bsearch returns the lowest suitable item id by default");
78   - equal(grouped.bsearch(5, constants.start, 5), 4, "Bsearch may locate a specific item within the index");
  82 + equal(index.bsearch(5, constants.start), 1, "Bsearch returns the lowest suitable item id by default");
  83 + equal(index.bsearch(5, constants.start, 5), 4, "Bsearch may locate a specific item within the index");
79 84
80 85 // demonstrating that addition preserves integrity on both key and rowId
81   - grouped.unbuild();
  86 + index.unbuild();
82 87 for (i = 0; i < 7; i++) {
83   - grouped.add(json[random_order[i]], random_order[i]);
  88 + index.add(json[random_order[i]], random_order[i]);
84 89 }
85   - deepEqual(grouped.order(), expected, "Order of additions has no effect on final index");
  90 + deepEqual(index.order(), expected, "Order of additions has no effect on final index");
86 91 });
87 92
  93 + test("Bsearch edge cases (string)", function () {
  94 + // heavily redundant data
  95 + var
  96 + index = jOrder.index(json, ['str'], {grouped: true, ordered: true, type: jOrder.string}),
  97 + expected = [
  98 + {key: "blah", rowId: 4},
  99 + {key: "blahhh", rowId: 5},
  100 + {key: "lab", rowId: 6},
  101 + {key: "test", rowId: 1},
  102 + {key: "test", rowId: 3},
  103 + {key: "testA", rowId: 2},
  104 + {key: "testx", rowId: 0}
  105 + ],
  106 + i;
  107 +
  108 + deepEqual(index.order(), expected, "Index is ordered by key, then rowId");
  109 +
  110 + // locating items by key (and optionally rowId)
  111 + equal(index.bsearch("test", constants.start), 3, "Bsearch returns the lowest suitable item id by default");
  112 + equal(index.bsearch("test", constants.start, 3), 4, "Bsearch may locate a specific item within the index");
  113 + });
  114 +
88 115 test("Modifying order", function () {
89 116 var expected;
90 117

0 comments on commit e636abb

Please sign in to comment.
Something went wrong with that request. Please try again.