Ejemplo n.º 1
0
            public int Call()
            {
                int v = 0;

                foreach (string term in input)
                {
                    v += lookup.DoLookup(term, outerInstance.onlyMorePopular, outerInstance.num).Count;
                }
                return(v);
            }
Ejemplo n.º 2
0
        private void RunTest(Type lookupClass,
                             bool supportsExactWeights)
        {
            // Add all input keys.
            Lookup lookup = (Lookup)Activator.CreateInstance(lookupClass);

            Input[] keys = new Input[this.keys.Length];
            for (int i = 0; i < keys.Length; i++)
            {
                keys[i] = new Input(this.keys[i], i);
            }
            lookup.Build(new InputArrayIterator(keys));

            // Store the suggester.
            DirectoryInfo storeDir = CreateTempDir(this.GetType().Name);

            lookup.Store(new FileStream(Path.Combine(storeDir.FullName, "lookup.dat"), FileMode.OpenOrCreate));

            // Re-read it from disk.
            lookup = (Lookup)Activator.CreateInstance(lookupClass);
            lookup.Load(new FileStream(Path.Combine(storeDir.FullName, "lookup.dat"), FileMode.Open));

            // Assert validity.
            Random random   = Random();
            long   previous = long.MinValue;

            foreach (Input k in keys)
            {
                IList <Lookup.LookupResult> list = lookup.DoLookup(TestUtil.BytesToCharSequence(k.term, random).ToString(), false, 1);
                assertEquals(1, list.size());
                Lookup.LookupResult lookupResult = list[0];
                assertNotNull(k.term.Utf8ToString(), lookupResult.Key);

                if (supportsExactWeights)
                {
                    assertEquals(k.term.Utf8ToString(), k.v, lookupResult.Value);
                }
                else
                {
                    assertTrue(lookupResult.Value + ">=" + previous, lookupResult.Value >= previous);
                    previous = lookupResult.Value;
                }
            }
        }