def testResultSerialization(): result = getRandomResult() assertMapArrayMatch(result.xingCharMap, result.xingCharSortedArray) assertMapArrayMatch(result.xingMap, result.xingSortedArray) assertMapArrayMatch(result.mingCharMap, result.mingCharSortedArray) assertMapArrayMatch(result.mingMap, result.mingSortedArray) assertMapArrayMatch(result.xingMingMap, result.xingMingSortedArray) result.writeToFile(fileForResultTest) newResult = Result() newResult.readFromFile(fileForResultTest) assertResultEqual(result, newResult) result.readableWriteToFile(dirForResultTest)
def getRandomResult(length=1000): result = Result() result.glbalInfo = getRandomGlobalNameInfo() result.xingCharMap = getRandomResultMap(length) result.xingMap = getRandomResultMap(length) result.mingCharMap = getRandomResultMap(length) result.mingMap = getRandomResultMap(length) result.xingMingMap = getRandomResultMap(length) result.caculate() return result
def _importRankArrayFromFile(self, f, arrayName): items = Result.readArrayFromFileGenerator(f) for item in items: key = item[0] rank = item[1] + 1 # Rank is 1 based self._addRankArrayRecord(key, rank, arrayName)
def _importMapFromFile(self, f, tableName): infos = Result.readMapFromFileGenerator(f) for info in infos: self._importInfo(info, tableName)