_binary ÿþFrom 0e20784403ae265bbea0cd2aef1dc99e317201fe Mon Sep 17 00:00:00 2001
From: TimmahC <tph.chow@gmail.com>
Date: Mon, 18 Mar 2019 18:34:53 -0700
Subject: [PATCH] Adds news test cases for IndexShard, as well as updates
 outdated ones, a=chris

---
 tests/IndexShardTest.php | 99 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 95 insertions(+), 4 deletions(-)

diff --git a/tests/IndexShardTest.php b/tests/IndexShardTest.php
index 87e2f28..054e158 100644
--- a/tests/IndexShardTest.php
+++ b/tests/IndexShardTest.php
@@ -120,6 +120,30 @@ class IndexShardTest extends UnitTest
             "Doc lookup by meta word works");
         $this->assertEqual(count($c_data), 1,
             "Doc lookup by meta word works has correct count");
+        // add a third document and check
+        $docid = "KKKKKKKK";
+        $doc_hash = "LLLLLLLL";
+        $doc_hosts_url = "MMMMMMMM";
+        $docid .= $doc_hash. $doc_hosts_url;
+        $offset = 10;
+        $word_counts = [
+            'BBBBBBBB' => [1, 3],
+            'DDDD' => [1, 4, 9],
+            'GG' => [6],
+        ];
+        $meta_ids = ["YYYYYYYY"];
+        $this->test_objects['shard']->addDocumentWords($docid,
+            $offset, $word_counts, $meta_ids, [], true);
+        //$this->assertEqual($this->test_objects['shard']->len_all_docs, 18,
+        //    "Len All Docs Correctly Counts Length of all Docs");
+        $c_data = $this->test_objects['shard']->getPostingsSliceById(
+            L\crawlHashWord('BBBBBBBB', true), 5);
+        $this->assertTrue(isset($c_data["AAAAAAAABBBBBBBBCCCCCCCC"]),
+            "Doc lookup by meta word works");
+        $this->assertTrue(isset($c_data["KKKKKKKKLLLLLLLLMMMMMMMM"]),
+            "Doc lookup by meta word works");
+        $this->assertEqual(count($c_data), 2,
+            "Doc lookup by meta word works has correct count");
     }
     /**
      * Check if can store link documents into an index shard and retrieve them
@@ -162,6 +186,28 @@ class IndexShardTest extends UnitTest
             "Link Doc lookup by word works 2nd doc");
         $this->assertEqual(count($c_data), 2,
             "Link Doc lookup by word works has correct count");
+        $docid = "AAAAAAAA";
+        $doc_hash = "BBBBBBBB";
+        $docid .= $doc_hash."GGGGGGGG";
+        $offset = 21;
+        $word_counts = [
+            'DDDDDDDD' => [1, 4],
+            'LLLLLLLL' => [7, 9],
+            'NNNNNNNN' => [2],
+        ];
+        $meta_ids = ["EEEEEEEE", "FFFFFFFF"];
+        $this->test_objects['shard']->addDocumentWords($docid,
+            $offset, $word_counts, $meta_ids, true);
+        $c_data = $this->test_objects['shard']->getPostingsSliceById(
+            L\crawlHashWord('NNNNNNNN', true), 5);
+        $this->assertTrue(isset($c_data["AAAAAAAABBBBBBBBCCCCCCCC"]),
+            "Link Doc lookup by word works 1st of two");
+        $this->assertTrue(isset($c_data["AAAAAAAABBBBBBBBGGGGGGGG"]),
+            "Link Doc lookup by word works 2nd doc");
+            $this->assertFalse(isset($c_data["AAAAAAAABBBBBBBBEEEEEEEE"]),
+            "Link Doc lookup should not have third document");
+        $this->assertEqual(count($c_data), 2,
+            "Link Doc lookup by word works has correct count");
     }
     /**
      * Check that appending two index shards works correctly
@@ -177,7 +223,7 @@ class IndexShardTest extends UnitTest
             'DDDDDDDD' => [6],
         ];
         $meta_ids = ["EEEEEEEE", "FFFFFFFF"];
-        $this->test_objects['shard']->addDocumentWords($docid,
+        $this->test_objects['shard']->addDocumentWords($docid, //adding a document to the first shard
             $offset, $word_lists, $meta_ids, true);
         $docid = "KKKKKKKKGGGGGGGGHHHHHHHH";
         $offset = 20;
@@ -186,7 +232,7 @@ class IndexShardTest extends UnitTest
             'DDDDDDDD' => [4],
         ];
         $meta_ids = [];
-        $this->test_objects['shard2']->addDocumentWords($docid,
+        $this->test_objects['shard2']->addDocumentWords($docid, //adding a document to the second shard
             $offset, $word_lists, $meta_ids);
         $docid = "GGGGGGGG";
         $offset = 6;
@@ -196,7 +242,7 @@ class IndexShardTest extends UnitTest
             'JJJJJJJJ' => [5],
         ];
         $meta_ids = ["KKKKKKKK"];
-        $this->test_objects['shard2']->addDocumentWords($docid,
+        $this->test_objects['shard2']->addDocumentWords($docid, //adding another document to the second shard
             $offset, $word_lists, $meta_ids);
         $this->test_objects['shard']->appendIndexShard(
             $this->test_objects['shard2']);
@@ -240,6 +286,20 @@ class IndexShardTest extends UnitTest
             L\crawlHashWord('KKKKKKKK', true), 5);
         $this->assertTrue(isset($c_data["GGGGGGGG"]),
             "Data from third shard present 4");
+        $docid = "HHHHHHHHDDDDDDDD";
+        $offset = 50;
+        $word_lists = [
+            'YYYYYYYY' => [3, 7],
+        ];
+        $meta_ids = [];
+        $this->test_objects['shard3']->addDocumentWords($docid, //adding a document to the third shard
+            $offset, $word_lists, $meta_ids);
+        $this->test_objects['shard']->appendIndexShard(
+            $this->test_objects['shard3']);
+        $c_data = $this->test_objects['shard']->getPostingsSliceById(
+            L\crawlHashWord('YYYYYYYY', true), 5);
+        $this->assertTrue(isset($c_data["HHHHHHHHDDDDDDDD"]),
+            "Data from third shard present 5");
     }
     /**
      * Check that changing document offsets works
@@ -306,6 +366,7 @@ class IndexShardTest extends UnitTest
             "DDDDDDDD" => 7,
         ];
         $i = 0;
+        echo $this->test_objects['shard']->len_all_link_docs;
         foreach ($predicted_offsets as $key =>$offset) {
             $this->assertTrue(isset($c_data[$key]),
                 "Summary key matches predicted $i");
@@ -318,6 +379,36 @@ class IndexShardTest extends UnitTest
         $this->assertEqual($c_data['CCCCCCCCFFFFFFFF']
                 [CrawlConstants::SUMMARY_OFFSET],
                 0,  "Summary offset matches predicted second word");
+        // adding new document after changing offset once
+        $docid = "AAAAAAAASSSSSSSD";
+        $offset = 0;
+        $word_lists = [
+            'BBBBBBBB' => [1]
+        ];
+        $meta_ids = [];
+        $this->test_objects['shard']->addDocumentWords($docid,
+            $offset, $word_lists, $meta_ids);
+        $new_doc_offsets = [
+            "QQQQQQQQEEEEEEEEFFFFFFFF" => 10,
+            "DDDDDDDD" => 6,
+        ];
+        $this->test_objects['shard']->changeDocumentOffsets($new_doc_offsets);
+        $c_data = $this->test_objects['shard']->getPostingsSliceById(
+            L\crawlHashWord('BBBBBBBB', true), 6);
+        $predicted_offsets = [
+            "AAAAAAAASSSSSSSS" => 5,
+            "CCCCCCCCFFFFFFFF" => 0,
+            "AAAAAAAAEEEEEEEEFFFFFFFF" => 10,
+            "QQQQQQQQEEEEEEEEFFFFFFFF" => 10,
+            "DDDDDDDD" => 6,
+        ];
+        foreach ($predicted_offsets as $key =>$offset) {
+            $this->assertTrue(isset($c_data[$key]),
+                "Summary key matches predicted $i");
+            $this->assertEqual($c_data[$key][CrawlConstants::SUMMARY_OFFSET],
+                $offset,  "Summary offset matches predicted $i");
+            $i++;
+        }
     }
     /**
      * Check that save and load work
@@ -397,4 +488,4 @@ class IndexShardTest extends UnitTest
         $this->assertTrue(isset($c_data["AAAAAAAABBBBBBBBCCCCCCCC"]),
             "Save without dictionary test works");
     }
-}
+}
\ No newline at end of file
-- 
2.5.0.windows.1

