public void TestFileSerializationManagerSerializeDeserializeSimpleResult() { var manager = new FileSerializationManager(new BinaryFormatter(), "test.bin"); var table = new TopResults(); table.Add(new SimpleResult(2, "player", new PlainResultFormatter())); table.Add(new SimpleResult(1, "player", new PlainResultFormatter())); manager.Serialize(table); var afterSerializationTable = manager.Deserialize(); Assert.AreEqual(table.ToString(), afterSerializationTable.ToString()); }
public void TestResultsTableConsoleGraphicInstance() { ITable testTopResults = new TopResults(); IResultsTable testResultsTable = new ResultsTable(testTopResults); IntPoint testCoords = new IntPoint(5, 5); IRenderer testRenderer = new ConsoleRenderer(); IRenderable testResultsTableConsGraphic = new ResultsTableConsoleGraphic(testResultsTable, testCoords, testRenderer); IRenderable factoryResultsTableConsGraphic = testConsoleGraphicFactory.GetResultsTableConsoleGraphic(testResultsTable, testCoords, testRenderer); Object.Equals(testResultsTableConsGraphic, factoryResultsTableConsGraphic); }
public void InitializeTopResultsInstance() { this.table = new TopResults(); }
public override IList <LookupResult> Lookup(string key, HashSet <BytesRef> contexts, bool onlyMorePopular, int num) { if (contexts != null) { throw new System.ArgumentException("this suggester doesn't support contexts"); } Debug.Assert(num > 0); if (onlyMorePopular) { throw new System.ArgumentException("this suggester only works with onlyMorePopular=false"); } if (fst == null) { return(Collections.emptyList()); } BytesRef scratch = new BytesRef(key); int prefixLength = scratch.Length; Arc <long?> arc = new Arc <long?>(); // match the prefix portion exactly long?prefixOutput = null; try { prefixOutput = LookupPrefix(scratch, arc); } catch (IOException bogus) { throw new Exception(bogus); } if (prefixOutput == null) { return(Collections.emptyList()); } IList <LookupResult> results = new List <LookupResult>(num); CharsRef spare = new CharsRef(); if (exactFirst && arc.Final) { spare.grow(scratch.length); UnicodeUtil.UTF8toUTF16(scratch, spare); results.Add(new LookupResult(spare.ToString(), decodeWeight(prefixOutput + arc.nextFinalOutput))); if (--num == 0) { return(results); // that was quick } } // complete top-N TopResults <long?> completions = null; try { completions = Util.ShortestPaths(fst, arc, prefixOutput, weightComparator, num, !exactFirst); Debug.Assert(completions.isComplete); } catch (IOException bogus) { throw new Exception(bogus); } BytesRef suffix = new BytesRef(8); foreach (Result <long?> completion in completions) { scratch.length = prefixLength; // append suffix Util.ToBytesRef(completion.input, suffix); scratch.Append(suffix); spare.Grow(scratch.Length); UnicodeUtil.UTF8toUTF16(scratch, spare); results.Add(new LookupResult(spare.ToString(), decodeWeight(completion.output))); } return(results); }